Select to view content in your preferred language

How to add Topology layer to map

1193
6
08-01-2022 09:34 AM
TimothySmith6
Occasional Contributor

How would I use the SDK to add a Topology to my map as a layer?

This post from 2019 says its not possible.  I see the updated topo API stuff, but can't figure out how to automate adding one to my active map.

I've tried this but get the message:   "MyTopoName cannot be added as a layer"

Thanks,

tim

    await QueuedTask.Run(() =>
                {
                    Map myMap = MapView.Active.Map;

                    Geodatabase myGDB = null;
                    var connFile = new DatabaseConnectionFile(new Uri(sdePath, UriKind.Absolute));
                    myGDB = new Geodatabase(connFile);

                    Topology myTopo = myGDB.OpenDataset<Topology>("MyTopoName");        
                   
                    Layer myLayer = LayerFactory.Instance.CreateLayer(myTopo.GetPath(), myMap);
                });

 

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

Maybe i don't understand your workflow, but Topologies are applied to a feature dataset and not to a map.  In geodatabases, a topology is an arrangement that defines how point, line, and polygon features share coincident geometry. Topologies provide a mechanism to perform integrity checks on data and help validate and maintain better feature representations in a geodatabase.  To do this you have to use the GP Tool: Import Topology.  The tool requires two parameters: the feature dataset for which you want to create a topology and a topology definition file (XML - exported from a toplogy).  The tool creates a topology in the specified feature dataset, however, this only works if the feature dataset contains the feature classes listed in the topology_definition_file.

Once you have a topology in your geodatabase you can use the topology functionality outlined in this ProConcept document:  ProConcepts Topology · Esri/arcgis-pro-sdk Wiki (github.com)  

You can find code examples in these ProSnippets: ProSnippets Topology · Esri/arcgis-pro-sdk Wiki (github.com)

0 Kudos
TimothySmith6
Occasional Contributor

Thanks for the reply.  We have the topology built out in a feature data set with the relevant feature classes and rules. I'd like to automate adding the topology as a layer to the map to visibly see dirty areas, errors and exceptions.   ArcObjects had the ITopologyLayer interface, I'm just struggling to find something similar in the ProSDK. 

It would look something like this:

TimothySmith6_0-1659375237372.png

 

Wolf
by Esri Regular Contributor
Esri Regular Contributor

You are correct and it looks like you can add Topology items via the Pro UI | Add Data from Path:

Wolf_0-1659388047872.png

and here is the result (using the sample dataset from the community samples):

Wolf_1-1659388105639.png

However, when i try to perform the same operation through the API, the LayerFactory fails as you described:

await QueuedTask.Run(() =>
{
  var path = @"C:\Data\Topology\GrandTeton.gdb\BackCountry\Backcountry_Topology";
  Uri uri = new Uri(path);
  // fails:
  LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map);
});

I tried different methods and also tested this under 2.9 to no avail.  The only workaround i was able to find was adding the whole feature dataset instead of the Topology.  This works:

await QueuedTask.Run(() =>
{
  var path = @"C:\Data\Topology\GrandTeton.gdb\BackCountry";
  var uri = new Uri(path);
  LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map);
});

Wolf_2-1659389630777.png

but needless to say, it will add all layers of that feature dataset to the map.  Consequently, all unwanted (or duplicated) layers have to be removed from the map's table of content.

Thanks for finding this, i will report it as a bug.

0 Kudos
TimothySmith6
Occasional Contributor

Thanks for the follow up and confirmation Wolf.  We'll keep an eye out in later versions for a fix.

 

Thanks again,

tim

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Tim,

 The upcoming release 3.1 is capable of adding 'Topology layers' to the TOC.  I used this code snippet to test this:

var path = @"C:\Data\Topology\GrandTeton.gdb\BackCountry";
Uri uri = new Uri(path);
await QueuedTask.Run(() =>
{
  var item = ItemFactory.Instance.Create(uri.AbsolutePath);
  if (!LayerFactory.Instance.CanCreateLayerFrom(item)) return;
  var topoLyrParams = new TopologyLayerCreationParams(item);
  LayerFactory.Instance.CreateLayer<TopologyLayer>(topoLyrParams, MapView.Active.Map);
});

Both TopologyLayer and TopologyLayerCreationParams were added in 3.1 to support this functionality.

 

 

0 Kudos
TimothySmith6
Occasional Contributor

Thanks so much for the follow up Wolf.    Looking foward to 3.1!

0 Kudos