Android GIS Development Series--Introductory season (Gdal) simply write a shp file

Source: Internet
Author: User

Gdal is used to read and write raster and vector data, in the Gdal official website, you can download the relevant resources for the compilation of the platform. In fact, the bottom of ArcGIS is also used gdal to read SHP files, that in Android can directly read and write shp files, is OK. Someone here has compiled the android-side so. You can also try compiling the related so yourself.

Create a new project, import the downloaded so and related resources, the relevant directory structure is as follows:

Note that the associated package name for Gdal should not be modified, so that so does not read the corresponding class.
Simply write a SHP, note the Guide package, to import Org.gdal the following related classes:

Private voidWRITESHP ()throwsunsupportedencodingexception {//Storage PathString Shppath = basepath + "/MY_LINE.SHP"; Ogr.        RegisterAll (); Gdal. Setconfigoption ("Gdal_filename_is_utf8", "NO"); //Chinese not supportedGdal. Setconfigoption ("shape_encoding", "" "); String Strdrivername= "ESRI Shapefile"; Org.gdal.ogr.Driver Odriver=ogr.        Getdriverbyname (Strdrivername); if(Odriver = =NULL) {System.out.println ("Driver is not available!" \ n "); return; }        //Create a data sourceDataSource ODS = Odriver.createdatasource (Shppath,NULL); if(ODS = =NULL) {            return; }        //create a layer with a 84 coordinate systemOrg.gdal.osr.SpatialReference SAP =Neworg.gdal.osr.SpatialReference (); Sap. Setwellknowngeogcs ("WGS84"); Layer Olayer=ODS. Createlayer ("Testpolygon", SAP, Ogr.wkbpolygon,NULL); if(Olayer = =NULL) {System.out.println ("Layer creation failed!" \ n "); return; }        //Create a property sheet below//Create an integer property called FieldID firstFielddefn Ofieldid =NewFielddefn ("ID", Ogr.        Oftinteger); Olayer.createfield (Ofieldid,1); //Create a character property called FeatureName, with a character length ofFielddefn Ofieldname =NewFielddefn ("name", Ogr.        oftstring); Ofieldname.setwidth (100); Olayer.createfield (Ofieldname,1); Featuredefn Odefn=Olayer.getlayerdefn (); //Create featuresFeature Ofeaturetriangle =NewFeature (ODEFN); Ofeaturetriangle.setfield (0, 0); Ofeaturetriangle.setfield (1, "Test"); Geometry Geomtriangle=Geometry. Createfromwkt ("POLYGON ((112 45,112 30,140 30))");        Ofeaturetriangle.setgeometry (Geomtriangle);        Olayer.createfeature (Ofeaturetriangle); //sync to file, be sure to writeOlayer.synctodisk (); }

Loading shp file effects with ArcGIS Mapview:

Gdal Java-related APIs

Android GIS Development Series--Introductory season (Gdal) simply write a shp file

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.