Skip to content

Instantly share code, notes, and snippets.

@bixb0012
Last active July 31, 2019 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bixb0012/11b7156568d488e48a820fa3f97928b3 to your computer and use it in GitHub Desktop.
Save bixb0012/11b7156568d488e48a820fa3f97928b3 to your computer and use it in GitHub Desktop.
ArcPy: Create Latitude and Longitude Lines
#!python
# Reference: 1) https://pro.arcgis.com/en/pro-app/arcpy/classes/spatialreference.htm
# 2) https://pro.arcgis.com/en/pro-app/arcpy/classes/array.htm
# 3) https://pro.arcgis.com/en/pro-app/arcpy/classes/point.htm
# 4) https://pro.arcgis.com/en/pro-app/arcpy/classes/polyline.htm
import arcpy
SR = arcpy.SpatialReference(4326)
interval = 5 # Interval of latitude and longitude lines, multiple of 1 degree
density = 10 # Density of vertices between each degree
# Example 1: Creating densified polylines
long_lines = [
arcpy.Polyline(
arcpy.Array(arcpy.Point(x, -90 + y/float(density))
for y
in range(180*density + 1)),
SR
)
for x in range(-180, 180 + interval, interval)
]
lat_lines = [
arcpy.Polyline(
arcpy.Array(arcpy.Point(-180 + x/float(density), y)
for x
in range(360*density + 1)),
SR
)
for y in range(-90, 90 + interval, interval)
]
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment