安卓智能地图开发与实施十四:业务数据编辑

来源:互联网 发布:多空指标软件 编辑:程序博客网 时间:2024/05/22 10:49

业务图层(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发布服务

http://server.arcgis.com/zh-cn/server/latest/publish-services/windows/publishing-feature-services.htm

配置要素服务数据以供离线使用

http://server.arcgis.com/zh-cn/server/latest/get-started/windows/tutorial-set-up-feature-service-data-for-offline-use.htm

FeatureTable中的编辑方法

涉及到要素编辑的方法都存储在FeatureTable(com.esri.arcgisruntime.data)中:
添加要素:addFeatureAsync、addFeaturesAsync
删除要素:deleteFeatureAsync、deleteFeaturesAsync
更新要素:updateFeatureAsync、updateFeaturesAsync

创建FeatureTable

在线编辑与离线编辑在实施层面都是相同的,只是离线编辑多了同步工作。

在线:ServiceFeatureTable

private ServiceFeatureTable damageTable;...//generate feature table from servicedamageTable = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");

离线:GeodatabaseFeatureTable

// Open the local geodatabase fileGeodatabase 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 ServerdamageTable.applyEditsAsync();}

核实要素添加结果

final ListenableFuture<Void> result = damageTable.addFeatureAsync(feature);result.addDoneListener(new Runnable() {@Overridepublic 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 featuresfinal ListenableFuture<FeatureQueryResult> selected = damageFeatureLayer.getSelectedFeaturesAsync();selected.addDoneListener(new Runnable() {@Overridepublic void run() {try {//loop through selected featuresfor (Feature feature : selected.get()) {//change the attributefeature.getAttributes().put("typdamage", "Inaccessible");//move it North a littlePoint currentLoc = (Point) feature.getGeometry();Point updatedLoc = new Point(currentLoc.getX(), currentLoc.getY() + 50000, mapView.getSpatialReference());feature.setGeometry(updatedLoc);//update the featuredamageTable.updateFeatureAsync(feature);}//commit update operationdamageTable.applyEditsAsync();} catch (Exception e) {// write error code heree.printStackTrace();}}});}

删除要素(Delete features)

private void deleteFeatures() {//get a list of selected featuresfinal ListenableFuture<FeatureQueryResult> selected = damageFeatureLayer.getSelectedFeaturesAsync();selected.addDoneListener(new Runnable() {@Overridepublic void run() {try {//delete featuresdamageTable.deleteFeaturesAsync(selected.get());//commit delete operationdamageTable.applyEditsAsync();} catch (Exception e) {// write error code heree.printStackTrace();}}});}

要素附件(Feature attachments)

要素附件可以是文本、图片、视频等。涉及的方法如下:

  • add attachment :给要素添加附件
  • delete attachment :删除要素附件
  • delete attachments :删除要素的一组附件
  • update attachment :更新要素附件
  • fetch attachments:访问要素附件
//get as an ArcGIS Feature so we can add attachmentsArcGISFeature agsFeature = (ArcGISFeature) feature;//add the attachmentagsFeature.addAttachmentAsync( new File(folderPath + "AssessmentImage.jpg"), "image/jpg", "assessment imaqe.jpg");//save the attachments in the featuredamageTable.updateFeatureAsync(agsFeature);//commit update operationdamageTable.applyEditsAsync();
阅读全文
0 0
原创粉丝点击