[TOC]
第十三、十四课时特征编辑
features编辑
How your features are stored affects how you make and manage edits to them in your app.
features如何保存影响你如何去在你的应用中编辑他们。
FeatureTable的关系
graph LR
FeatureTable_add_update_delete-->ArcGISFeatureTable编辑附件
FeatureTable_add_update_delete-->FeatureCollectionTable_portal不包括附件
ArcGISFeatureTable编辑附件-->GeodatabaseFeatureTable离线
ArcGISFeatureTable编辑附件-->ServiceFeatureTable在线
展示features
var table = new ServiceFeatureTable(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0"));
await table.LoadAsync();
if (table.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
var flayer = new FeatureLayer(table);
myMap.OperationalLayers.Add(flayer);
}
添加features
private async void AddDamageFeature(MapPoint structureLocation, long type, string commit)
{
var attributes = new Dictionary<string, object>();
attributes.Add("req_type", "Sidewalk and Curb Issues");
attributes.Add("status ", 1);
// create a new feature in the damage table, pass in the attributes and geometry
var newFeature = table.CreateFeature(attributes, structureLocation);
// add the new feature (this updates the local copy of the table)
await table.AddFeatureAsync(newFeature);
// push this update (apply edits) to the feature service
IReadOnlyList<EditResult> editResults = await table.ApplyEditsAsync();
// check the results for errors
foreach (var r in editResults)
{
if (r.CompletedWithErrors)
{
Console.WriteLine("Edit to Object '" + r.ObjectId + "' failed: " + r.Error.Message);
}
}
}
识别features
double mapTolerance = tolerance * myMapView.UnitsPerPixel;
var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance,
e.Location.Y + mapTolerance, myMapView.Map.SpatialReference);
var query = new QueryParameters();
query.Geometry = selectionEnvelope;
query.SpatialRelationship = SpatialRelationship.Within;
FeatureLayer fl = myMap.OperationalLayers[0] as FeatureLayer;
await fl.SelectFeaturesAsync(query, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
更新feature
var damageLayer = myMapView.Map.OperationalLayers[1] as FeatureLayer;
var selectedFeatures = await damageLayer.GetSelectedFeaturesAsync();
foreach (ArcGISFeature f in selectedFeatures)
{
await f.LoadAsync();
f.Attributes["req_type"] = "Tree Maintenance or Damage";
//var location = f.Geometry as MapPoint;
//var newLocation = new MapPoint(location.X, location.Y+5);
//f.Geometry = newLocation;
await table.UpdateFeatureAsync(f);
}
var editResults = await table.ApplyEditsAsync();
删除feature
var damageLayer = myMapView.Map.OperationalLayers[1] as FeatureLayer;
var selectedFeatures = await damageLayer.GetSelectedFeaturesAsync();
await table.DeleteFeaturesAsync(selectedFeatures);
var editResults = await table.ApplyEditsAsync();
添加附件
var damageLayer = myMapView.Map.OperationalLayers[1] as FeatureLayer;
var selectedFeatures = await damageLayer.GetSelectedFeaturesAsync();
// cast to ArcGISFeature to add attachments
ArcGISFeature agsFeature = (ArcGISFeature)selectedFeatures.FirstOrDefault();
await agsFeature.LoadAsync();
await agsFeature.AddAttachmentAsync("timg.jpg", "image/jpg", AuthGetFileData(@"C:\Users\tom\Desktop\timg.jpg"));
await table.UpdateFeatureAsync(agsFeature);
IReadOnlyList<EditResult> results = await table.ApplyEditsAsync();
var errs = from er in results where er.CompletedWithErrors select er;
foreach (var err in errs)
{
Console.WriteLine(err.ToString());
}
geometries编辑
Geometry Builders
Geometry builders (or builders for short) create or change geometry. A geometry builder contains the same things a geometry contains—vertices, segments, and parts—allowing its state to be changed as needed.
工作流程
graph LR
创建builder-->修改
修改-->ToGeometry