This site contains excerpts and examples of topics covered in the book. Beta Book Available Now at Pragmatic Bookshelf!!
View Contents
Suppose you want to extract features from a vector layer to create a smaller subset. This can be very handy if you have a large dataset and need just a portion of it for your current project. If your data happens to be in one of the formats supported by OGR, you can use ogr2ogr to create a new layer.
First let's look at extracting by a simple bounding box. Say we want to pull Canada, United States, and Mexico from the world_borders shapefile. This can easily be done with a small bounding box that crosses each of the countries:
For this example, we’ll create a map of Alaska and annotate it. If you looked at the Simple Globe example you'll recall that the -R switch controls the extent of a GMT map. Alaska ranges from about 172 degrees east longitude to 130 degrees west. Using 360 degrees for the entire globe, this translates to a region extending from 172 degrees to 230 degrees. For the Alaska map we will use the Albers Equal Area Conic projection. Looking at the syntax for pscoast reveals that this requires the use of the -Jb switch. In this case, we use the lowercase “b” to indicate that we will specify the size of the map using a scale. First lets look at the command used to create the map:
pscoast -Jb-154/50/55/65/1:12000000 -R172/230/51/72 -B10g5/5g5 -W1p/0/0/0 \ -I1/2p/0/192/255 -I2/2p/0/192/255 -I3/1p/0/192/255 -I4/1p/0/192/255 \ -G220/220/220 -S0/192/255 -L210/54/54/1000 -P -N1/1p/0/0/0 -Dl >gmt_alaska_coast.eps
This looks like quite a complex command, but it’s really not too bad once you get past all the numbers and slashes.
The Generic Mapping Tools (GMT) can be used to create high quality maps for printing or use in web pages or documents.
You can easily create a simple globe (similar to the one on this website) using GMT. Here is the command:
pscoast -JA0/20/2.5i -Bg30/g15 -Dl -A2000 -G187/142/46 -S109/202/255 \ -R0/360/-90/90 -P -N1 > simple_hemi.eps
This produces:
Sometimes you need just a portion of a raster for use in your latest mapping project. In this example we will see a simple way to extract a rectangular region of an image and warp it to the desired projection.
The tools for accomplishing this feat are gdal_translate and gdalwarp, both part of the GDAL suite of utilities. On Linux and Windows you can easily get access to these tools by installing FWTools. If you use a Mac, download the GDAL framework and required dependencies from Kyng Chaos.
The U.S. Geological Survey has an excellent poster on projections available at http://erg.usgs.gov/isb/pubs/MapProjections/projections.pdf. You can also download it from this site.

The sample data for Desktop GIS includes world boundaries, cities, and a global mosaic.
Download World Boundaries and Cities (3.3 Mb, Shapefiles)
Download World Mosaic (31 Mb, TIFF)
Recent comments
21 weeks 1 day ago
21 weeks 5 days ago