Gdal create kml

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.