concept dataset in category geoprocessing

appears as: A dataset, dataset, datasets, The dataset, datasets, dataset
Geoprocessing with Python

This is an excerpt from Manning's book Geoprocessing with Python.

You’ll learn how to work with the two main types of spatial data, vector and raster. Vector data is made up of points, lines, and polygons, while raster data is a two- or three-dimensional array of data values such as the pixels in a photograph. A dataset containing country boundaries is an example of vector data. In this case, each country is generally represented as a polygon. Datasets that use lines to represent roads or rivers, or points to show the location of weather stations, are other examples. Early primitive maps, such as those drawn on cave walls, only showed the features themselves. Later maps contained labels for features of interest such as cities or seaports; for example, the Portolan map of northwest Africa shown in figure 1.1.

Figure 1.1. A Portolan map of the northwest coast of Africa, circa 1590

Using digital data, you have the advantage of attaching multiple attribute values to each feature, whether you plan to display the information on a map or not. For each road, you can store information such as its name, speed limit, number of lanes, or anything else you can think of. Figure 1.2 shows an example of data you might store with each country in a dataset.

Figure 1.2. You can store attributes such as name and population for each geographic feature in a dataset.

If you have a geographic dataset that’s made of continuous data such as elevation or temperature, it’s probably a raster dataset. Spectral data such as aerial photographs and satellite imagery are also stored this way. These types of datasets don’t assume strict boundaries exist between objects in the way that vector datasets do. Think of a digital photograph and how each pixel can be a slightly different color than the pixels next to it. The fact that pixel values can vary continuously like this makes for a much better-looking photo than if there were only a few colors to choose from. This trait also makes rasters appropriate for continuously varying data such as elevation.

You still need to add the green and red Landsat bands to your dataset, so then you open the second band’s GeoTIFF. Notice that you don’t get the band object from the dataset, though, because you’re going to read pixel data directly from the dataset itself this time. Because the second Landsat band is the green one, you then get a handle to the second (green) band in your stacked dataset, and copy the data from the Landsat file to your stacked dataset:

in_ds = gdal.Open(band2_fn)
out_band = out_ds.GetRasterBand(2)
out_band.WriteArray(in_ds.ReadAsArray())

When you call ReadAsArray on a dataset, you get a three-dimensional array if the dataset you’re reading from has multiple bands. Because the Landsat file only has one band, ReadAsArray on the dataset returns the same two-dimensional array that you’d get from the band object. Instead of saving the data into an intermediate variable, this time you immediately send it to the output band. Then you do the same thing for the red pixel values, but compress it into even less code. The result is the same, however:

Several types of datasets can contain other datasets, which each in turn contain bands (figure 9.15). One example of this is the MODIS imagery distributed by the United States Geological Service, which comes as a hierarchical data format (HDF) file. If your dataset contains subdatasets, you can get a list of them with the GetSubDatasets function and then use that information to open the one you want.

Figure 9.15. Several types of datasets include subdatasets. Each of these subdatasets is structured like a normal dataset and contains its own bands and georeferencing information.

The ReadAsArray function has several optional parameters, although they differ depending on whether you’re using a dataset or a band.