Saturday, 5 May 2018

arcpy - Draw horizontal lines on points shapefile using ArcGIS



I have one shapefile of 200 points in which I would like to draw one horizontal line of 2Km on each of those points.


Shapefile


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

enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...