Calculating Odd and Even side of road using PyQGIS and GRASS

المشرف العام

Administrator
طاقم الإدارة
I'm trying to programmatically and automatically assign odd and even sides of a road to number homes using QGIS and GRASS. I noticed this other post, which gives a solution using PostGIS and I have adapted ideas to come up with my own. For some reason, however, not all homes are successfully assigned.

My procedure: - Use GRASS v.distance I find the closest point on my road layer to the homes layer - Explode Lines QGIS processing tool to get line segments. Calculate the bearing of each segment. - Use points to paths to connect the homes layer to its coinciding point on the road layer. Calculate the azimuth of these paths - My python code to assign the paths to odd or even side follows a logic that assumes the path is perpendicular to the line segment (which is the case, except for if the path happens to fall on a vertex/end of line segment)

for feat in roadsLayer.getFeatures(): roadsAzimuth = feat.attributes()[azimuthRoadsIDX] for feature in pathsLayer.getFeatures(): pathsAzimuth = feature.attributes()[azimuthPathsIDX] if (roadsAzimuth - pathsAzimiuth == 90) or (roadsAzimuth - pathsAzimth == -270): evenList.append(feature.id()) if (roadsAzimuth - pathsAzimiuth == -90) or (roadsAzimuth - pathsAzimth == 270): oddList.append(feature.id()) I have more code to update a field for the path Layer to assign odd or even depending on the oddList and evenList, but I don't think this is part of the issue.

I have checked by manually subtracting azimuth of paths and road segments, and even values that satisfy the conditions aren't caught using my code.

Possible answers my include improvements on my method or new suggestions to attain my goal.



أكثر...
 
أعلى