Australia/Archive/QueenslandDcdbLite

From OpenStreetMap Wiki
Jump to navigation Jump to search
Logo.png
This page describes a historic artifact in the history of OpenStreetMap. It does not reflect the current situation, but instead documents the historical concepts, issues, or ideas.


Mapserver for Queensland DCDB Lite

Windows version

This is a quick and dirty guide to get the DCDB Queensland Lite data onto your Windows machine and served out with MapServer from a PostgreSQL database. Familiarity with Windows and installing software is assumed. This is not a step-by-step guide but just highlights the main steps involved. Due to the size of the DCDB data a database is used instead of the shape file for performance reasons.

Before you continue please be warned that this guide is written by a quick scan of online documentation by a novice without a proper understanding of all of the software involved. It could break your computer so make sure you have all data backed up before starting the procedure as no responsibility can be taken for any consequences of following this guide. The method of software installation will likely result in a very insecure system so make sure it is behind a good firewall at all times.

Downloading Software and Data

1. MapServer installer from http://trac.osgeo.org/osgeo4w/ by clicking on the OSGeo4W Installer link.

2. Property Boundaries Annual Extract Queensland (Lite DCDB) from the http://data.australia.gov.au/152 website.

3. PostGIS on PostgreSQL from http://www.enterprisedb.com/products/download.do by clicking on Download for PostgreSQL 8.4 under Windows.

Installing

1. Install MapServer by running the osgeo4w-setup.exe file from your download folder. Choose Advanced Install. Choose Install for Internet. Keep the default Root Directory of C:\OSGeo4W. Keep the default Local Package Directory. From the list expand Web and select apache, mapserver and php. Expand Web_Applications and choose any further apps including gmap for testing if you like. Next and allow any dependancies to be resolved. Make folders C:\OSGeo4W\apps\dcdb\htdocs and C:\OSGeo4W\apps\dcdb\data. If Apache OSGEO4W Web Server is not already installed in services.msc, do Start / Programs / OSGeo4W / Apache / OSGEO4W-Apache-Install. In Vista or Windows 7 you may need to run as Administrator.

2. Unzip IQATLAS.QLD_CADASTRALBDY_DCDB_YR.zip contents to C:\OSGeo4W\apps\dcdb\data.

3. Install PostGIS by running the postgresql-8.4.1-1-windows.exe. Keep defaults including server port of 5432. Choose and remember your password as you will need it for future steps. Use the Stack Builder. Under Spatial Extensions, select PostGIS 1.4 for PostgreSQL 8.4 v1.4.0. Be sure to have Create spatial database selected. Add the PostgreSQL bin folder to your system path. (Depending on your version of Windows: Computer / Properties / Advanced system settings / Advanced / Environment Variables / Path / Edit and add something like ";C:\Program Files (x86)\PostgreSQL\8.4\bin" to the end of the path.)

Configuring

1. Change the apache server port to one that won't clash with other servers on your computer. Edit C:\OSGeo4W\apache\conf\httpd.conf by finding Listen 80 and changing it to Listen 8087 for example. Uncomment the very last line in the file to log MapServer errors. Notice how the ScriptAlias /cgi-bin/ "C:\OSGeo4W/bin/" line puts all binaries available for execution from http://localhost:8087/cgi-bin which is probably not a good idea so keep your server behind a good firewall and DO NOT serve this out on the internet. Save httpd.conf. Restart Apache OSGEO4W Web Server from Start / Run / services.msc. Test the server by browsing to http://localhost:8087/

1.1 Optionally to test the mapserver if you installed gmap you need to fix two files. Edit C:\OSGeo4W\apps\gmap\htdocs\gmap75.map and add MAP on a new line at the top of the file. Edit C:\OSGeo4W\apps\gmap\etc\symbols.txt and add SYMBOLSET on a new line at the top of the file. Test gmap from http://localhost:8087/gmap/gmap75.phtml in a browser.

1.2 Create the file C:\OSGeo4W\httpd.d\httpd_dcdb.conf with contents:

Alias /dcdb/ "C:/OSGeo4W/apps/dcdb/htdocs/"

<Directory "C:/OSGeo4W/apps/dcdb/htdocs/">
  AllowOverride None
  Options Indexes FollowSymLinks Multiviews 
  Order allow,deny
  Allow from all
</Directory>

1.3 Create the file C:\OSGeo4W\apps\dcdb\htdocs\wms.osm.au.qld.map with contents: (don't forget to change the line with <yourpasswordhere> in it)

#
# Start of WMS Server map file
#
MAP
NAME WMS_server
STATUS ON
## ESPG:4326 extents:
EXTENT 137.994646 -29.178024 153.551832 -9.141952
UNITS METERS
SHAPEPATH "C:/OSGeo4W/apps/dcdb/data"
IMAGECOLOR 0 0 0

#
# Start of web interface definition
#
# On Windows systems, /tmp and /tmp/ms_tmp/ should be created at the root 
# of the drive where the .MAP file resides.
#
WEB
  IMAGEPATH "C:/OSGeo4W/tmp/ms_tmp/" 
  IMAGEURL "/ms_tmp/"
  METADATA
    "wms_title"                  "Property Boundaries Annual Extract Queensland (Lite DCDB)"
    "wms_onlineresource"         "http://localhost/cgi-bin/mapserv.exe?MAP=C:\OSGeo4W/apps/dcdb/htdocs/wms.osm.au.qld.map"
    "wms_srs"                    "EPSG:4326"
    "wms_feature_info_mime_type" "text/html"
    "wms_abstract"               "Property Boundaries Annual Extract Queensland (Lite DCDB). Data from http://data.australia.gov.au/152. Copyright: Creative Commons - Attribution 2.5 Australia (CC-BY) by Queensland Department of Environment and Resource Management, http://dds.information.qld.gov.au/dds."
  END
END

PROJECTION
  "init=epsg:4326"
END

#
# Start of layer definitions
#
LAYER
  NAME dcdb_lite_geometry_test
  METADATA
    "wms_title"    "DCDB_QLD"
  END
  TYPE POLYGON
  STATUS OFF
  DATA iqatlas
  PROJECTION
    "init=epsg:4326"
  END
  CLASS
    NAME "DCDB_QLD"
    STYLE
      COLOR 50 240 50
      OUTLINECOLOR 240 50 50
    END
  END
END # Layer

LAYER
  NAME dcdb_lite_geometry
  METADATA
    "wms_title"    "DCDB_QLD"
  END
  TYPE POLYGON
  STATUS OFF
  CONNECTIONTYPE POSTGIS
  CONNECTION "host=localhost dbname=postgis user=postgres password=<yourpasswordhere> port=5432"
  DATA "the_geom from dcdbqldlite using unique gid using srid=4326"
#  DATA "the_geom from (select dcdbqldlite.gid, ST_Simplify(dcdbqldlite.the_geom, 10.0) as the_geom from geotable dcdbqldlite order by ST_Area(dcdbqldlite.the_geom) desc limit 10) as subquery unique gid using srid=4326"
  PROJECTION
    "init=epsg:4326"
  END
  CLASS
    NAME "DCDB_QLD"
    STYLE
      COLOR 50 240 50
      OUTLINECOLOR 240 50 50
    END
  END
END # Layer

END # Map File

2. Shorten all the long filenames in C:\OSGeo4W\apps\dcdb\data from IQATLAS.QLD_CADASTRALBDY_DCDB_YR.* to just iqatlas.* for example iqatlas.dbf, iqatlas.shp, iqatlas.shx etc.

2.1 Optionally test the mapserver with data from the raw shape files by using the WMS URL in say JOSM: (be aware this will be painfully slow while it processes the 400MB+ shape file repeatedly for each tile)

http://localhost:8087/cgi-bin/mapserv.exe?MAP=C:\OSGeo4W/apps/dcdb/htdocs/wms.osm.au.qld.map&SERVICE=wms&VERSION=1.1.1&LAYERS=dcdb_lite_geometry_test&REQUEST=GetMap&SRS=EPSG:4326&FORMAT=image/png&

3. Start a command prompt and change to the C:\OSGeo4W\apps\dcdb\data directory. To import the data into PostgreSQL type the following:

shp2pgsql -D iqatlas public.dcdbqldlite > dcdbqldlite.sql
psql -h localhost -U postgres -d postgis -f dcdbqldlite.sql

Note: A nice way to crash a text editor is to try and edit the 800MB+ dcdbqldlite.sql file.

3.1 Use Start / Programs / PostgreSQL 8.4 / pgAdmin III query tool to make an index by running: (these commands will take a while to run depending upon your computer)

CREATE INDEX dcdbqldlite_the_geom_gist ON dcdbqldlite USING gist (the_geom);

and then vacuum and analyse the table by running the query tool with:

VACUUM ANALYZE dcdbqldlite;

Conclusion

Finally test the database powered mapserver with the WMS URL:

http://localhost:8087/cgi-bin/mapserv.exe?MAP=C:\OSGeo4W/apps/dcdb/htdocs/wms.osm.au.qld.map&SERVICE=wms&VERSION=1.1.1&LAYERS=dcdb_lite_geometry&REQUEST=GetMap&SRS=EPSG:4326&FORMAT=image/png&

This guide could certainly be improved tremendously by someone who is familiar with the software.

You should be able to use a similar procedure to serve any of the shapefiles from http://data.australia.gov.au/ or other sources from your Windows based box.