Tuesday, 19 June 2018

arcgis desktop - Selecting points on one side of the road


I am a newby in python scripting in GIS. I have 2 shapefile: first one with roads and second one with points that contains address number and street name.


enter image description here


I want to select these points from right or left side of the street but in the correct order according to the street start and end.


enter image description here


Firstly, I want to select the points from the red polygon and check them (checking is another task and I know how to do it but selecting this points in the right order..)



Secondly, the same. I want to select the points from the blue polygon an check them too.


NB: Points is a layer, roads is another layer. also buffer of the roads is another layer.


I think that would be a good idea to parse the buffer and select by location the points that is in the buffer, but i don't know how.



Answer



EDIT: I've revamped this answer after realizing that Linear Referencing supports determining the side along a line.


The best approach to this problem is to use the Linear Referencing toolbox in ArcGIS:



A linear reference system stores data using a relative position along existing line features. That is, location is given in terms of a known linear feature and a position, or measure, along it. For example, route I-10, mile 23.2, uniquely identifies a position in geographic space, and can be used instead of an x,y coordinate.


Linear referencing point to line




Here's how you would do it, assuming we're using the streets and lines below:


Example points and lines




  • Run the Create Routes (Linear Referencing) tool with your streets as your in_line_features. Pick a unique ID field for the route_id_field parameter. You can leave all other parameters as their defaults.




  • Run the Locate Features Along Routes (Linear Referencing) tool with your points as the in_features, the routes we created above as the in_routes, and the street ID field as your route_id_field. You should change your radius_or_tolerance such that there's enough distance from your streets to capture all of your points. Lastly, uncheck the m_direction_offsetting parameter; this will make it such that the left/right designation is based on the digitization direction of your streets rather than the more arbitrary direction of your routes.





  • In your output table (shown below), you will have one row for each point. The value in the MEAS field represents the distance along the street that the point is located. The value in the Distance field represents the distance from the point to the snapped nearest location in your street, where the sign of the distance indicate the side of the street. So negative values indicate points to the left of the street and positive values indicate points to the right of the street.




Attribute table


To iterate through your left-side points, sort the table by RID and MEAS and skip positive values; do the same but reverse the sorting of MEAS and skip negative values to iterate through your ride-side points in reverse order. It's probably easiest to sort in Python:


points = []
cursor = arcpy.da.SearchCursor(eventTable, ["RID","MEAS","Distance","OBJECTID"])
for row in cursor:
if row[2] < 0: #negative value = digitized left
points.append((row[0],"L",row[1]))

else: #positive value = digitized right
points.append((row[0],"R",row[1]*-1.0)) #negate MEAS to reverse direction
points.sort() #will break ties when sorting using 2nd or 3rd element in tuple
print [point[3] for point in points]

This results in our points sorted by street ID, then left side from start to end, then right side from end to start:


[9, 11, 12, 10, 8, 1, 4, 6, 5, 3, 2, 7]

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