I'm trying to use positionAlongLine() to create equally spaced points down a polyline as part of a loop. I also need to calculate the distance at the same time.
However, on curves there is a mismatch between what the distance SHOULD BE and what the distance IS when the points are measured using the measure tool in arcmap.
See example image - 18 points on a 660.979m curved line should all be 36.72m apart but instead vary from 35 to 40m each (but the calculated distance in the script is correct as 36.72m).
I'm not sure why this is not working for curves - does the positionAlongLine() take the curve into account to get the correct position? If not, is there a way of adapting it?
def fillInPoints(prevID):
prevStreetLen = streetLengths[prevID] # How long was the street before (before we add our point)? # 18/04/18 - REMOVED THE (*1000)
streetVertexCount = len(xyDict[prevID]) - 1 # How many vertices on street according to the geometry?
distBetween = prevStreetLen /streetVertexCount # Average distance between vertices
if distBetween > 100: # 100 is our max distance, fill in between if greater
streetVertexCount += floor(distBetween / 100) # add in the min number to bring distbetween down below 100 (e.g. 300m = 3)
thisDirection = streetSeq_dict[streetSeq-1]['direction'] # Direction (FT/TF) of PREVIOUS street
# Here we are filling in the gaps where the distance between the start and end of the segment are too long
if streetVertexCount > 1: # More than just the start and end (NB we've already added vertices if streets were >100m)
# Loop through each vertex
for n in range(1,int(streetVertexCount)):
position = n * (1 / float(streetVertexCount)) # Get the position (e.g. 0.5 if only 1 point added)
streetShape = streetShapeDict[prevID]
thisDistance = 0
# Subtracting from the current distance as we're looking back to the street before
if thisDirection == "FT":
thisPoint = streetShape.positionAlongLine(position,True).firstPoint
thisDistance = distanceFromStart - ((1 - position) * prevStreetLen)
else:
thisPoint = streetShape.positionAlongLine((1 - position),True).firstPoint
thisDistance = distanceFromStart - ((1 - position) * prevStreetLen)
outputList.append([thisPoint.X,thisPoint.Y,thisDistance])