I have the following polygons shapefile consisting of polygons of the five boroughs of New York City from "NYC Open Data", linked here: https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm
I want to take this shapefile and rasterize it to a
.tif file using
GDAL in python.
I would like to use a GDAL command line command to accomplish this, but I would like to carry this out in Jupyter Notebook using python, rather than through the OSGeo4W Shell.
I am calling this input shapefile
This is what I am trying to use after navigating to the folder
boroughs.shp is located in:
from osgeo import gdal from osgeo import ogr import numpy as np import matplotlib.pyplot as plt import os gdal.UseExceptions() os.system([gdal_rasterize -b1 -burn 1 -a_nodata 0 -ot Byte -tr 25 25 -l boroughs boroughs.shp boroughs.tif])
And this returns the following error:
File "<ipython-input-7-921412e61b57>", line 9 os.system([gdal_rasterize -b1 -burn 1 -a_nodata 0 -ot Byte -tr 25 25 -l boroughs boroughs.shp boroughs.tif]) ^ SyntaxError: invalid syntax
Is there a simple fix to my syntax so that the burning option is correct, or is this approach to using a GDAL command using python in Jupyter Notebook not the correct approach at all? My goal is to simply output a raster file of the NYC borough polygons with 1 burned into where the polygons are, and 0 outside of the polygons, with the same extent as the input shapefile.