Deleting the same Map Points

529
3
11-22-2022 05:28 AM
DavidMrázek
Occasional Contributor II

Hello,
how to remove duplicate MapPoints?Is there an easy way? or should I upload the coordinates of each MapPoint, then save and delete the same?

 

Thank you in advance
David

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You have to describe your workflow in a bit more detail.  For example, where are your MapPoints?  In a graphic layer, in a feature layer, in memory?  You are talking about 'uploading coordinates', I am not clear what that means.  Do you have to check the 'dataset' to where you 'upload' your MapPoints for duplicates before you upload?   If you have a feature class with MapPoints you suspect having duplicates you can use the 'Delete Identical (Data Management)' geoprocessing tool: Delete Identical (Data Management)—ArcGIS Pro | Documentation

0 Kudos
DavidMrázek
Occasional Contributor II

I had a Polyline layer which I converted to a PointCollection from which I created a Point layer.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I created sample code that copies all vertices from a line layer (TestLines) into a point layer (PointsNoDuplicates) and then deletes all duplicates (with the same shape) using the "management.DeleteIdentical" GP tool.  I used an addin with a button to test this code and a map  that contained the required layers.

protected override async void OnClick()
{
  try
  {
    var lineLayerName = "TestLines";
    var noDupPointLayerName = "PointsNoDuplicates";

    FeatureLayer polyLine = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(layer => layer.Name.Equals(lineLayerName)) as FeatureLayer;
    FeatureLayer pointsNoDuplicates = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(layer => layer.Name.Equals(noDupPointLayerName)) as FeatureLayer;

    var ok = await QueuedTask.Run<bool>(() =>
    {
      var createFeatures = new EditOperation();
      createFeatures.Name = "Add Points with duplicates";
      //Create a feature for each point        
      using (var fc = polyLine.Search())
      {
        while (fc.MoveNext())
        {
          using (var feature = fc.Current as Feature)
          {
            var multiPart = feature.GetShape() as Multipart;
            foreach (var point in multiPart.Points)
            {
              createFeatures.Create(pointsNoDuplicates, point);
            }
          }
        }
      }
      //Execute to execute the operation
      //Must be called within QueuedTask.Run
      var result = createFeatures.Execute();
      if (!result)
      {
        MessageBox.Show($@"Error creating points with duplicated: {createFeatures.ErrorMessage}");
      }
      return result;
    });
    if (!ok) return;

    await Project.Current.SaveEditsAsync();
    // Clear selection
    await QueuedTask.Run (() => pointsNoDuplicates.ClearSelection());
    // arcpy.management.DeleteIdentical(noDupPointLayerName, "Shape", "0.1 Meters", 0.1)

    var paramsArray = Geoprocessing.MakeValueArray(noDupPointLayerName,
        "Shape", "0.1 Meters", 0.1);
    var delDupsDlg = new ProgressDialog("Delete Duplicates", "Cancel", 100, false);
    var progsrc=new CancelableProgressorSource(delDupsDlg);

    await Geoprocessing.ExecuteToolAsync("management.DeleteIdentical", paramsArray, null, progsrc.Progressor);
  }
  catch (Exception ex)
  {
    MessageBox.Show($@"{ex.Message}");
  }
}

 

Note that when i click my button repeatedly it will add the same points again (hence creating duplicates) which are then removed by the GP tool.