Tasmania Testbed / 1st Map
Click on the image to the right for a first simple map in SVG showing rivers, lakes, roads, railroads, airports and mayor cities. GIS vector data at a scale of 1:1.000.000 has been downloaded from Geoscience Australia, Global Map Australia 1M 2001. Raster data has been interpolated using contour lines from four map sheets of the GEODATA TOPO 250K Series 2 with ArcView 3.2, Spatial Analyst and the Contour Gridder extension.
Import of vector data into PostgreSQL
PostGIS provides a commandline tool called shp2pgsql that allows you to load shapefiles into database tables. Usage is straight forward and looks as follows:
shp2pgsql -c roads.shp roads tasmania > load_roads.sql
-ccauses CREATE TABLE statements to be included in the outputroads.shpspecifies the shapefile to useroadsis the name of the database table where geometry and attributes will be storedtasmaniais the database where the table will reside> load_roads.sqlpipes the output to a file that will contain sql-statements that can be loaded to the database with:
psql -f load_roads.sql tasmania
Delivery of geometry as SVG
Creation of the SVG-content is realised with Perl using the DBI module. Here's the source code of map.perl and a short explanation of what's happening:
- predefine style attributes
- connect to PostgreSQL using the DBI module
- build sql query using the AsSvg() function to deliver svg-code
- query database, parse result and build <path />, <use /> or <text /> elements
- pack attribute data into a custom namespace (e.g: <path d="..." tas:name="HOBART" />)
- send image/svg+xml header and svg content containing
- viewBox to define where we're looking to
- symbol definiton for the airplane symbol that can be referenced with <use ... />
- background image to show elevation
- geometry with styles and attributes collected from the query
- if you call the script from the commandline you can save the script's output to a file like with:
./map.perl noheader=1 > overview.svg
As you've noticed when looking at the map, some of the labels are doubled and some labels overlap. Well, the original data had no field that allowed to decide where labels for cities should be placed, so i've added one in the shapefile, altered the table structure and implemented a simple label placement. Click on the map to the right to see the result. If you're interested in how it was done - read on.
Simple Label placement
Simple label placement may be implemented using nine reference positions and one special case - skip it. The SVG on the right shows these positions - just click on the numbers. Text is moved by setting baseline-shift and text-anchor and as font-size may change, baseline-shift is specified using em - this allows font-size independet functionality. text-anchor may be set to start|middle|end. One could specify additional dx and dy attributes as well, but for a first try, nine positions should be enough to get a better result.
click here for the updated map
