I have one shapefile of 200 points in which I would like to draw one horizontal line of 2Km on each of those points.
How can I do this?
Answer
With some python code which you can execute in the Python window:
import arcpy, os
shapefile_folder = r'C:\folder'#Change to match your data
point_shapefile = 'points.shp' #Change to match your data
hlines = 'Horizontal_lines.shp'
lenght_of_lines = 1000 #on each side of the point
arcpy.CreateFeatureclass_management(out_path=shapefile_folder, out_name=hlines,
geometry_type='POLYLINE',
spatial_reference=arcpy.Describe(point_shapefile).spatialReference)
icur = arcpy.da.InsertCursor(hlines,'SHAPE@')
with arcpy.da.SearchCursor(os.path.join(shapefile_folder,point_shapefile),['SHAPE@X','SHAPE@Y']) as cursor:
for row in cursor:
poly=arcpy.Polyline(arcpy.Array([arcpy.Point(row[0]-lenght_of_lines,row[1]),arcpy.Point(row[0]+lenght_of_lines,row[1])]))
icur.insertRow([poly])
del icur
No comments:
Post a Comment