Saturday 29 August 2015

arcgis desktop - How to select all dangling polyline features with Arcview license?


I have a city roads shp file and would like to identify (select) all the locations where a roads ends (in other words dangles). I am working in ArcView 10.


I do not want to use a topological tool such as ETgeowizards because it can detect and dangles but fixes them automatically with no further options to identify exeptions or even visualize where fixes occured (in my case I will have many exeptions). ArcEditor provides a good interactive environment for identifying which errors are expections - but I am trying to see if I can do this with just ArcView.


The approach I have been experimenting with is to try to identify/select segments in the network that only touch one other segment. I thought the dissolve tool might be an option, but it doesnt look like it has the settings I want in the "unsplit lines" option...




Answer



This can be done using a MapTopology.



Although you cannot create or edit geodatabase topologies with ArcView (only ArcEditor and ArcInfo), you can create and edit map topologies in ArcView.



Create a new Add-in button and copy the code from below.


Add the roads layer to the map and start editing. Open the topology toolbar and create a map topology. Click the button that runs the Test code.


enter image description here


using System;
using System.Collections.Generic;

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.EditorExt;

namespace KalkulatorAddin
{
public class TestButton : ESRI.ArcGIS.Desktop.AddIns.Button
{

public TestButton()
{
}

protected override void OnClick()
{
try
{
Test();
}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

protected override void OnUpdate()
{
}
public void Test()

{
var fSel = ArcMap.Document.FocusMap.get_Layer(0) as IFeatureSelection;
fSel.Clear();
var dangleOids = GetDangleOids();
if (dangleOids.Count > 0)
{
var oidarray = dangleOids.ToArray();
fSel.SelectionSet.AddList(dangleOids.Count, ref oidarray[0]);
}
((IActiveView)ArcMap.Document.FocusMap).Refresh();

}

private List GetDangleOids()
{
UID topoUiD = new UID();
topoUiD.Value = "esriEditorExt.TopologyExtension";
var topoExt = ArcMap.Application.FindExtensionByCLSID(topoUiD) as ITopologyExtension;
var mapTopology = topoExt.CurrentTopology as IMapTopology;
if (mapTopology == null)
throw new Exception("map topology not found");


//assume just one class in the map topology
var extent = ((IGeoDataset)mapTopology.get_Class(0)).Extent;
mapTopology.Cache.Build(extent, false);

var dangleOids = new List();
var nodes = mapTopology.Cache.Nodes;
nodes.Reset();
ITopologyNode node;
while ((node = nodes.Next()) != null)

{
// sometimes degree is referred to as valence
if (node.Degree == 1)
{
var parents = node.Parents;
parents.Reset();
int oid = parents.Next().m_FID;
if (!dangleOids.Contains(oid))
dangleOids.Add(oid);
}

}
return dangleOids;
}
}
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...