Hi, I need to compare two features in the same feature class. I'd like to test to see if they intersect. Specifically, I have a feature set composed of lines, and I'd like to know if any given two are intersecting. What is a quick and easy way to do this?
A picture would help...
Intersecting the layer with itself might be a possibility with a lot of caveat's depending on the above.
I have had success with offsetting a copy of a featureclass by a small finite amount, then intersecting that with the original.
The direction and offset is important, if done right, segments that cross/intersect will remain overlapped after the translation, the rest won't intersect.
Right, I knew my original question was vague.
Basically, what I am trying to do is determine whether or not two lines in any given polyline are touching/meeting at the ends: for instance, in a four-sided rectangle (say a tax lot in a cadastral map), if the lines meet at a point or if they do not (such as if they were on opposite sides of the rectangle).
I'm not sure if intersect is the right relationship, or if there is another relationship description that is more appropriate.
Whenever I intersect (arcpy.Intersect_analysis()) the feature class with itself, I always get all of the lines, when what I am looking for is a point output that represents the specific location of the intersection of those two lines, if they do intersect; or nothing, if they do not.
I've had good luck using cursors in place of other geospatial processing functions, and wonder if they would be appropriate here as well, I just don't quite know how to properly declare the objects in advance and then step through the featureclasses with the cursor to test the spatial relationships against the other features in the same class.
Any help or code snippets would be helpful for me to learn, as I am just starting to get a grasp of the different objects/classes and their methods.
For instance, I am trying to test whether any two of the four lines in one feature class intersect at a point. In the image below, A & B do meet at a point, whereas A & C do not, and I would like to figure out how to test that relationship and determine the point, if possible.
If you convert the polylines to segments
Split Line At Vertices—Data Management toolbox | ArcGIS Desktop
and segment vertices to points
Feature Vertices To Points—Data Management toolbox | ArcGIS Desktop
Advanced license required.
Once you have your points and segments, you can derive the point coordinates and determine which are shared and what shares them.
This can of course be done within the arcpy PointGeometry, Polyline, and Array classes
Geometry—ArcPy classes | ArcGIS Desktop
Array—ArcPy classes | ArcGIS Desktop
So in your simple example above, you can identify the top-most point, It will belong to 2 and only 2 segments
Alternately, you can use the intersect method of the polyline class and perform and intersection to see if it returns an intersection on the segment.
I will work up an alternate example if you want to work with python
From what you describe, why not just use the Intersect—Help | ArcGIS Desktop tool? A feature class can be intersected with itself (just put a single feature class in list of inputs).
You do, but for ever line crossing you end up with 4 identical multipoints.
4 identical point? I only get 2. Regardless, maybe it would be easier to clean up duplicate multipoints than doing the intersection testing in ArcPy or NumPy.
I didn't find any consistency, that is why I went my other route.
My initial featureclass was composed of lines--so even if I selected one and intersected it with itself, I get three resultant lines: say A was the initial selection, lines B and D would seemingly be the resultant for a self-intersect.
I've adopted Dan's suggestion to further break down the lines into points via the Feature Vertices to Points and then looping through the points to test intersections, which seems to provide the results I want (a point intersection between two lines, where I can then do logical operators to determine if the two lines I want to test indeed have a point intersection).
I was hoping to avoid creating extra featureclass for which to test geometries against, but I don't know of a way to do that. I wish there was a way you could loop through a featureclass with a cursor and test each feature geometry against other features in that same feature class.