Hi at all,
i could extract a point by a lines.
I have write a script for extract the start and end point of line, but i could exctract point by line every 500 meters respect the total lenght of line.
Is there in python some script to do this or some example (way) to see?
Thanks
Regards
Solved! Go to Solution.
Jeff, you've pretty well described the exact process I linked to...
... perpLines = [] ... fc = "line" ... sr = arcpy.Describe(fc).spatialReference ... perpLineSpacing = 1000 ... perpLineLength = 1000 ... with arcpy.da.SearchCursor(fc,"SHAPE@",spatial_reference=sr) as cursor: ... for row in cursor: ... for part in row[0]: # part = a line array ... for i in range(len(part)): ... if i==0: # first vertex ... perpLineCounter = 0 ... else: ... dy = part.Y - part[i-1].Y ... dx = part.X - part[i-1].X ... segmentAngle = math.degrees(math.atan2(dy,dx)) ... segmentLength = math.sqrt(math.pow(dy,2)+math.pow(dx,2)) ... linesOnSegment = int(segmentLength/perpLineSpacing) ... for line in range(linesOnSegment+1): ... point = row[0].positionAlongLine(perpLineCounter * perpLineSpacing) ... left = arcpy.Point(point.centroid.X - (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y - (math.sin(math.radians(segmentAngle-90))*perpLineLength)) ... right = arcpy.Point(point.centroid.X + (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y + (math.sin(math.radians(segmentAngle-90))*perpLineLength)) ... perpLines.append(arcpy.Polyline(arcpy.Array([left,right]),sr)) ... perpLineCounter += 1 ... arcpy.CopyFeatures_management(perpLines ,r'in_memory\lines')
You may be interested in Designing a linear referencing system in your geodatabase—Help | ArcGIS for Desktop
See this thread for an example. You can ignore the part about constructing perpendicular lines and simply place points.
I would take a look at a useful function available to you directly from a geometry object.
The function is called positionAlongLine:
To get to that function you will first need to get access to the polyline geometry.
That can be done using some of the examples here:
Once you have the access to Polyline geometry you will be able to use the positionAlongLine function.
The value needed will depend on the spatial reference of the geometry, more to the point the linear unit.
So if the unit is meters the value pass to the function will be in meters.
You could look at the python range function to give you a list of the values to pass in:
2. Built-in Functions — Python 2.7.11 documentation
The function will return a point geometry, so you can pass that geometry to the next step in your process.
Jeff, you've pretty well described the exact process I linked to...
... perpLines = [] ... fc = "line" ... sr = arcpy.Describe(fc).spatialReference ... perpLineSpacing = 1000 ... perpLineLength = 1000 ... with arcpy.da.SearchCursor(fc,"SHAPE@",spatial_reference=sr) as cursor: ... for row in cursor: ... for part in row[0]: # part = a line array ... for i in range(len(part)): ... if i==0: # first vertex ... perpLineCounter = 0 ... else: ... dy = part.Y - part[i-1].Y ... dx = part.X - part[i-1].X ... segmentAngle = math.degrees(math.atan2(dy,dx)) ... segmentLength = math.sqrt(math.pow(dy,2)+math.pow(dx,2)) ... linesOnSegment = int(segmentLength/perpLineSpacing) ... for line in range(linesOnSegment+1): ... point = row[0].positionAlongLine(perpLineCounter * perpLineSpacing) ... left = arcpy.Point(point.centroid.X - (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y - (math.sin(math.radians(segmentAngle-90))*perpLineLength)) ... right = arcpy.Point(point.centroid.X + (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y + (math.sin(math.radians(segmentAngle-90))*perpLineLength)) ... perpLines.append(arcpy.Polyline(arcpy.Array([left,right]),sr)) ... perpLineCounter += 1 ... arcpy.CopyFeatures_management(perpLines ,r'in_memory\lines')
I love the output from that script, Nice work on that one!!
Hi Darren and Jeff,
thanks for your help.
I will follow this way and script published by Darren.
Thanks guys
Regards