GIS techniques can help actualize your, and others', imagination.
From the shifting shape of Thomas More's Utopia, to New World maps losing whole continents between editions, to the introductory maps of J.R.R. Tolkien's Lord of the Rings, maps and the imaginary have been intertwined. Early cartography covered unknown continents with speculative features, but in these days of satellite photography, everything on the surface of the earth that can be mapped is.
Where is the unknown to be found? The world of your imagination could fill a dozen atlases: imaginary landscapes, cities, routes. Mapping them is a practice known to some as geofiction, defined at http://geofiction.wikiverse.org/. With the many tools and techniques covered in this book, you can translate the stuff of your stories beyond paper maps into full-on GIS data models.
9.9.1. Generate an Ellipsoid and Datum for an Imaginary World
A fictional planet has a size and a shape. Packages such as PostGIS and Manifold will allow you to define your own ellipsoid or spheroid and will support novel or obscure reference datums. Manifold already comes with ellipsoidal or spheroidal definitions for all the planets and some moons in the solar system, useful when you decide to [Hack #34]
Some fictional worlds have clearly defined and imagined topologies, which should be simple to reproduce in a GIS. A Game World in Iain M Banks's The Player of Games is a flattened ellipsoid that has one strip of land running around the equator, a forest fire perpetually circling round it each year. We amateur GIS hackers had possibly best avoid weird extraplanetary shapes, such as Banks's artificial torus-shaped Rings or Terry Pratchett's DiscWorld, an upturned saucer with a mountain at the center.
A perfect spheroid is basically defined by one value: the radius of its axis. Figure 9-17 illustrates the slightly more complex definition of an ellipsoid. An ellipsoid is a flattened spheroid, so it has two axes: a major and minor axis, the former wider than the latter. In GIS, we conventionally define an ellipsoid using two values: the radius of its major axis, known as the semi-major axis, and the inverse flattening. The flattening is the ratio of the difference between the two semi-axes, major and minor, to the major axis (f = (a-b)/a). The inverse flattening is just the inverse of the flattening, 1/f, which probably became a standard because large numbers are easier to deal with programmatically than very small floating-point ones.
Figure 9-17. Defining an ellipsoid
Once you've decided on a size and shape for your imaginary world, you can add this ellipsoid to your favorite GIS program. Here we show how to add an new ellipsoid to a PostGIS database. See [Hack #87] to get started with PostGIS.
The PostGIS set of extensions allows you to store spatial information in different projections and do spatial calculations on it. PostGIS stores its reference list of ellipsoids and projections in a table called spatial_ref_sys, which must be included in every spatially enhanced database. Each column in the spatial_ref_sys table has an SRID, a commonly known spatial-reference identifier, and a reference to a standards body that manages that SRID and owns the definition of the ellipsoid. Bizarrely enough, this is in many cases the EPSG, the European Petroleum Standards Group. Now you get to impersonate your own standards bodythe Intergalactic Astrospatial Consortium, let's say. The IAC, our new self-organization, allocates a serial number to each spatial reference system, so let's pick one at random that hasn't already been bagged by the EPSG.
The following SQL statement is a template for adding an imaginary surface to your PostGIS database. It uses a representation of the geometry called Well Known Text (WKT):
insert into spatial_ref_sys (srid,auth_name,auth_srid,srtext,proj4text) VALUES (9999, 'IAC',9999, GEOGCS["GCS_IAC_A2484", DATUM["D_IAC_A2484", SPHEROID["IAC_A2484",3487375,254.5]], PRIMEM["New New Albemuth",0], UNIT["Degree",0.017453292519943295]]', '+proj=longlat+ellps=WGS84 +datum=WGS84')
The GEOGCS[ entry is where we define our coordinate system, known as A2484, with a prime meridian of New New Albemuth. For future spatial analysis, the important part of this is the SPHEROID definition inside the WKT: SPHEROID("made_up_name",<semi-major axis>,<inverse flattening>). The UNIT is 2/360, the number of degrees per radian; degree-based coordinate systems are (relatively) simple and familiar, so don't change it. The semi-major axis and inverse flattening tell PostGIS how to calculate distance and area from points based on a latitude/longitude coordinate system. Ours is an unprojected, geographical coordinate system. [Hack #26] explains how different projections work in more depth. Try SELECT SRID,SRTEXT FROM SPATIAL_REF_SYS from your database shell to see all the different projections normally available in PostGIS.
The last value, PROJ4TEXT, tells proj4 how to perform coordinate transformations and isn't really necessary for our purposes, so we just borrow the definition for WGS84 for the sake of completeness. For in-depth information about the PostGIS spatial tables, check out the online documentation at http://postgis.refractions.net/docs/ch04.html.
Now when you insert and retrieve points or other bits of geometry into PostGIS, use your new SRID and you can perform realistic spatial querying and indexing on your imaginary world. So far, this may have seemed abstract, but now we have the cornerstone of all manner of geospatial services and interfaces to render your imagination a virtual reality.
9.9.2. Generate Imaginary Topography
If you can run GNOME, then Terraform (http://terraform.sf.net/) comes recommended as a great integrated GNOME application that generates height fields for terrain models. It has a selection of beautiful plug-ins to scatter your terrain with craters, volcanoes, and more, and it will also import DEMs, digital elevation models, of real places.
For lucky Debian users, Terraform is available from apt; just type apt-get install terraform. At the time of writing, packages for OS X are slated for imminent release. Building the application from source should be easy as long as you have the libgnome-dev and libgnomeprint libraries installed. Run ./configure; make; make test; make install.
Terraform will also let you import DEMs of real places in .png, .tif, or .tga format and creatively adapt or destroy them. (Ever wondered what your city would look like threaded with a network of canals, or with downtown replaced by a mountain?) Figure 9-18 shows an imaginary place in Terraform.
Figure 9-18. Terraform DEM of imaginary topography
Consider using Terraform to generate a series of "georeferenced" tiles that represent the height field for your imaginary world at some arbitrary resolution (LANDSAT is available at 30-meters-per-pixel resolution for the U.S., and 90 meters for the rest of the world, which seems like an adequate start. Each tile can come accompanied with a world file [Hack #33] , which describes its extents in space.
As you may have expected, GRASS also has tools to generate random terrain. GRASS provides the r.surf.fractal command that creates a fractal surface. Assuming you've started GRASS, try:
GRASS 5.7.0:~ > r.surf.fractal out=fractal_surface d=2.05 GRASS 5.7.0:~ > d.mon start=x1 GRASS 5.7.0:~ > d.rast fractal_surface
Every time you run r.surf.fractal you get a new output, and I got the image in Figure 9-19.
Figure 9-19. A fractal world
Another bite at the fractal apple gave me a passable rendition of Two Harbors on Catalina Island in Southern California (Figure 9-20).
Figure 9-20. A known place seems to emerge from a "random" fractal
9.9.3. Gazetteer for Imaginary Places
With our new imaginary coordinate system, we can geocode fictional places. In [Hack #84], we suggested that the "next steps" involve a PostGIS database to store points with proper geometry, rather than separate database columns for latitude and longitude. Here's how you go about adding a geometry column to a Postgres database with PostGIS installed:
SELECT AddGeometryColumn ('database_name','table_name','column_name', ,'GEOMETRY',2);
This statement adds a GEOMETRY field (which can contain points, lines, or shapes) to a table of our choosing. The fourth item in this statement, the SRID, is replaced with our new ellipsoid identifier, 9999, as approved by the Intergalactic Astronavigation Consortium. The last item is dimensionality, indicating that this piece of geometry has two dimensions. The latest release of PostGIS supports four-dimensional geometry, which is, frankly, worrisome.
[Hack #87] provides more detail on how to create and query spatial tables in your database. To get started, add new columns describing points into your PostGIS database as shown here, where the last value is the SRID of your imaginary reference system:
INSERT INTO table_name (column_name) VALUES (GeometryFromText('POINT(" ")',9999))
Now each city, town, and other landmark in your imaginary world can have geometry that can be queried associated with it. Cities might be scattered round an equatorial strip of land near latitude 0, or huddle near the cold poles on a terraformed world uncomfortably near its sun.
9.9.4. Spatial Index of Imaginary Places
PostGIS allows points, lines, and shapes to be combined in one geometry column in the same table. Now you can think about creating shapefiles for towns and countries, and political and economic districts in your fantasy world. Use Illustrator or another vector drawing environment to create vector shapes that can be converted into ESRI Shapefile format or SVG. If you tire of urban planning by hand, send a fleet of tiny agents to create lowest-shortest-path solutions using a routing algorithm [Hack #2] . Create ambitious public transport networks to carry your citizen-consumers between imaginary continents.
9.9.5. Web Services about Imaginary Places
Once you have a spatial database representing your imaginary world, consider setting up a Web Feature Service to publish your annotations on the geospatial web. [Hack #89] works by connecting a PostGIS database to a WFS and WMS server. Soon enough, a semantic web autodiscovery agent will be trying to book plane flights to the capital city of your imagination. This could happen sooner than you think! The idiosyncratic Knowhere guide to the UK (http://www.knowhere.co.uk), a site that's been around for over 10 years, features the friendly town of Chuffing Hell, somewhere in Yorkshire, with a small but flourishing online community. Other sitesmostly big directories that assemble massive link collections ostensibly related to towns and citiescrawled Knowhere and used its knowledge base to seed an online directory; now a web search for "Knowhere" abounds with listings for Chuffing Hell's local florists, computer retailers, and other exciting services.
Now that you've seen the first hundred mapping hacks, it's time for you to go make your own. There are literally thousands of potential mapping hacks out there, one for every story someone's got to tell. Find selections of our next hundred at http://mappinghacks.com/!
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects.
The tool on the cover of Mapping Hacks is a compass. Used since the eleventh century as a navigation device, the compass consists of a magnetized needle stabilized on a friction-free pivot point. The lightweight needle acts as a detector for Earth's magnetic field, which attracts the needle such that its north end points toward the North Pole. Contemporary mariners often deploy the more sophisticated gyrocompass for navigation, which uses a spinning wheel constrained by the forces of friction to orient itself toward the North Pole. The gyrocompass is considered superior to its magnetic counterpart because it relies solely on Earth's rotation for its readings and thus always locates True North, as opposed to Magnetic North.
Sanders Kleinfeld was the production editor and copyeditor for Mapping Hacks. Linley Dolby was the proofreader. Adam Witwer and Claire Cloutier provided quality control. John Bickelhaupt wrote the index.
Hanna Dyer designed the cover of this book, based on a series design by Edie Freedman. The cover image is from photos.com. Emma Colby produced the cover layout with Adobe InDesign CS using Adobe's Helvetica Neue and ITC Garamond fonts.
David Futato designed the interior layout. This book was converted by Joe Wizda to FrameMaker 5.5.6 with a format conversion tool created by Erik Ray, Jason McIntosh, Neil Walls, and Mike Sierra that uses Perl and XML technologies. The text font is Linotype Birka; the heading font is Adobe Helvetica Neue Condensed; and the code font is LucasFont's TheSans Mono Condensed. The illustrations that appear in the book were produced by Robert Romano and Jessamyn Read using Macromedia FreeHand MX and Adobe Photoshop CS. This colophon was written by Sanders Kleinfeld.
The online edition of this book was created by the Safari production group (John Chodacki, Ken Douglass, and Ellie Cutler) using a set of Frame-to-XML conversion and cleanup tools written and maintained by Erik Ray, Benn Salter, John Chodacki, Ellie Cutler, and Jeff Liggett.