1.首先确保自己的手机上文件路径正确,必须包含(.shp,.shx,.dbf三个文件,放在同一文件夹下)当然,如果加载了底图的话,最好要有投影坐标系文件.prj。
2. 读取shp文件,方法参照(Arcgis for Android之前的配置等工作好多大神写过了的,可以看看他们的系列)
https://blog.csdn.net/qq_36699930/article/details/82498704
https://blog.csdn.net/Smart3S/article/details/81138051
主要就是那一句 shapefileTable = new ShapefileFeatureTable(你自己的shp路径);
//示例
public void showShapefile() {
String mappath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Map/xzq.shp";
//这一句就读取了!!注意,测试用的shp文件放在Map文件夹下的,按照自己放的位置改路径。
shapefileTable = new ShapefileFeatureTable(mappath);
shapefileTable.loadAsync();
shapefileTable.addDoneLoadingListener(()-> {
shapefileLayer = new FeatureLayer(shapefileTable);
if (shapefileLayer.getFullExtent() != null) {
mapView.setViewpointGeometryAsync(shapefileLayer.getFullExtent());
} else
{
shapefileLayer.addDoneLoadingListener(()->
mapView.setViewpointGeometryAsync(shapefileLayer.getFullExtent()));
}
arcGISMap.getOperationalLayers().add(shapefileLayer);
});
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1.0f);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.NULL, Color.YELLOW, lineSymbol);
SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
shapefileLayer.setRenderer(renderer);
}
3.到这一步,运行下,讲道理,应该就可以读取了的。但是,我遇到一个坑,就是读取不了shp文件。
程序崩溃,提示 java.lang.IllegalArgumentException: Parameter boundingGeometry must not be null,报错地点在
mapView.setViewpointGeometryAsync(shapefileLayer.getFullExtent());
或者写了try,catch,不崩溃,但是同样不显示你的shp文件。
解决方法:
最开始我想,难道是我的shp文件有问题?搞了个Arcgis for desktop10.2(高版本的arcgis绘制的shp没有测试,不知道shp有没有什么变化,手机读不到先用100.7.0 的SDK试试),加载了下发现数据没问题。
然后用了别人的代码加载我的底图和shp,发现别人的程序的可以读取到。但是咱们的程序和人家一模一样啊?为啥咱的不行?
经历了控制变量法的几十遍测试,发现Arcgis for Android 100.5的大坑一个。
就是:不要去那个“Lecensed For Developer Use Only”水印!![去除办法,网上有,就是申请下arcgis开发者的账号,自动给你一个,然后写一句话就去除了]当然,下面的powered by esri可以去掉,没啥影响。
我把去除水印的话注释掉,就能读取shp了。
坑了我一整天,看着代码没问题,就是给你报错看。Arcgis for Android 这一手整的,666。
本文介绍了在ArcGIS for Android 100.5版本中遇到的无法读取shapefile的问题及解决方法。问题表现为程序崩溃或不显示shapefile,错误提示为'Parameter boundingGeometry must not be null'。解决方法是检查文件路径和文件完整性,以及避免移除'Licensed For Developer Use Only'水印,因为移除该水印可能导致此问题。

1109

被折叠的 条评论
为什么被折叠?



