Basics of NumPy for rasters
Using NumPy for rasters is very straightforward. Rasters are data organized into regular rows and columns, and may have multiple bands of data. These data behaviors can be precisely recreated using NumPy arrays, which can have any number of rows or columns, as well as multiple dimensions.
Creating an array
Often in GIS you must create rasters for analyses. These arrays may need to be blank, allowing you to accumulate values from inputs to a continuous surface based on location; all one value to create a constant raster; or merged with vector data inputs such as GeoJSON files or shapefiles. All of these are possible with NumPy arrays.
There are many ways to create a NumPy array. Some of these are built-in tools, and some are methods to derive an array from an existing dataset such as a raster, CSV file, or JSON data, as seen in Chapter 8’s exploration of Pandas. Data can also be read from a vector file such as a shapefile or feature...