来自:https://developers.arcgis.com/android/guide/edit-features.htm#ESRI_SECTION1_56C60DB71AF941E98668AFB991A1B9C9

Edit features

In this topic

You can let users edit features while online (connected) or offline (disconnected). Editing includes adding new features, deleting features, and updating existing features by changing their geometry (location or shape), attributes, or attachments. There are two models for editing features: feature table editing and feature layer editing. This topic focuses on feature table editing. For an introduction to editing and the editing models, see Editing.

Whether you are online or offline, the workflow to edit features is similar. In both cases, you need to do the following:

  1. Create a feature table—In a connected workflow, create it from a feature service. In a disconnected workflow, create it from a geodatabase you generated with a sync-enabled feature service before you went offline, as described in Create an offline map.
  2. Create a feature layer from the feature table and add the layer to the map.
  3. Perform any edits against the feature table (add, update, and delete features and feature attachments).
  4. Commit your edits—In a connected workflow, apply any edits you make to the feature service right away. In a disconnected workflow, sync all your edits back to the service once you have a network connection, as described inSync offline edits.

In a connected workflow, the type of feature table you create and edit is a GeodatabaseFeatureServiceTable. In a disconnected workflow, the type of feature table you create and edit is a GeodatabaseFeatureTable. The class hierarchy between these is as follows:

The methods to add, update, and delete features and feature attachments are common to FeatureTable andGeodatabaseFeatureTable. Therefore, all the methods you have at your disposal to edit in an offline workflow are also available for an online workflow, since GeodatabaseFeatureServiceTable inherits GeodatabaseFeatureTable. TheGeodatabaseFeatureServiceTable used in connected editing provides additional methods to apply feature edits and attachment edits back to the service. You should apply any edits to the service as soon as you have made them on your feature table.

To update or delete features, your app should enable users to select features on the map, as described below inSelect features.

Create a feature table

Before you can edit features, you need to obtain feature data from a feature service. In an online workflow, create a feature table from a feature service right before you want to edit features, for example, on application load. In an offline workflow, generate a geodatabase from a sync-enabled feature service while you have a network connection, in preparation for editing features offline. When offline, create feature tables from the geodatabase to edit the features locally. In both cases, check the capabilities of the feature service to ensure the editing capability is available.

Online

In an online workflow, create a geodatabase feature service table from a feature service. You can then create a feature layer using this feature table. Once you add the feature layer to a map, features in the map extent are added to the feature service table and can be edited. As you pan and zoom the map (that is, change the map extent), more features are retrieved from the feature service and added to the geodatabase feature service table.

Note:

The number of features you see when you initially visit a new area of the map is limited by the feature service's MaxRecordCount property (the default value for this property is 1,000). Pan and zoom to query the service for more features. Once features are retrieved from the service and visible in your map, they are available in your geodatabase feature service table for editing and querying.

featureServiceTable =
new GeodatabaseFeatureServiceTable(FEATURE_SERVICE_URL, LAYER_ID);
// you can set the spatial reference of the table here
// if not set, the service's spatial reference will be used
featureServiceTable.setSpatialReference(SpatialReference.create(102100)); // initialize the table asynchronously
featureServiceTable.initialize(
new CallbackListener<GeodatabaseFeatureServiceTable.Status>() { @Override
public void onError(Throwable e) {
// report/handle error as desired
System.out.println(featureServiceTable.getInitializationError());
} @Override
public void onCallback(Status status) {
if (status == Status.INITIALIZED) {
// ...create a FeatureLayer from the GeodatabaseFeatureServiceTable...
}
}
});

As shown above, once you create a GeodatabaseFeatureServiceTable instance, you can set the table's spatial reference by calling setSpatialReference. This must be done before you call the initialize method on the table. If you do not explicitly set the spatial reference of the table this way, the spatial reference of the service will be used. However, if your map is in a difference spatial reference than your GeodatabaseFeatureServiceTable, your features will not appear on the map, so it is good practice to always set the spatial reference explicitly.

You can set your table's spatial reference to the spatial reference of your map once the map is initialized by setting an OnStatusChanged callback on the MapView:

map.setOnStatusChangedListener(new OnStatusChangedListener() {
private static final long serialVersionUID = 1L;
@Override
public void onStatusChanged(Object source, STATUS status) {
if(source == map && STATUS.INITIALIZED == status) {
SpatialReference mapSR = event.getMap().getSpatialReference();
featureServiceTable = new GeodatabaseFeatureServiceTable(FEATURE_SERVICE_URL, LAYER_ID);
// set the table's spatial reference to be the same as the map's
featureServiceTable.setSpatialReference(mapSR);
// ...initialize GeodatabaseFeatureServiceTable...
}
}
});

Offline

In an offline workflow, generate a geodatabase from a sync-enabled feature service while you have a network connection. Follow the geodatabase generation process described in Create an offline map. This process results in a geodatabase stored locally on disk. The geodatabase contains one or more feature tables, one for each service layer or service table that you requested in the geodatabase generation process. When offline, create geodatabase feature tables (GeodatabaseFeatureTable class) from the geodatabase, for example, on application load. The features in the geodatabase feature tables are available for editing whether you create a feature layer or not, but in most cases you'll want to create a feature layer from the feature tables to display the features on a map. Also, consider generating an offline basemap to give the feature data some geographical context when your users edit offline, as described in Include a basemap.

The following code sample shows how to create a feature table from a local geodatabase:

 
// 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.getGeodatabaseFeatureTableByLayerId(LAYER_ID); // Create a FeatureLayer from the GeodatabaseFeatureTable and then use the layer...
Note:

The Geodatabase constructor used above throws a FileNotFoundException if the geodatabase file cannot be found. You must surround this line with a try-catch block, if the surrounding method itself does not declare that it throws this exception.

Add layers to the map

Display the features contained in the feature table in a map so your users can view and edit them. Create a feature layer from the feature table and add the layer to a map. The feature layer, once added to a map, takes care of displaying the features contained in your feature table that fall within the map extent displayed. When you make edits to features in the table, these edits are visible right away in the associated feature layer and map, but not yet committed back to the service.

The following code sample shows how to create a feature layer from a feature table:

private Geodatabase geodatabase = null;
private GeodatabaseFeatureTable geodatabaseFeatureTable;
private FeatureLayer featureLayer; //open the local geodatabase file
geodatabase = new Geodatabase(PATH_TO_GEODATABASE); //open the layer in the geodatabase created from the service layer specified in 'LAYER_ID'
geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTableByLayerId(LAYER_ID); //create a feature layer and add it to the map
featureLayer = new FeatureLayer(geodatabaseFeatureTable);
map.addLayer(featureLayer);

Add features

To add or insert new features into a geodatabase table, create the geometry (for example, point, line, or polygon) and attributes for the new feature, and then call the addFeature method. This method returns the unique feature ID of the added feature, which you can store for later use, such as if you want to modify the geometry or attributes of this particular feature later on. Adding a feature to a geodatabase table is shown in the code below:

//make a map of attributes
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("TYPDAMAGE", "Minor");
attributes.put("PRIMCAUSE" , "Earthquake");
attributes.put("TYPDAMAGE_INT", new Integer(3)); try {
//Create a feature with these attributes at the given point
GeodatabaseFeature gdbFeature = new GeodatabaseFeature(attributes, point, geodatabaseFeatureTable); //Add the feature into the geodatabase table returning the new feature ID
long fid = geodatabaseFeatureTable.addFeature(gdbFeature); String geomStr = geodatabaseFeatureTable.getFeature(fid).getGeometry().toString();
Log.d(TAG, "added fid = " + fid + " " + geomStr);
} catch (TableException e) {
// report errors, e.g. to console
Log.e(TAG, "", e);
}

Update features

Features can be updated with the updateFeature method on the GeodatabaseFeatureTable.

The code sample below shows a method that updates a point feature in the geodatabase feature table with a new point geometry, changing its location on the map.

public void updateFeature(long featureID, Point newLocation) {
try {
//calls the API method updateFeature taking a feature ID and the new geometry
gdbFeatureTable.updateFeature(featureID, newLocation);
} catch (TableException e) {
// report/handle exception
Log.e(TAG, "", e);
}
}

Delete features

Features are deleted using the unique ID of the feature you want to delete. This unique ID can be stored when you add a feature to a geodatabase table or can be obtained, for example, through a query on the table. If you have selected the features to delete, the following line of code removes them from the layer:

geodatabaseFeatureTable.deleteFeatures(featureLayer.getSelectionIDs());

Select features

In a typical map application involving editing, users should be able to select features to edit. You can programmatically select features in a feature layer using their unique IDs. You can obtain feature IDs by performing a query on the feature table from which the feature layer was created, or by letting your users tap the map and obtain the IDs of any features within a certain pixel tolerance around the tapped point. The following code sample shows how to use a single tap event listener on the map to select tapped features:

mMapView.setOnSingleTapListener(new OnSingleTapListener() {
private static final long serialVersionUID = 1L; public void onSingleTap(float x, float y) {
// gets the first 1000 features at the clicked point on the map, within 5 pixels
long[] selectedFeatures = featureLayer.getFeatureIDs(x, y, 5, 1000);
// select the features
featureLayer.selectFeatures(selectedFeatures, false);
}
}

Commit your edits

Committing your feature table edits to the feature service is different depending on whether your workflow is fully connected or disconnected.

Online

In a fully connected workflow, you should apply feature edits and attachment edits back to the service as you make them. That way, anyone else using the same feature service will have access to your changes right away.

To commit your local feature edits to the service, call the applyEdits method. Optionally, you can list the current locally edited features by using getAddedFeatures()getUpdatedFeatures(), and getDeletedFeatures(). Changes to the features returned by those three methods will be committed to the service on a call to applyEdits. Once the edits have been applied, newly added features will be given the server-generated object ID. You can find out the value of the new object ID by passing the locally held object ID to the method lookupObjectID, before calling applyEdits. TheapplyEdits method is asynchronous; any errors from this method call will be returned in a callback as a list ofGeodatabaseEditError objects.

To commit your local feature attachment edits to the service, call the applyAttachmentEdits method. A feature needs to exist on the server before attachment edits for this feature can be applied. Generally, you should callapplyAttachmentEdits after a successful call to applyEdits. The applyAttachmentEdits method is asynchronous; any errors from this method call will be returned in a callback as a list of GeodatabaseEditError objects.

Note:

For descriptions of errors that can arise during edit commits, go to the Apply Edits (Feature Service) topic and click the error code link in the Description section.

Offline

In a disconnected workflow, commit all edits back to the service, and optionally pull the latest changes from the service back to your geodatabase through a sync operation, as described in Sync offline edits. Syncing requires a network connection; therefore, do this when you are back online. Note that the edits that are last committed to the service will overwrite previously committed edits, even if committed edits were made at a later time.

arcgis andriod Edit features的更多相关文章

  1. arcgis andriod 点击后变色

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  2. arcgis andriod开发程序实例,有图有真相

    本程序使用Google公司最新开发工具andriod studio开发,实现了地图的加载,放大,缩小,GPS定位,画点.线,面工具,本程序有偿提供源代码 主界面,加载tpk切片 放大: 加载geoda ...

  3. arcgis andriod 长按获得当前信息

    // 长按显示鼠标点坐标及比例尺 private class myLongPressListener implements OnLongPressListener { private static f ...

  4. arcgis andriod GeometryEngine使用

    intersectionMenuItem.setChecked(true); showGeometry(GeometryEngine.intersection(inputPolygon1, input ...

  5. arcgis andriod 加载影像

    MapView mMapView;......String rasterPath = Environment.getExternalStorageDirectory().getPath() + &qu ...

  6. leaflet地图库

    an open-source JavaScript libraryfor mobile-friendly interactive maps Overview Tutorials Docs Downlo ...

  7. ArcEngine二次开发错误编码对照表(转)

    阅读数:3323 每当我们在进行AE开发,出现错误时经常会出现错误代码,但是我们并不知道它到底代表什么意思,这里的而错误编码我们可以对照着找到我们需要的时候常详细信息(问题是,经常还是会出现没有错误编 ...

  8. ArcMap所有Command GUID

    The information in this topic is useful if you're trying to programmatically find a built-in command ...

  9. AE错误代码解释

    每当我们在进行AE开发,出现错误时经常会出现错误代码,但是我们并不知道它到底代表什么意思,这里的而错误编码我们可以对照着找到我们需要的时候常详细信息(问题是,经常还是会出现没有错误编码HRESULT ...

随机推荐

  1. 利用PowerDesigner逆向工程导出PDM模型及生成文档

    原文:利用PowerDesigner逆向工程导出PDM模型及生成文档 最近需要对老项目进行重构优化,由于项目都是好几年前的,相关设计资料很不全,最基本的数据库设计文档都没有,只能利用PowerDesi ...

  2. day02 Python 的模块,运算,数据类型以及方法

    初识pyhton的模块: 什么是模块: 我的理解就是实现一个功能的函数,把它封装起来,在你需要使用的时候直接调用即可,我的印象里类似于shell 的单独函数脚本. python 的模块分为标准的和第三 ...

  3. 【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸

    多维数组声明 数据类型[][] 数组名称; 数据类型[] 数组名称[]; 数据类型数组名称[][]; 以上三种语法在声明二维数组时的功能是等价的.同理,声明三维数组时需要三对中括号,中括号的位置可以在 ...

  4. 聊聊、Nginx 初始化日志文件

    我们接着上一篇文章继续来看看 ngx_regex_init()函数.搜索 ngx_regex_init 得到位置为src/core/ngx_regex.c:ngx_regex_init(void). ...

  5. [git 学习篇]版本回退

    再次修改readme.txt ,并将其提交成功 $ git add readme.txt $ git commit -m "append GPL" [master ] append ...

  6. 【mysql 优化 5】左连接和右连接优化

    原文地址:8.2.1.8 Left Join and Right Join Optimization mysql以下列方式实现一个A left join B 连接条件: 1,表B设置为依赖于表A和A所 ...

  7. BZOJ3697 采药人的路径 【点分治】

    题目 采药人的药田是一个树状结构,每条路径上都种植着同种药材. 采药人以自己对药材独到的见解,对每种药材进行了分类.大致分为两类,一种是阴性的,一种是阳性的. 采药人每天都要进行采药活动.他选择的路径 ...

  8. webpack错误Chunk.entry was removed. Use hasRuntime()

    这个错误在从webpack1升级webpack2或webpack3时候都遇到了,起初查到的都是extract-text-webpack-plugin版本的问题,升级了还是不管用.搜索引擎上查不到其他的 ...

  9. 数据库操作之——key与index的区别

    mysql的key和index多少有点令人迷惑,这实际上考察对数据库体系结构的了解的. 1 key 是数据库的物理结构,它包含两层意义,一是约束(偏重于约束和规范数据库的结构完整性),二是索引(辅助查 ...

  10. APUE 学习笔记(四) 标准I/O库

    1.流与FILE对象 unix I/O系统调用都是针对文件描述符的 标准C的I/O函数都是针对流(文件指针)的,我们使用一个流与一个文件相关联   2.缓冲 标准I/O库提供缓冲的目的就是尽可能减少r ...