Real world example

kbh3rd edited this page Sep 13, 2010 · 10 revisions
Clone this wiki locally

This shellscript below was used to generate the map shown at right using the shptosvg.pl utility. You can see a larger PNG version of it by clicking on the image, and that is linked to the SVG rendering itself.

The shapefiles used are:

ogallala_us_state.shp

Outline of the 8 states overlying the Ogallala Aquifer. This is used twice; once for the background color that must underly all other layers, and once for just the outlines that lie above the aquifer rendering.

(I had this 8-state shapefile left over from earlier work with this subject, using a GIS program that did not let me select only certain shapes to show; I had to create a shapefile containing only the objects I wanted to render. This utility, on the other hand, has the ability to select objects for inclusion, and indeed is how the county outlines are selected as explained below.)

co99_d00.shp

All counties in the United States. Only the counties in the 8 subject states are selected for drawing by use of a ‘grep’ directive in the input spec that selects the counties by the states’ FIPS codes, which is one of the data attributes of this shapefile.

sattk_97.shp

Saturated thickness of the aquifer. This file contains complex shapes that overlap each other. They must be drawn in the order encountered to be rendered correctly, so no regrouping can be done. The shapes are colored according to the “RANGE” attribute in the data, which contains the specific strings being matched in the inputspec with the ‘colorby’ option.

Rivers.sh

The channels of the major rivers of the United States. Select only the Platte, Arkansas, Red, and Brazos rivers with the ‘grep’ directive. There is a Red River in North Dakota that we’re not interested in, but it appears in the data slightly differntly than the OK-TX Red River, so we can grep the one we want; otherwise both woud appear, requiring manual post-processing to remove the irrelevant instance.

The SRS of each input file is specified in its inputspec.

The target projection is an Albers equal-area centered on the aquifer at 100 degrees west longitude with standard parallels at 29.5 and 45.5 degrees north latitude. This is specified in the argument to the -T parameter.

The SVG generated from this script is fairly complete. The following manual post-processing steps were done with Inkscape before posting to Wikimedia Commons:

  • The rivers were edited to clip the Arkansas and Red rivers at the state lines, and a reservoir outline on the Red River was manually removed.
  • The thin stroke outline was added to the aquifer areas; this ought to have been in the original output and bears further investigation.
  • The state names and the legend were manually added.

The map was rendered with this command (a single command broken into multple lines with “\” characters for readability):

#!/bin/sh

shptosvg.pl -x 600 -y 800 "$@" -T "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-100 +x_0=0 +y_0=0 +ellps=clrk66 +datum=NAD83 +units=m +no_defs"	\
\
\
  ogallala_us_state.shp,srs="+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs",style="fill:#ffffd0;stroke:none" \
\
  sattk_97.shp,style="stroke-width:0.333;stroke:#00000;fill:#808080",srs="+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=clrk66 +datum=NAD27 +units=m +no_defs ",colorby="RANGE;m/island/#ffffff;m/0 to 50/#cfef7f;m/50 to 100/#a1f574;m/100 to 200/#95fbcb;m/200 to 400/#77d9f0;m/400 to 600/#93beea;m/600 to 800/#7e90dc;m/800 to 1000/#6145fd;m/1000 to 1200/#1c00d2" \
\
  co99_d00.shp,srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",style="stroke-width:0.333;fill:none;stroke:#D0C0A0",grep="STATE~(48)|(08)|(20)|(31)|(35)|(40)|(46)|(56)",group=STATE \
\
  ogallala_us_state.shp,group=NAME,srs="+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs",style="stroke-width:1;fill:none;stroke:#a08070" \
\
  Rivers,grep="NAME~(Platte)|(Red$)|(Brazos)|(Arkansas)",style="stroke:#1821DE;stroke-width:1",srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" \
\
\
    > ogallala.svg

exit $?

Obviously the command line for shptosvg can get very long. It’s also complicated, meaning it can take multiple iterations to get just what you want produced. For both reasons it is probably best to create a shellscript file that you can edit and run in turns until you’re satisfied. You’ll also have a record of exactly how you used the utility to generate the output, and you can add comments to it also. Note that the "$@" right near the beginning lets me add additional command line parameters whenever I invoke the shellscript.