喜大普奔!!ArcGIS Runtime SDK for Android 100.2 支持本地Shapefile文件的编辑啦!!!

0
分享 2018-01-12
对于Shapfile这一文件格式,ArcGIS Runtime SDK for Android 在100.2.0系列中推出了两大重磅利好消息: 
(1) 实现对本地 Shapfile 文件的加载、显示和查询 
(2) 实现对本地 Shapefile 文件的编辑,即增删改操作 
毋庸置疑,对于广大的ArcGIS移动端爱好者而言,支持Shapefile编辑操作绝对是一则振奋人心的好消息。
今天,我们就先来看看在ArcGIS Runtime SDK for Android中如何实现对Shapefile文件的要素添加。
本地Shapefile文件的加载和显示
Shapefile的加载和显示主要通过ShapefileFeatureTable和FeatureLayer这两个类来实现。
// 构建ShapefileFeatureTable,引入本地存储的shapefile文件
shapefileFeatureTable_Point = new ShapefileFeatureTable(Environment.getExternalStorageDirectory().getAbsolutePath() + "/ArcGIS/shapefile/center.shp");

// 构建FeatureLayer
FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable_Point);

// 设置Shapefile文件的渲染方式
featureLayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 20)));

// 添加到地图的业务图层组中
arcGISMap.getOperationalLayers().add(featureLayer);

本地Shapefile文件的编辑(以要素添加为例)
这里我们将直接传入一个固定的点几何以实现要素的添加。
// 调用isEditable和canAdd方法判断文件是否支持编辑操作,是否可添加要素;否,则抛出信息
if (shapefileFeatureTable.isEditable()&&shapefileFeatureTable.canAdd()) {

// 构建新增几何
Point mapPoint = new Point(140.0, 39.0, SpatialReference.create(4326));

// 构建待增加的Feature对象,设置几何,设置属性
Feature feature = shapefileFeatureTable.createFeature();
feature.setGeometry(mapPoint);
feature.getAttributes().put("NAME", "测试点");

// 调用addFeatureAsync方法增加要素
final ListenableFuture<Void> addFeatureOper = shapefileFeatureTable.addFeatureAsync(feature);

// 在操作完成的监听事件中判断操作是否成功
addFeatureOper.addDoneListener(new Runnable() {
@Override
public void run() {
try{
addFeatureOper.get();
if (addFeatureOper.isDone()){
Log.i("ShapefileEdit:", "Feature added!");
}
}catch(InterruptedException interruptedExceptionException){
// 处理异常
}catch (ExecutionException executionException){
// 处理异常
}
}
});
}else{
Log.i("ShapefileEdit:", "The Shapefile cann't be edited");
}



至此,我们就完成了ArcGIS for Android端 Shapefile文件的离线要素添加功能。 当然,除了要素增加,updateFeatureAsync()和deleteFeatureAsync()等方法则可以实现要素的更新和删除。这些用法我们将在后续章节中进行讲解。
文章来源:http://blog.csdn.net/zssai2015/article/details/79038438

5 个评论

Merry GISmas!
Merry GISmas!
记得及时回复微信消息!
你好,请问我是依照您给的代码加载shp文件的,能生成APK,底图能显示,但是不能显示shp文件的内容,经调试,好像是featurelayer中无shapefiletable的信息,请问如何解决
如何加载shp,供参考:https://blog.csdn.net/gislaozhang/article/details/114871322

要回复文章请先登录注册