业务图层(OperationalLayers)编辑
除了对业务成果的地图可视化展示,外业数据调绘采集是移动地图应用很大一部分内容。从外业数据调绘采集的功能上来说包括添加、删除、更新,更新包括属性更新、几何更新和附件(图片、文件、视频)更新。
处理编辑工作的是FeatureTable( GeodatabaseFeatureTable 、ServiceFeatureTable ),主功能包括添加要素(Add features)、更新要素(Update features)、删除要素(Delete features)和要素附件(Feature attachments)管理。
从编辑模式上,或者说受移动设备有无网络连接,分为在线编辑( Online feature service editing)和离线编辑与同步( Offline feature service editing and sync)。要进行外业数据调绘采集,需要先准备要素服务(Feature Service)。
通过Online & Portal发布要素服务
http://server.arcgis.com/zh-cn/portal/latest/use/publish-features.htm
通过ArcGIS Server发布服务
配置要素服务数据以供离线使用
FeatureTable中的编辑方法
涉及到要素编辑的方法都存储在FeatureTable(com.esri.arcgisruntime.data)中:
添加要素:addFeatureAsync、addFeaturesAsync
删除要素:deleteFeatureAsync、deleteFeaturesAsync
更新要素:updateFeatureAsync、updateFeaturesAsync
创建FeatureTable
在线编辑与离线编辑在实施层面都是相同的,只是离线编辑多了同步工作。
在线:ServiceFeatureTable
private ServiceFeatureTable damageTable;
...
//generate feature table from service
damageTable =
new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");
离线:GeodatabaseFeatureTable
// Open the local geodatabase file
Geodatabase geodatabase = new Geodatabase(PATH_TO_GEODATABASE);
// Get the feature table created from the service layer specified in 'LAYER_ID'
GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTableByServiceLayerId(LAYER_ID);
添加要素(Add features)
private void addFeature(Point point) {
// 创建要素的属性信息
java.util.Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("typdamage", "Minor");
attributes.put("primcause" , "Earthquake");
//创建要素的空间信息并关联属性信息
Feature feature = damageTable.createFeature(attributes, point);
//添加要素
damageTable.addFeatureAsync(feature);
//同步编辑到ArcGIS Server
damageTable.applyEditsAsync();
}
核实要素添加结果
final ListenableFuture<Void> result = damageTable.addFeatureAsync(feature);
result.addDoneListener(new Runnable() {
@Override
public void run() {
try {
// 追踪FeatureTable,核实要素添加成功
result.get();
if (result.isDone()) {
System.out.println("success");
}
} catch (InterruptedException | ExecutionException e) {
}
}
});
更新要素(Update features)
private void updateAttributes() {
//get a list of selected features
final ListenableFuture<FeatureQueryResult> selected = damageFeatureLayer.getSelectedFeaturesAsync();
selected.addDoneListener(new Runnable() {
@Override
public void run() {
try {
//loop through selected features
for (Feature feature : selected.get()) {
//change the attribute
feature.getAttributes().put("typdamage", "Inaccessible");
//move it North a little
Point currentLoc = (Point) feature.getGeometry();
Point updatedLoc = new Point(currentLoc.getX(), currentLoc.getY() + 50000, mapView.getSpatialReference());
feature.setGeometry(updatedLoc);
//update the feature
damageTable.updateFeatureAsync(feature);
}
//commit update operation
damageTable.applyEditsAsync();
} catch (Exception e) {
// write error code here
e.printStackTrace();
}
}
});
}
删除要素(Delete features)
private void deleteFeatures() {
//get a list of selected features
final ListenableFuture<FeatureQueryResult> selected = damageFeatureLayer.getSelectedFeaturesAsync();
selected.addDoneListener(new Runnable() {
@Override
public void run() {
try {
//delete features
damageTable.deleteFeaturesAsync(selected.get());
//commit delete operation
damageTable.applyEditsAsync();
} catch (Exception e) {
// write error code here
e.printStackTrace();
}
}
});
}
要素附件(Feature attachments)
要素附件可以是文本、图片、视频等。涉及的方法如下:
- add attachment :给要素添加附件
- delete attachment :删除要素附件
- delete attachments :删除要素的一组附件
- update attachment :更新要素附件
- fetch attachments:访问要素附件
//get as an ArcGIS Feature so we can add attachments
ArcGISFeature agsFeature = (ArcGISFeature) feature;
//add the attachment
agsFeature.addAttachmentAsync( new File(folderPath + "AssessmentImage.jpg"), "image/jpg", "assessment imaqe.jpg");
//save the attachments in the feature
damageTable.updateFeatureAsync(agsFeature);
//commit update operation
damageTable.applyEditsAsync();