Add kml points
Public void writekmlpiont () {string drivername = "kml"; // MapInfo file osgeo. gdal. gdal. setconfigoption ("gdal_filename_is_utf8", "no"); // to make the Attribute Table field support Chinese, add the following shape_encoding // UTF-8 to ISO-8859-1. osgeo. gdal. gdal. setconfigoption ("shape_encoding", ""); // register OGR. registerall (); osgeo. OGR. driver ogrdriver = OGR. getdriverbyname (drivername); datasource ogrds = ogrdriver. createdatasource ("C: \ test. kml ", null); // string filename = datetime. now. tostring ("yyyymmddhhmmss"); layer ogrlayer = ogrds. createlayer ("kml", null, wkbgeometrytype. wkbpoint, null); fielddefn fdefn = new fielddefn ("name", fieldtype. oftstring); fdefn. setwidth (32); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("intfield", fieldtype. oftinteger); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("dblefield", fieldtype. oftreal); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("datefield", fieldtype. oftdate); ogrlayer. createfield (fdefn, 1); feature = new feature (ogrlayer. getlayerdefn (); feature. setfield ("name", "New kml"); feature. setfield ("intfield", (INT) 123); feature. setfield ("dblefield", (double) 12.345); feature. setfield ("datefield", 2007, 3, 15, 18, 24, 30, 0); geometry Geom = geometry. createfromwkt ("Point (115.91466833333 28.668223333)"); feature. setgeometry (Geom); ogrlayer. createfeature (feature); ogrlayer. dispose (); ogrds. dispose ();}
View code
New kml line
Public void writekmlline () {string drivername = "kml"; // MapInfo file osgeo. gdal. gdal. setconfigoption ("gdal_filename_is_utf8", "no"); // to make the Attribute Table field support Chinese, add the following shape_encoding // UTF-8 to ISO-8859-1. osgeo. gdal. gdal. setconfigoption ("shape_encoding", ""); // register OGR. registerall (); osgeo. OGR. driver ogrdriver = OGR. getdriverbyname (drivername); datasource ogrds = ogrdriver. createdatasource ("C :\\ wkblinestring. Kml ", null); // string filename = datetime. now. tostring ("yyyymmddhhmmss"); layer ogrlayer = ogrds. createlayer ("kml", null, wkbgeometrytype. wkblinestring, null); fielddefn fdefn = new fielddefn ("name", fieldtype. oftstring); fdefn. setwidth (32); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("intfield", fieldtype. oftinteger); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("dblefield ", Fieldtype. oftreal); ogrlayer. createfield (fdefn, 1); fdefn = new fielddefn ("datefield", fieldtype. oftdate); ogrlayer. createfield (fdefn, 1); feature = new feature (ogrlayer. getlayerdefn (); feature. setfield ("name", "New kml"); feature. setfield ("intfield", (INT) 123); feature. setfield ("dblefield", (double) 12.345); feature. setfield ("datefield", 2007, 3, 15, 18, 24, 30, 0); geometry Geom = new Geom Etry (wkbgeometrytype. wkblinestring); // geometry. createfromwkt ("linestring (115.91466833333 28.668223333)"); // you need to add two points to the line. errors are often reported during the test., Geom. addpoint_2d (115.91466833333, 28.668223333); Geom. addpoint_2d (115.92466833333, 28.668223333); feature. setgeometry (Geom); ogrlayer. createfeature (feature); ogrlayer. dispose (); ogrds. dispose ();}
View code