KS22 Posted May 8, 2014 Report Share Posted May 8, 2014 I have two shapefiles. First of them, there is about 115 000 points (clients and their field size) All together there is about 16 226 different clients. In the other shapefile I have calculated the median point for all the clients. Now, I want to calculate the distance from each client field to its corresponding median point. Doing it one by one takes a lot of time.I tried to use Generate Near Table tool but it takes account other clients mean centers too, because some are near to each other. I need to classify source points by client number, but no distance tool have case field option to do this.How this process should look like in Model Builder? I know that i must use iterators but witch ones? I tried to do different things but I still get wrong results. Can someone help me? Quote Link to comment Share on other sites More sharing options...
souvik.gis Posted May 11, 2014 Report Share Posted May 11, 2014 Try this python script: ------ import arcpy import math # Change these first four variables to suit your data # 1. points is the raw point file # 2. medianPoints is a point file of median points using ArcMap's 'Median Center' tool # 3. sharedNameField is the name of the field that both points and medianPoints share # 4. distanceFieldName is the name of the field that will be created to store distances points = r'C:\give your file path\your data.shp' medianPoints = r'C:\give output file path\points_median_center.shp' sharedNameField = 'name of the field' distanceFieldName = "pointDist" # add field to point dataset that will store distances corresponding to median point arcpy.AddField_management(points, distanceFieldName, "DOUBLE") # loop through median points, get x,y coords and field value medianPointCursor = arcpy.SearchCursor(medianPoints) for medianPoint in medianPointCursor: medPointXY = medianPoint.getValue('Shape').getPart() x1,y1 = medPointXY.X, medPointXY.Y fieldValue = medianPoint.getValue(sharedNameField) # query the point file for only points that match the sharedNameField value query = "{0} = '{1}'".format(sharedNameField, fieldValue) pointCursor = arcpy.UpdateCursor(points, query) for point in pointCursor: pointXY = point.getValue('Shape').getPart() x2,y2 = pointXY.X, pointXY.Y distanceToMedianPt = math.hypot(x2 - x1, y2 - y1) point.setValue(distanceFieldName, distanceToMedianPt) pointCursor.updateRow(point) del point, pointCursor del medianPoint, medianPointCursor 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.