Wednesday, 6 November 2019

modelbuilder - Determining features which are Near By Group using ArcGIS Desktop?


I have two polyline layers with corresponding attributes. Each layer has 100,000+ rows. I need to calculate the distance between the corresponding features from each layer.



E.g.


Layer 1:


FID | LineID
1 1234
2 5678
3 9012

Layer 2:


FID | LineID
1 9012

2 1234
3 5678

I need to find the distance between the rows from each layer that match by LineID.


ESRI had a blog about using model builder to create a Near By Group tool - https://blogs.esri.com/esri/arcgis/2010/09/16/nearbygroup/


The tool seems to stall out (probably because of the large number of rows). Does anyone have any other ideas on how I can accomplish this task?



Answer



One of the options is field calculator. Place 1 layer at the top of your table of content and use this on a new numeric field of second layer.


def FindD ( shp, FID ):
mxd = arcpy.mapping.MapDocument("CURRENT")

lr=arcpy.mapping.ListLayers(mxd)[0]
with arcpy.da.SearchCursor(lr, 'Shape@',r'"LINEID"='+str(FID)) as cursor:
for row in cursor: a=row[0]
try: return a.distanceTo(shp)
except: return -1

=========================


FindD ( !Shape!, !LIDONE! )

This is essentially the same what @Andy Bradford suggesting. You'll have to change naming of matching fields. Code assumes matching field is numeric. If not use FID instead of str(FID). Query I used in cursor is valid for shapefiles.



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...