I'm trying to generate a graticule with user-defined range of latitude, longitude, and interval; however, my code only displays one line of latitude and one line of longitude when loading it in QGIS. How do I create a grid of lines of latitude and longitude?
multiline = ogr.Geometry(ogr.wkbMultiLineString):
for lon in range(min_lon, max_lon, interval):
line1 = ogr.Geometry(ogr.wkbLineString)
lat = min_long + interval
line1.AddPoint(min_lon, lat)
line1.AddPoint(max_lon, lat)
multiline.AddGeometry(line1)
for lat in range(min_lat, max_lat, interval):
line2 = ogr.Geometry(ogr.wkbLineString)
lat = min_lat + interval
line2.AddPoint(lon, min_lat)
line2.AddPoint(lon, max_lat)
multiline.AddGeometry(line2)
print(multiline.ExportToWkt())
with open ('multiline.txt', 'w') as f:
f.write(multiline.ExportToWkt())
lat = min_long + interval
. You are getting the same value oflat
every pass of the loop because theinterval
value doesn't change.