Created
March 21, 2017 07:50
-
-
Save AlexArcPy/a20cd7633f5fa08192e7c431807f85d3 to your computer and use it in GitHub Desktop.
Get points along the line feature (arcpy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| def get_points_along_line(input_line_feature, interval, number_of_points): | |
| '''given a single polyline feature shape will return a list of point features | |
| positioned along the line at set intervals''' | |
| out_pnts = [] | |
| intervals_list = [] | |
| if number_of_points: | |
| interval = input_line_feature.length / number_of_points | |
| i = 0 | |
| while i < input_line_feature.length: | |
| intervals_list.append(i) | |
| out_pnts.append(input_line_feature.positionAlongLine(i)) | |
| i += interval | |
| out_pnts.append(input_line_feature.positionAlongLine(input_line_feature.length)) | |
| intervals_list.append(input_line_feature.length) | |
| print intervals_list | |
| return out_pnts | |
| lines_fc = r'C:\GIS\Temp\ArcGISHomeFolder\ScriptData.gdb\roads' | |
| out_points_fc_with_number_of_points = r'C:\GIS\Temp\ArcGISHomeFolder\ScriptData.gdb\points_along_line_number_of_points' | |
| out_points_fc_with_interval_value = r'C:\GIS\Temp\ArcGISHomeFolder\ScriptData.gdb\points_along_line_interval_value' | |
| with arcpy.da.SearchCursor(lines_fc, "SHAPE@", '''OBJECTID = 554''') as feats: | |
| for feat in feats: | |
| out_pnts = get_points_along_line(input_line_feature=feat[0], interval=None, number_of_points=10) | |
| if arcpy.Exists(out_points_fc_with_number_of_points): | |
| arcpy.Delete_management(out_points_fc_with_number_of_points) | |
| arcpy.CopyFeatures_management(out_pnts, out_points_fc_with_number_of_points) | |
| out_pnts = get_points_along_line(input_line_feature=feat[0], interval=200, number_of_points=None) | |
| if arcpy.Exists(out_points_fc_with_interval_value): | |
| arcpy.Delete_management(out_points_fc_with_interval_value) | |
| arcpy.CopyFeatures_management(out_pnts, out_points_fc_with_interval_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment