internal void OnDeleteRouteButtonClick() { QueuedTask.Run(() => { using (var cursor = RoutesStandaloneTable.GetSelection().Search(null)) { var operation = new EditOperation(); cursor.MoveNext(); var routeRow = cursor.Current; string routeID = (string)routeRow[RouteID]; string routeName = (string)routeRow[RouteName]; operation.Name = $"Delete route: {routeName}"; operation.Delete(RoutesStandaloneTable, routeRow.GetObjectID()); var query = new QueryFilter() { WhereClause = $"{RouteID} = '{routeID}'" }; using (var segsCursor = RouteToTrailSegmentsTable.Search(query)) using (var headsCursor = RouteToTrailheadsTable.Search(query)) { while (segsCursor.MoveNext()) { operation.Delete(RouteToTrailSegmentsTable, segsCursor.Current.GetObjectID()); } while (headsCursor.MoveNext()) { operation.Delete(RouteToTrailheadsTable, headsCursor.Current.GetObjectID()); } } operation.Execute(); if (operation.IsSucceeded) { Notification notification = new Notification(); notification.Title = FrameworkApplication.Title; notification.Message = $"Route: \"{routeName}\" deleted successfully!"; FrameworkApplication.AddNotification(notification); RoutesStandaloneTable.ClearSelection(); } else { MessageBox.Show(operation.ErrorMessage); } } }); }
public async static void DeleteAllFeatures(BasicFeatureLayer layer) { var deleteOp = new EditOperation(); deleteOp.Delete(layer, SharedFunctions.GetAllIdsFromLayer(layer)); await deleteOp.ExecuteAsync(); }
private async Task DeleteCandidates(List <CandidateDam> candidates, BasicFeatureLayer damCandidatesLayer, List <CandidateDam> candidatesToDelete) { foreach (var candidateToDelete in candidatesToDelete) { candidates.Remove(candidateToDelete); OutgoingCandidates--; } if (candidatesToDelete.Count > 0) { var deleteOp = new EditOperation(); deleteOp.Delete(damCandidatesLayer, candidatesToDelete.Select(c => c.ObjectID).ToList()); await deleteOp.ExecuteAsync(); } }
/// <summary> /// Deletes Currently Selected Features and zooms to next feature if applicable /// </summary> public async void Delete() { bool proceed = false; proceed = await PrepStatus(); if (!proceed) { return; } if (!FeaturesSelected()) { return; } await QueuedTask.Run(() => { try { var basicfeaturelayer = _selectedLayer as BasicFeatureLayer; var selection = basicfeaturelayer.GetSelection(); var oidset = selection.GetObjectIDs(); var op = new EditOperation(); op.Name = "Delete Next"; foreach (var oid in oidset) { op.Delete(basicfeaturelayer, oid); } op.Execute(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }); GoToNext(_selectedLayer, false); }
private async void DoDelete() { var crimes = Module1.Current.Crimes; if (NoCrimes(crimes)) { return; } bool noSelect = true; var editOp = new EditOperation(); editOp.Name = $"Delete {Module1.Current.CrimesLayerName}"; await QueuedTask.Run(() => { using (var select = crimes.GetSelection()) { if (select.GetCount() > 0) { noSelect = false; editOp.Delete(crimes, select.GetObjectIDs()); editOp.Execute(); } } if (!_cancelEdit && !_failvalidate) { crimes.ClearSelection(); } }); if (noSelect) { NothingSelected(); } }
public void EditOperations() { var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList()[0] as FeatureLayer; var polygon = new PolygonBuilder().ToGeometry(); var clipPoly = new PolygonBuilder().ToGeometry(); var cutLine = new PolylineBuilder().ToGeometry(); var modifyLine = cutLine; var oid = 1; #region Edit Operation Create Features var createFeatures = new EditOperation(); createFeatures.Name = "Create Features"; //Create a feature with a polygon createFeatures.Create(featureLayer, polygon); //with a callback createFeatures.Create(featureLayer, polygon, (object_id) => { //TODO - use the oid of the created feature //in your callback }); //Do a create features and set attributes var attributes = new Dictionary <string, object>(); attributes.Add("SHAPE", polygon); attributes.Add("NAME", "Corner Market"); attributes.Add("SIZE", 1200.5); attributes.Add("DESCRIPTION", "Corner Market"); createFeatures.Create(featureLayer, attributes); //Create features using the current template //Must be within a MapTool createFeatures.Create(this.CurrentTemplate, polygon); //Execute to execute the operation //Must be called within QueuedTask.Run createFeatures.Execute(); //or use async flavor //await createFeatures.ExecuteAsync(); #endregion #region Edit Operation Clip Features var clipFeatures = new EditOperation(); clipFeatures.Name = "Clip Features"; clipFeatures.Clip(featureLayer, oid, clipPoly, ClipMode.PreserveArea); //Execute to execute the operation //Must be called within QueuedTask.Run clipFeatures.Execute(); //or use async flavor //await clipFeatures.ExecuteAsync(); #endregion #region Edit Operation Cut Features var select = MapView.Active.SelectFeatures(clipPoly); var cutFeatures = new EditOperation(); cutFeatures.Name = "Cut Features"; cutFeatures.Cut(featureLayer, oid, cutLine); //Cut all the selected features in the active view //Select using a polygon (for example) var kvps = MapView.Active.SelectFeatures(polygon).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); cutFeatures.Cut(kvps, cutLine); //Execute to execute the operation //Must be called within QueuedTask.Run cutFeatures.Execute(); //or use async flavor //await cutFeatures.ExecuteAsync(); #endregion #region Edit Operation Delete Features var deleteFeatures = new EditOperation(); deleteFeatures.Name = "Delete Features"; var table = MapView.Active.Map.StandaloneTables[0]; //Delete a row in a standalone table deleteFeatures.Delete(table, oid); //Delete all the selected features in the active view //Select using a polygon (for example) var selection = MapView.Active.SelectFeatures(polygon).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); deleteFeatures.Delete(selection); //Execute to execute the operation //Must be called within QueuedTask.Run deleteFeatures.Execute(); //or use async flavor //await deleteFeatures.ExecuteAsync(); #endregion #region Edit Operation Duplicate Features var duplicateFeatures = new EditOperation(); duplicateFeatures.Name = "Duplicate Features"; //Duplicate with an X and Y offset of 500 map units duplicateFeatures.Duplicate(featureLayer, oid, 500.0, 500.0, 0.0); //Execute to execute the operation //Must be called within QueuedTask.Run duplicateFeatures.Execute(); //or use async flavor //await duplicateFeatures.ExecuteAsync(); #endregion #region Edit Operation Explode Features var explodeFeatures = new EditOperation(); explodeFeatures.Name = "Explode Features"; //Take a multipart and convert it into one feature per part //Provide a list of ids to convert multiple explodeFeatures.Explode(featureLayer, new List <long>() { oid }, true); //Execute to execute the operation //Must be called within QueuedTask.Run explodeFeatures.Execute(); //or use async flavor //await explodeFeatures.ExecuteAsync(); #endregion var destinationLayer = featureLayer; #region Edit Operation Merge Features var mergeFeatures = new EditOperation(); mergeFeatures.Name = "Merge Features"; //Merge three features into a new feature using defaults //defined in the current template mergeFeatures.Merge(this.CurrentTemplate as EditingFeatureTemplate, featureLayer, new List <long>() { 10, 96, 12 }); //Merge three features into a new feature in the destination layer mergeFeatures.Merge(destinationLayer, featureLayer, new List <long>() { 10, 96, 12 }); //Use an inspector to set the new attributes of the merged feature var inspector = new Inspector(); inspector.Load(featureLayer, oid);//base attributes on an existing feature //change attributes for the new feature inspector["NAME"] = "New name"; inspector["DESCRIPTION"] = "New description"; //Merge features into a new feature in the same layer using the //defaults set in the inspector mergeFeatures.Merge(featureLayer, new List <long>() { 10, 96, 12 }, inspector); //Execute to execute the operation //Must be called within QueuedTask.Run mergeFeatures.Execute(); //or use async flavor //await mergeFeatures.ExecuteAsync(); #endregion #region Edit Operation Modify single feature var modifyFeature = new EditOperation(); modifyFeature.Name = "Modify a feature"; //use an inspector var modifyInspector = new Inspector(); modifyInspector.Load(featureLayer, oid);//base attributes on an existing feature //change attributes for the new feature modifyInspector["SHAPE"] = polygon; //Update the geometry modifyInspector["NAME"] = "Updated name"; //Update attribute(s) modifyFeature.Modify(modifyInspector); //update geometry and attributes using overload var featureAttributes = new Dictionary <string, object>(); featureAttributes["NAME"] = "Updated name";//Update attribute(s) modifyFeature.Modify(featureLayer, oid, polygon, featureAttributes); //Execute to execute the operation //Must be called within QueuedTask.Run modifyFeature.Execute(); //or use async flavor //await modifyFeatures.ExecuteAsync(); #endregion #region Edit Operation Modify multiple features //Search by attribute var queryFilter = new QueryFilter(); queryFilter.WhereClause = "OBJECTID < 1000000"; //Create list of oids to update var oidSet = new List <long>(); using (var rc = featureLayer.Search(queryFilter)) { while (rc.MoveNext()) { oidSet.Add(rc.Current.GetObjectID()); } } //create and execute the edit operation var modifyFeatures = new EditOperation(); modifyFeatures.Name = "Modify features"; modifyFeatures.ShowProgressor = true; var insp = new Inspector(); insp.Load(featureLayer, oidSet); insp["MOMC"] = 24; modifyFeatures.Modify(insp); modifyFeatures.ExecuteAsync(); #endregion #region Move features //Get all of the selected ObjectIDs from the layer. var firstLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(); var selectionfromMap = firstLayer.GetSelection(); // set up a dictionary to store the layer and the object IDs of the selected features var selectionDictionary = new Dictionary <MapMember, List <long> >(); selectionDictionary.Add(firstLayer as MapMember, selectionfromMap.GetObjectIDs().ToList()); var moveFeature = new EditOperation(); moveFeature.Name = "Move features"; moveFeature.Move(selectionDictionary, 10, 10); //specify your units along axis to move the geometry moveFeature.Execute(); #endregion #region Move feature to a specific coordinate //Get all of the selected ObjectIDs from the layer. var abLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(); var mySelection = abLayer.GetSelection(); var selOid = mySelection.GetObjectIDs().FirstOrDefault(); var moveToPoint = new MapPointBuilder(1.0, 2.0, 3.0, 4.0, MapView.Active.Map.SpatialReference); //can pass in coordinates. var modifyFeatureCoord = new EditOperation(); modifyFeatureCoord.Name = "Move features"; modifyFeatureCoord.Modify(abLayer, selOid, moveToPoint.ToGeometry()); //Modify the feature to the new geometry modifyFeatureCoord.Execute(); #endregion #region Edit Operation Planarize Features var planarizeFeatures = new EditOperation(); planarizeFeatures.Name = "Planarize Features"; //Planarize one or more features planarizeFeatures.Planarize(featureLayer, new List <long>() { oid }); //Execute to execute the operation //Must be called within QueuedTask.Run planarizeFeatures.Execute(); //or use async flavor //await planarizeFeatures.ExecuteAsync(); #endregion #region Edit Operation Reshape Features var reshapeFeatures = new EditOperation(); reshapeFeatures.Name = "Reshape Features"; reshapeFeatures.Reshape(featureLayer, oid, modifyLine); //Reshape a set of features that intersect some geometry.... var selFeatures = MapView.Active.GetFeatures(modifyLine).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); reshapeFeatures.Reshape(selFeatures, modifyLine); //Execute to execute the operation //Must be called within QueuedTask.Run reshapeFeatures.Execute(); //or use async flavor //await reshapeFeatures.ExecuteAsync(); #endregion var origin = MapPointBuilder.CreateMapPoint(0, 0, null); #region Edit Operation Rotate Features var rotateFeatures = new EditOperation(); rotateFeatures.Name = "Rotate Features"; //Rotate works on a selected set of features //Get all features that intersect a polygon var rotateSelection = MapView.Active.GetFeatures(polygon).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); //Rotate selected features 90 deg about "origin" rotateFeatures.Rotate(rotateSelection, origin, Math.PI / 2); //Execute to execute the operation //Must be called within QueuedTask.Run rotateFeatures.Execute(); //or use async flavor //await rotateFeatures.ExecuteAsync(); #endregion #region Edit Operation Scale Features var scaleFeatures = new EditOperation(); scaleFeatures.Name = "Scale Features"; //Rotate works on a selected set of features var scaleSelection = MapView.Active.GetFeatures(polygon).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); //Scale the selected features by 2.0 in the X and Y direction scaleFeatures.Scale(scaleSelection, origin, 2.0, 2.0, 0.0); //Execute to execute the operation //Must be called within QueuedTask.Run scaleFeatures.Execute(); //or use async flavor //await scaleFeatures.ExecuteAsync(); #endregion var mp1 = MapPointBuilder.CreateMapPoint(0, 0, null); var mp2 = mp1; var mp3 = mp1; #region Edit Operation Split Features var splitFeatures = new EditOperation(); splitFeatures.Name = "Split Features"; var splitPoints = new List <MapPoint>() { mp1, mp2, mp3 }; //Split the feature at 3 points splitFeatures.Split(featureLayer, oid, splitPoints); // split using percentage var splitByPercentage = new SplitByPercentage() { Percentage = 33, SplitFromStartPoint = true }; splitFeatures.Split(featureLayer, oid, splitByPercentage); // split using equal parts var splitByEqualParts = new SplitByEqualParts() { NumParts = 3 }; splitFeatures.Split(featureLayer, oid, splitByEqualParts); // split using single distance var splitByDistance = new SplitByDistance() { Distance = 27.3, SplitFromStartPoint = false }; splitFeatures.Split(featureLayer, oid, splitByDistance); // split using varying distance var distances = new List <double>() { 12.5, 38.2, 89.99 }; var splitByVaryingDistance = new SplitByVaryingDistance() { Distances = distances, SplitFromStartPoint = true, ProportionRemainder = true }; splitFeatures.Split(featureLayer, oid, splitByVaryingDistance); //Execute to execute the operation //Must be called within QueuedTask.Run splitFeatures.Execute(); //or use async flavor //await splitAtPointsFeatures.ExecuteAsync(); #endregion var linkLayer = featureLayer; #region Edit Operation Transform Features var transformFeatures = new EditOperation(); transformFeatures.Name = "Transform Features"; //Transform a selected set of features var transformSelection = MapView.Active.GetFeatures(polygon).Select( k => new KeyValuePair <MapMember, List <long> >(k.Key as MapMember, k.Value)); transformFeatures.Transform(transformSelection, linkLayer); //Transform just a layer transformFeatures.Transform(featureLayer, linkLayer); //Perform an affine transformation transformFeatures.TransformAffine(featureLayer, linkLayer); //Execute to execute the operation //Must be called within QueuedTask.Run transformFeatures.Execute(); //or use async flavor //await transformFeatures.ExecuteAsync(); #endregion #region Edit Operation Perform a Clip, Cut, and Planarize //Multiple operations can be performed by a single //edit operation. var clipCutPlanarizeFeatures = new EditOperation(); clipCutPlanarizeFeatures.Name = "Clip, Cut, and Planarize Features"; clipCutPlanarizeFeatures.Clip(featureLayer, oid, clipPoly); clipCutPlanarizeFeatures.Cut(featureLayer, oid, cutLine); clipCutPlanarizeFeatures.Planarize(featureLayer, new List <long>() { oid }); //Note: An edit operation is a single transaction. //Execute the operations (in the order they were declared) clipCutPlanarizeFeatures.Execute(); //or use async flavor //await clipCutPlanarizeFeatures.ExecuteAsync(); #endregion #region Edit Operation Chain Edit Operations //Chaining operations is a special case. Use "Chained Operations" when you require multiple transactions //to be undo-able with a single "Undo". //The most common use case for operation chaining is creating a feature with an attachement. //Adding an attachment requires the object id (of a new feature) has already been created. var editOperation1 = new EditOperation(); editOperation1.Name = string.Format("Create point in '{0}'", CurrentTemplate.Layer.Name); long newFeatureID = -1; //The Create operation has to execute so we can get an object_id editOperation1.Create(this.CurrentTemplate, polygon, (object_id) => newFeatureID = object_id); //Must be within a QueuedTask editOperation1.Execute(); //or use async flavor //await editOperation1.ExecuteAsync(); //Now, because we have the object id, we can add the attachment. As we are chaining it, adding the attachment //can be undone as part of the "Undo Create" operation. In other words, only one undo operation will show on the //Pro UI and not two. var editOperation2 = editOperation1.CreateChainedOperation(); //Add the attachement using the new feature id editOperation2.AddAttachment(this.CurrentTemplate.Layer, newFeatureID, @"C:\data\images\Hydrant.jpg"); //editOperation1 and editOperation2 show up as a single Undo operation on the UI even though //we had two transactions //Must be within a QueuedTask editOperation2.Execute(); //or use async flavor //await editOperation2.ExecuteAsync(); #endregion #region SetOnUndone, SetOnRedone, SetOnComitted // SetOnUndone, SetOnRedone and SetOnComittedManage can be used to manage // external actions(such as writing to a log table) that are associated with // each edit operation. //get selected feature and update attribute var selectedFeatures = MapView.Active.Map.GetSelection(); var testInspector = new Inspector(); testInspector.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First()); testInspector["Name"] = "test"; //create and execute the edit operation var updateTestField = new EditOperation(); updateTestField.Name = "Update test field"; updateTestField.Modify(insp); //actions for SetOn... updateTestField.SetOnUndone(() => { //Sets an action that will be called when this operation is undone. Debug.WriteLine("Operation is undone"); }); updateTestField.SetOnRedone(() => { //Sets an action that will be called when this editoperation is redone. Debug.WriteLine("Operation is redone"); }); updateTestField.SetOnComitted((bool b) => //called on edit session save(true)/discard(false). { // Sets an action that will be called when this editoperation is committed. Debug.WriteLine("Operation is committed"); }); updateTestField.Execute(); #endregion }
/// <summary> /// Separate a selected multipart feature into individual features. /// </summary> protected override void OnClick() { //check for one selected feature if (MapView.Active.Map.SelectionCount != 1) { MessageBox.Show("Please select one multipart feature to explode", "Explode Multipart Feature"); return; } //run on MCT QueuedTask.Run(() => { //get selected feature geometry var selectedFeatures = MapView.Active.Map.GetSelection(); var insp = new Inspector(); insp.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First()); var selGeom = insp.Shape; var selGeomType = selGeom.GeometryType; //early checks for geometry type and single point in a multipoint if ( !(selGeomType == GeometryType.Multipoint || selGeomType == GeometryType.Polygon || selGeomType == GeometryType.Polyline) || selGeom.PointCount == 1) { MessageBox.Show("Please select a multipart feature to explode", "Explode Multipart Feature"); return; } //check if selected feature has multiple parts var mpGeom = selGeom as Multipart; if (mpGeom != null) if (mpGeom.PartCount < 2) { MessageBox.Show("Please select a multipart feature to explode","Explode Multipart Feature"); return; } //setup the edit operation var op = new EditOperation(); op.Name = "Explode Multipart Feature"; //handle geometry types switch(selGeomType) { case GeometryType.Multipoint: //create a new feature for each pointcount var mpoint = selGeom as Multipoint; for (var i = 0; i < mpoint.PointCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new MultipointBuilder(mpoint.Points[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; case GeometryType.Polyline: //create a new feature for each polyline part for (var i = 0; i < mpGeom.PartCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new PolylineBuilder(mpGeom.Parts[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; case GeometryType.Polygon: //ignore donut features for now //check if any part area is negative for (var i = 0; i < mpGeom.PartCount; i++) { if ((new PolygonBuilder(mpGeom.Parts[i]).ToGeometry()).Area < 0) { MessageBox.Show("Please select a non-donut polygon to explode", "Explode Mutltpart Feature"); return; } } //create a new feature for each polygon part for (var i = 0; i < mpGeom.PartCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new PolygonBuilder(mpGeom.Parts[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; } //switch //delete the original feature and execute the creates //op.Delete(insp.MapMember, insp.ObjectID); //double cast to workaround 1.1 bug op.Delete(insp.MapMember, (long)(int)insp.ObjectIDAttribute.CurrentValue); op.Execute(); }); }
/// <summary> /// Separate a selected multipart feature into individual features. /// </summary> protected override void OnClick() { //check for one selected feature if (MapView.Active.Map.SelectionCount != 1) { MessageBox.Show("Please select one multipart feature to explode", "Explode Multipart Feature"); return; } //run on MCT QueuedTask.Run(() => { //get selected feature geometry var selectedFeatures = MapView.Active.Map.GetSelection(); var insp = new Inspector(); insp.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First()); var selGeom = insp.Shape; var selGeomType = selGeom.GeometryType; //early checks for geometry type and single point in a multipoint if (!(selGeomType == GeometryType.Multipoint || selGeomType == GeometryType.Polygon || selGeomType == GeometryType.Polyline) || selGeom.PointCount == 1) { MessageBox.Show("Please select a multipart feature to explode", "Explode Multipart Feature"); return; } //check if selected feature has multiple parts var mpGeom = selGeom as Multipart; if (mpGeom != null) { if (mpGeom.PartCount < 2) { MessageBox.Show("Please select a multipart feature to explode", "Explode Multipart Feature"); return; } } //setup the edit operation var op = new EditOperation(); op.Name = "Explode Multipart Feature"; //handle geometry types switch (selGeomType) { case GeometryType.Multipoint: //create a new feature for each pointcount var mpoint = selGeom as Multipoint; for (var i = 0; i < mpoint.PointCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new MultipointBuilder(mpoint.Points[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; case GeometryType.Polyline: //create a new feature for each polyline part for (var i = 0; i < mpGeom.PartCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new PolylineBuilder(mpGeom.Parts[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; case GeometryType.Polygon: //ignore donut features for now //check if any part area is negative for (var i = 0; i < mpGeom.PartCount; i++) { if ((new PolygonBuilder(mpGeom.Parts[i]).ToGeometry()).Area < 0) { MessageBox.Show("Please select a non-donut polygon to explode", "Explode Mutltpart Feature"); return; } } //create a new feature for each polygon part for (var i = 0; i < mpGeom.PartCount; i++) { //copy the original feature into a dictionary and update the shape. var newFeature = insp.ToDictionary(a => a.FieldName, a => a.CurrentValue); newFeature[insp.GeometryAttribute.FieldName] = new PolygonBuilder(mpGeom.Parts[i]).ToGeometry(); op.Create(insp.MapMember, newFeature); } break; } //switch //delete the original feature and execute the creates //op.Delete(insp.MapMember, insp.ObjectID); //double cast to workaround 1.1 bug op.Delete(insp.MapMember, (long)(int)insp.ObjectIDAttribute.CurrentValue); op.Execute(); }); }
public async void Examples2() { #region Determine if a FeatureSceneLayer supports editing var featSceneLayer = MapView.Active.Map.GetLayersAsFlattenedList() .OfType <FeatureSceneLayer>().FirstOrDefault(); if (!featSceneLayer.HasAssociatedFeatureService || !featSceneLayer.IsEditable) { return;//not supported } //TODO continue editing here... #endregion // create a new point at specified coordinates MapPoint mapPoint = MapPointBuilder.CreateMapPoint(122.39, 37.78); #region Create a new Point feature in FeatureSceneLayer //must support editing! //var featSceneLayer = ... ; if (!featSceneLayer.HasAssociatedFeatureService || !featSceneLayer.IsEditable) { return; } //Check geometry type...must be point in this example if (featSceneLayer.ShapeType != esriGeometryType.esriGeometryPoint) { return; } var editOp = new EditOperation() { Name = "Create new 3d point feature", SelectNewFeatures = true }; var attributes = new Dictionary <string, object>(); //mapPoint contains the new 3d point location attributes.Add("SHAPE", mapPoint); attributes.Add("TreeID", "1"); editOp.Create(featSceneLayer, attributes); editOp.ExecuteAsync();//fyi, no await #endregion #region Delete all the selected features in FeatureSceneLayer //must support editing! //var featSceneLayer = .... ; if (!featSceneLayer.HasAssociatedFeatureService || !featSceneLayer.IsEditable) { return; } var delOp = new EditOperation() { Name = "Delete selected features" }; //Assuming we have a selection on the layer... delOp.Delete(featSceneLayer, featSceneLayer.GetSelection().GetObjectIDs()); await delOp.ExecuteAsync();//await if needed but not required #endregion }
public void execute(CancelableProgressorSource status) { editOperation = new EditOperation(); editOperation.Name = "Delete routes"; Selection selection = routesLayer.GetSelection(); QueryFilter queryFilter = new QueryFilter(); queryFilter.ObjectIDs = selection.GetObjectIDs(); if (queryFilter.ObjectIDs.Count() == 0) { return; } uint count = 0; using (var cursor = featureClass.Search(queryFilter)) { while (cursor.MoveNext()) { count++; } } status.Progressor.Max = count; uint scount = 0; using (var cursor = featureClass.Search(queryFilter)) { while (cursor.MoveNext()) { scount++; status.Progressor.Value += 1; status.Progressor.Message = "Обработка маршрутов " + scount.ToString() + " из " + count.ToString(); var feature = cursor.Current as Feature; if (feature == null) { continue; } var g = feature.GetShape(); using (var cursor2 = featureClass2.Search()) { while (cursor2.MoveNext()) { if (status.Progressor.CancellationToken.IsCancellationRequested) { return; } var feature2 = cursor2.Current as Feature; if (feature2 == null) { continue; } var g2 = feature2.GetShape(); if (addedObjectIds.Exists((i => i == feature2.GetObjectID()))) { continue; } if (!GeometryEngine.Instance.Intersects(g, g2)) { continue; } addedObjectIds.Add(feature2.GetObjectID()); editOperation.Delete(routesLayer, feature.GetObjectID()); createFeature(feature2); //break; } } } } status.Progressor.Message = "Сохранение..."; if (status.Progressor.CancellationToken.IsCancellationRequested) { return; } editOperation.Execute(); status.Progressor.Message = "Готово"; }