标签:tin mtr 失败 null 简单 reg sso 属性 class
新建项目,将下载的so 与相关资源导入,相关目录结构如下:
注意gdal的相关包名不要修改,避免so读取不到相应的类。
简单写个shp,注意导包,要导入org.gdal下面相关的类:
private void writeShp() throws UnsupportedEncodingException { //存放路径 String shpPath = basePath + "/my_line.shp"; ogr.RegisterAll(); gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); // 不支持中文 gdal.SetConfigOption("SHAPE_ENCODING", ""); String strDriverName = "ESRI Shapefile"; org.gdal.ogr.Driver oDriver = ogr.GetDriverByName(strDriverName); if (oDriver == null) { System.out.println(" 驱动不可用!\n"); return; } // 创建数据源 DataSource oDS = oDriver.CreateDataSource(shpPath, null); if (oDS == null) { return; } // 创建一个84坐标系的图层 org.gdal.osr.SpatialReference sap = new org.gdal.osr.SpatialReference(); sap.SetWellKnownGeogCS("WGS84"); Layer oLayer = oDS .CreateLayer("TestPolygon", sap, ogr.wkbPolygon, null); if (oLayer == null) { System.out.println("图层创建失败!\n"); return; } // 下面创建属性表 // 先创建一个叫FieldID的整型属性 FieldDefn oFieldID = new FieldDefn("ID", ogr.OFTInteger); oLayer.CreateField(oFieldID, 1); // 再创建一个叫FeatureName的字符型属性,字符长度为50 FieldDefn oFieldName = new FieldDefn("name", ogr.OFTString); oFieldName.SetWidth(100); oLayer.CreateField(oFieldName, 1); FeatureDefn oDefn = oLayer.GetLayerDefn(); // 创建要素 Feature oFeatureTriangle = new Feature(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); //同步到文件中,一定要写 oLayer.SyncToDisk(); }
用Arcgis MapView加载shp文件效果:
Android GIS开发系列-- 入门季(13)Gdal简单写个shp文件
标签:tin mtr 失败 null 简单 reg sso 属性 class
原文地址:http://www.cnblogs.com/arxive/p/7751997.html