Remove the Discrepancy Between ArcView/ArcGIS and Map 3D When Deleting Features

By Daniel Du

In last post, I introduced how to delete selected features in Map 3D using APIs, some users argue that there is a discrepancy for SHP files when examining the file in ArcGIS, the deleted features in Map 3D still appear in ArcGIS when FDO connection in Map 3D is still open.

To better understand this problem, let’s examine the modification date of files firstly. Following screen-shot is the shp files before deleting in Map 3D:

image

And following is another screen-shot when the features are deleted in Map 3D using the custom command we introduced in last post.

image

You may notice that only the *.dbf file is modified, while *.shp does not.

Is this a bug of Map 3D? First, here are some background regarding SHP files and the FDO SHP provider:

· A  DBF record holds the attributes + a Delete flag. When a geometry is deleted this flag is set. The geometry is still in the SHP file but marked for deletion in DBF. If you are interested in the DBF specification, please refer to this doc.

· The weird aspect of this flag is that while it is part of the ESRI SHP specification it is ignored by applications like ArcGIS or TatukGis Viewer.

In the past development team made a significant deal of effort to address this issue. They ended up by compressing (i.e. effectively deleting the records) the SHP files (.dbx, .shx, .shp) when the last connection is closed. This is because, obviously, it is non-performant to compress the files for every single deleted feature (these files can be extremely large). o it is as designed, shp file is only compressed when the connection is closed.

But for some reason, customer may want to sync the changes between Map 3D and ArcGIS more frequently, is there any a way to compress the shp explicitly? Unfortunately, there is no such APIs in Map 3D, but since it will be compressed when the connection is closed, how about to close the connection programmatically? Yes, that is the solution.

If you examine the BuidMap sample in Map 3D ObjectARX SDK, you will understand that the process of creating a connection to FDO datasource and adding layer to map is actually a process of create feature source and layer definition using resource service. So we of cause can disconnect by deleting these resources.

Here is the code snippet:

 

[CommandMethod("CloseConnection")]

public void CloseConnectionForLayer()

{

RemoveLayer("Layer1");

}

 

public void RemoveLayer(string layerName)

{

Document doc = Application.DocumentManager.MdiActiveDocument;

Editor ed = doc.Editor;

Database db = doc.Database;

 

AcMapMap map = AcMapMap
.GetCurrentMap();

 

// remove the layer

var layers = map.GetLayers();

if (!layers.Contains(layerName))

{

  ed.WriteMessage("\nLayer does not exist: " + layerName);

  return;

}

 

MgLayerBase layer = layers.GetItem(layerName);

layers.Remove(layer);

 

// remove the layer resource

MgResourceIdentifier identifier = layer.LayerDefinition;

MgResourceService resourceService

  = AcMapServiceFactory.GetService(MgServiceType.ResourceService)

  as MgResourceService;

 

if (resourceService.ResourceExists(identifier))

  resourceService.DeleteResource(identifier);

 

// remove the feature source

identifier = new MgResourceIdentifier(layer.FeatureSourceId);

if (resourceService.ResourceExists(identifier))

  resourceService.DeleteResource(identifier);

 

 

}

 

By this way, the SHP layer is removed from map and FDO connection is closed, let’s examine the modification data again, the SHP files (.dbx, .shx, .shp) are modified. The result will be synced with ArcGIS now.

image

If you need to keep working the SHP file in Map 3D, you need to re-create the connection using the way introduced in BuildMap Sample. As you can imagine, this workaround may cause performance issue if you do that very frequent
ly, so please apply it only when necessary.

Hope this helps.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading