I want to create a numpy array of size 2160 * 4320 with each grid cell containing the size of a 5' grid cell on earth.
Is there a python library or function to do this?
I am using GDAL and rasterio.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI want to create a numpy array of size 2160 * 4320 with each grid cell containing the size of a 5' grid cell on earth.
Is there a python library or function to do this?
I am using GDAL and rasterio.
Numpy doesn't support any spatial info. You can use pyshp library for the same. https://github.com/GeospatialPython/pyshp
import shapefile as shp
import math
minx,maxx,miny,maxy = xxxxx, xxxxx, xxxxx, xxxxx (specify the extents)
dx = xx (size of grid)
dy = xx (size of grid)
nx = int(math.ceil(abs(maxx - minx)/dx))
ny = int(math.ceil(abs(maxy - miny)/dy))
w = shp.Writer(shp.POLYGON)
w.autoBalance = 1
w.field("ID")
id=0
for i in range(ny):
for j in range(nx):
id+=1
vertices = []
parts = []
vertices.append([min(minx+dx*j,maxx),max(maxy-dy*i,miny)])
vertices.append([min(minx+dx*(j+1),maxx),max(maxy-dy*i,miny)])
vertices.append([min(minx+dx*(j+1),maxx),max(maxy- dy*(i+1),miny)])
vertices.append([min(minx+dx*j,maxx),max(maxy-dy*(i+1),miny)])
parts.append(vertices)
w.poly(parts)
w.record(id)
w.save('polygon_grid')