Check for Features to touch boundary

768
6
12-04-2012 12:55 AM
thomsh
by
New Contributor
Hello

Im thinking about a problem to solve for a while now, but cant find a good approach...

Here is my problem:

i have a feature class with lots of line features. The line features equal segements and a segment touches only one other segment.

Now i need to sort them.
From a starting segement, i want to look up the one that touches the boundary to the next segment (and write a new attribute to this segment, eq iterating numbers). From this second segement, i want to look for the third one, and so on.

Does anyone has a good hint how to achieve that?
some pseudo code would be deeply appreciates.

greetings tom
Tags (2)
0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Thomas,

You could start with something like this:

fc = "lines"

rows = arcpy.SearchCursor(fc)
for row in rows:
    geom = row.Shape
    rows2 = arcpy.UpdateCursor(fc)
    for row2 in rows2:
        if row2.shape.touches(geom):
            print str(row.OBJECTID) + " touches " + str(row2.OBJECTID)
            row2.ID = row.OBJECTID
            rows2.updateRow(row2)

del row, rows, row2, rows2


I have not thoroughly tested the code, but this could get you started.
0 Kudos
thomsh
by
New Contributor
Thanks a lot!
this is what i needed!


only the
 if geom.touches(row2.shape) 

doesnt work, eventhough the lines definitly touch eacher other (other methods like equals() and within() works...)

any idea for a workaround?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Would you be able to upload a sample set of your data?
0 Kudos
thomsh
by
New Contributor
Thanks for ur time!!

For now, i have to go over an "opposite of a shortcut" of creating a single shapefile, copy it and then compare it with the data i want to order (im sorry for the strange variable names and the brute force approach in general, but somehow i cant think of a better way)

Tips and Help would be deeply appreciated!

[PHP]

str_nameOut = "DeleteMeuu"
str_file = "OutFahrbahn.shp"
str_geoOrderField = "ordergeo"

def geoSortInput(file, startId):
    i = 2
    for i in range(2, 8):
        #make a shapefile with the segment to compare
        arcpy.MakeFeatureLayer_management(file, str_nameOut)
        arcpy.SelectLayerByAttribute_management(str_nameOut, "NEW_SELECTION", str_geoOrderField+ "=" + str(i))
        arcpy.CopyFeatures_management(str_nameOut, str_nameOut +"_.shp")
      
        rows = arcpy.SearchCursor(str_nameOut + "_.shp")
        for row in rows:
            geom = row.Shape
            rows2 = arcpy.UpdateCursor(file)
            for row2 in rows2:
                if row2.shape.touches(geom) and str(row2.getValue(str_geoOrderField)) is str(0):
                    i+=1
                    print "______________________yes!! "  + str(row2.FID) + "   touches "
                    row2.setValue(str_geoOrderField, i)
                    rows2.updateRow(row2)
            del row2, rows2     
        del row, rows
       
# XX = start FID
geoSortInput(str_file, XX)


[/PHP]

here is a datasample:
https://www.dropbox.com/s/opz7zw9988k2sag/outFahrbahn.zip

note that the method needs the first tow segments to be ordered already....

cheers
0 Kudos
JakeSkinner
Esri Esteemed Contributor
What version of ArcGIS are you running?  With the original code I sent and you test data, it reported each segment touched another segment successfully.  I am currently using ArcGIS 10.1 SP1.
0 Kudos
thomsh
by
New Contributor
Im using ArcGis 10 ArcInfo (dont know what sp1 stands for)

strange, it doesnt work with me (only other methods like equals()), and my "workaround" seems terribly slow....

in this case it must be a problem of versions....

thanks anyway, ur approach helped me a lot!
0 Kudos