Inthe previous topics we have taken a closer look at vector data. While vectorfeatures use geometry (points, polylines and polygons) to represent the realworld, raster data takes a different approach. Rasters are made up of a matrixof pixels (also called cells), each containing a value that represents theconditions for the area covered by that cell (see figure_raster). In this topicwe are going to take a closer look at raster data, when it is useful and when itmakes more sense to use vector data.
Using raster data is a solution to these problems. Many people use raster data asa backdrop to be used behind vector layers in order to provide more meaningto the vector information. The human eye is very good at interpreting images andso using an image behind vector layers, results in maps with a lot more meaning.Raster data is not only good for images that depict the real world surface (e.g.satellite images and aerial photographs), they are also good for representing moreabstract ideas. For example, rasters can be used to show rainfall trends over anarea, or to depict the fire risk on a landscape. In these kinds of applications,each cell in the raster represents a different value e.g. risk of fire on a scaleof one to ten.
Raster data can be obtained in a number of ways. Two of the most common ways areaerial photography and satellite imagery. In aerial photography, an aeroplaneflies over an area with a camera mounted underneath it. The photographs are thenimported into a computer and georeferenced. Satellite imagery is created whensatellites orbiting the earth point special digital cameras towards the earthand then take an image of the area on earth they are passing over. Once the imagehas been taken it is sent back to earth using radio signals to special receivingstations such as the one shown in figure_csir_station. The process of capturing raster data froman aeroplane or satellite is called remote sensing.
In other cases, raster data can be computed. For example an insurance company maytake police crime incident reports and create a country wide raster map showinghow high the incidence of crime is likely to be in each area. Meteorologists(people who study weather patterns) might generate a province level raster showingaverage temperature, rainfall and wind direction using data collected from weatherstations (see figure_csir_station). In these cases, they will often use rasteranalysis techniques such as interpolation (which we describe in TopicSpatial Analysis (Interpolation)).
Sometimes raster data are created from vector data because the data owners wantto share the data in an easy to use format. For example, a company with road,rail, cadastral and other vector datasets may choose to generate a raster versionof these datasets so that employees can view these datasets in a web browser.This is normally only useful if the attributes, that users need to be aware of,can be represented on the map with labels or symbology. If the user needs to lookat the attribute table for the data, providing it in raster format could be a badchoice because raster layers do not usually have any attribute data associatedwith them.
Every raster layer in a GIS has pixels (cells) of a fixed size that determine itsspatial resolution. This becomes apparent when you look at an image at a smallscale (see figure_raster_small_scale) and then zoom in to a large scale (seefigure_raster_large_scale).
In raster data that is computed by spatial analysis (such as the rainfall map wementioned earlier), the spatial density of information used to create the rasterwill usually determine the spatial resolution. For example if you want to createa high resolution average rainfall map, you would ideally need many weatherstations in close proximity to each other.
If you take a colour photograph with a digital camera or camera on a cellphone,the camera uses electronic sensors to detect red, green and blue light. When thepicture is displayed on a screen or printed out, the red, green and blue (RGB)information is combined to show you an image that your eyes can interpret. Whilethe information is still in digital format though, this RGB information is storedin separate colour bands.
Because having images containing multiple bands of light is so useful in GIS,raster data are often provided as multi-band images. Each band in the image islike a separate layer. The GIS will combine three of the bands and show them asred, green and blue so that the human eye can see them. The number of bands in araster image is referred to as its spectral resolution.
If an image consists of only one band, it is often called a grayscale image.With grayscale images, you can apply false colouring to make the differences invalues in the pixels more obvious. Images with false colouring applied are oftenreferred to as pseudocolour images.
Another approach is to use advanced computer programs to automatically extractvector features from images. Some features such as roads show in an image as asudden change of colour from neighbouring pixels. The computer program looks forsuch colour changes and creates vector features as a result. This kind offunctionality is normally only available in very specialised (and often expensive)GIS software.
Sometimes it is useful to convert vector data into raster data. One side effectof this is that attribute data (that is attributes associated with the originalvector data) will be lost when the conversion takes place. Having vectorsconverted to raster format can be useful though when you want to give GIS datato non GIS users. With the simpler raster formats, the person you give the rasterimage to can simply view it as an image on their computer without needing anyspecial GIS software.
There are a great many analytical tools that can be run on raster data whichcannot be used with vector data. For example, rasters can be used to model waterflow over the land surface. This information can be used to calculate wherewatersheds and stream networks exist, based on the terrain.
Raster data is also very important for disaster management. Analysis of DigitalElevation Models (a kind of raster where each pixel contains the height abovesea level) can then be used to identify areas that are likely to be flooded.This can then be used to target rescue and relief efforts to areas where it isneeded the most.
Get your learners to create a raster map of your school by using A4 transparencysheets with grid lines drawn on them. Overlay the transparencies onto atoposheet or aerial photograph of your school. Now let each learner or groupof learners colour in cells that represent a certain type of feature e.g.building, playground, sports field, trees, footpaths etc. When they are allfinished, overlay all the sheets together and see if it makes a good rastermap representation of your school. Which types of features worked well whenrepresented as rasters? How did your choice in cell size affect your abilityto represent different feature types?
This section describes how to visualize and set raster layer properties.QGIS uses the GDAL library to read and write raster data formats,including ArcInfo Binary Grid, ArcInfo ASCII Grid, GeoTIFF, ERDAS IMAGINE,and many more. GRASS raster support is supplied by a native QGIS data providerplugin. The raster data can also be loaded in read mode from zip and gziparchives into QGIS.
Unlike vector data, raster data typically do not have an associated databaserecord for each cell. They are geocoded by pixel resolution and the x/ycoordinate of a corner pixel of the raster layer. This allows QGIS to positionthe data correctly in the map canvas.
Once a raster layer is loaded in the map legend, you can click on the layer namewith the right mouse button to select and activate layer-specific features or toopen a dialog to set raster properties for the layer.
I am trying to use QGIS to extract raster statistics for shapefiles (I have shapefiles of species distribution and I want to extract environmental data from within each species' range). This is possible using the Zonal Statistics plugin however I have about 300 shapefiles I need to get data from. I've tried merging the shapefiles into one but this results in massive files that cause QGIS to crash (using shapefiles >15mB causes problems).
Is there a way to automate the procedure using a Python script? I found a post that details how to run ZonalStats using Python (How to calculate raster statistics for polygons? second answer) but can't get it to work. I know absolutely nothing about Python and so I'm not sure if there's something that needs to be done before attempting to run the script or if the problem is something else. A similar script that will run on its own without user input would be ideal.
Yes you can do this in a stand alone script. To do this you efficiently, you will need SciPy. SciPy is a cousin of NumPy and together they extend Python with a lot of extremely powerful array handling capabilities. In SciPy you will use the 'ndimage' module.
Your procedure is to make a raster of your zones. Then import your original raster and the zones raster each into a NumPy array. Make a third numpy array of the unique values in your zones array to use as an index for the ndimage function. Finally use one of the ndimage statistics to extract your result, e.g.
I often write my results to a a simple csv text file and can then do a table join to pull the statistics back into my zone polygons. If you have many rasters, then you can automate the process into a batch process.
While you can do this with GDAL and indeed, will need GDAL to read the original raster and polygon data, I would not recommend that you attempt it without SciPy because the process will have glacial alacrity! See this excellent series on coding GDAL with Python. Note tutorial 6 in the series as this is especially relevant. However, it doesn't mention SciPy as it is a bit old (and where it mentions 'Numeric' understand that this has been replaced by 'NumPy'). ndimage is very fast and much better than manually iterating over a raster in a bitwise fashion or even iterating over an array cell by cell. The speed difference of using SciPy vs. NumPy alone can be seconds compared to hours for the same data (from personal experience). As a bonus, it takes less code too :)
3a8082e126