Select to view content in your preferred language

Bug in Modifying Feature?

2935
23
Jump to solution
09-23-2019 01:59 PM
SusanFarley
Occasional Contributor

I have two Node layers in my map with the second layer being a copy of the first. I am enabling users to merge similar nodes to help clean up data, but all alterations are done on the copy layer in case the user later decides those nodes shouldn't be merged. So in my code I have:

//MergeRow is the new row and SelectedNodes is the list of rows to be deleted

public async Task<bool> MergeNodes(DataRow MergedRow, List<DataRow> SelectedNodes) {

      var modifyFeature = new EditOperation();

      modifyFeature.Name = "Merged Nodes";

      //Other stuff

      modifyFeature.Delete(MergeNodeLayer, Int64.Parse(SelectedNodes[0][oidNum].ToString()));

      modifyFeature.Execute();

     return true;

}

Even though I pass in the MergeNodeLayer, it deletes the node from both the control layer and the new layer. Is this a bug with delete or am I doing something wrong? The nodes on both layers have the same oids since it is a direct copy so it is deleting the correct one from each layer, but it should only be deleting the one for the layer I passed in.

Thank you,

Susan

Tags (3)
0 Kudos
23 Replies
SusanFarley
Occasional Contributor

I have a little more info:

  1. The copy does not work at all if the file are on a network drive. There are no spaces in the path, but there is a $ in the path ("\UserPublic$\susan\Files")
  2. The copy does not work on geodatbases where there is a space in the name (i.e., "Medium Database.gdb") but does work if I remove the space (i.e., "MediumDatabase.gdb"). When I get the absolute path of the one with the space, it replaces the space with %20.

Any ideas of how to resolve these two issues?

0 Kudos
by Anonymous User
Not applicable

Hi Susan,

Sorry for the delay, I'll take a look at all those cases.

Should be just a matter of C# string wrangling with the different cases.

0 Kudos
by Anonymous User
Not applicable

Susan,

It turns out to be an easy fix by using the localpath property instead of absolutepath and a different way to combine the paths.

Here's the complete code i used for testing:

      QueuedTask.Run(async () =>
      {
        //use the selected layer
        var selLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;

        //get the underlying featureclass for the layer
        var selClass = selLayer.GetFeatureClass();

        //get the datastore for the featureclass
        var selStore = selClass.GetDatastore();

        string fileExtention = "";
        if (selStore is FileSystemDatastore)
        {
          //var fileconpath = selStore.GetConnector() as FileSystemConnectionPath;
          //if (fileconpath.Type == FileSystemDatastoreType.Shapefile)
          //assume its a shapefile since were casting to featurelayer anyway
          fileExtention = ".shp";
        }

        //concat path (datastore and featureclass name)
        var selPath = System.IO.Path.Combine(selStore.GetPath().LocalPath, selClass.GetName());

        //make the value array and pass to the GP tool
        var mva = Geoprocessing.MakeValueArray(selPath + fileExtention, $@"{selPath}2" + fileExtention);
        await Geoprocessing.ExecuteToolAsync("Copy_management", mva);
      });

For the input layer i was using the selected one in the table of contents as i had a few layers for testing.

Tested for: shapefile, shapefile with space, filegdb, filegdb with space both on local and network drives and an enterprise GDB source for kicks. All seems to work and created copies as expected.

SusanFarley
Occasional Contributor

Worked great! Thank you! Not sure if it helps you, but our customer number is below 1000. I can find out the exact number if you need it.

0 Kudos