I want to create a shapefile using the GDAL library. And I want this Shapefile, when created, to have a grid of square polygons. And where each polygon cell is 10 degrees by 10 degrees, ultimately I want this grid to cover the entire world. As well, I also want the shapefile to contain a decimal column 'LAND', which should be populated with 0.0 for all rows/cells.
Having confusion here because I've never used GDAL before and just sifting through the documents is confusing me. I think I understand how to create a shapefile something like the following:
from osgeo import ogr from osgeo import osr import gdal # specifying that I want to work with a shapefile DriverName = 'My Shapefile' driver = ogr.GetDriverByName(DriverName) Filename = 'points.shp'
Just a little lost here. Not sure exactly how this would be done through GDAL. I know if I am creating the world, the extent of the world is -180 deg to 180 deg longitude and -90 deg to 90 deg for latitude. And that I should create a nested loop somewhere to loop the outer of longitudes and the inner of latitudes, stepping a value of 10 each time for spatial resolution for the grid.
It's just the whole-set up and the library functionally is confusing not sure what way to go about all this.
The general structure of the code I'd think would be something like: - Import GDAL and other modules - create a spatial reference - Create an empty shapefile - create a layer in the shapefile and assign it the spatial reference - create a set of point geometries as a ring - add those point geometries in an order to a polygon geometry - create a feature and add the polygon Geometry to it - put the feature in the layer
I examine the GDAL library website and found this: link: https://pcjericks.github.io/py-gdalogr-cookbook/
and then more specifically a section that said "Create a New Shapefile and Add Data" link: https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#create-a-new-shapefile-and-add-data
I looked at the following but they did not help so much: link: Creating square grid polygon shapefile with Python?
I am trying to piece all this information together in order to solve my task but it is proving difficult.
Please help how would I create a shapefile being a grid of 10x10degree polygons?