Extension:SpatialWiki

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
SpatialWiki

Release status: beta

Implementation Database, Parser function
Description Adds spatial references to a separate geospatial database and displays maps in Wiki pages.
Author(s) Brian Krzys (cokrzysTalk)
Last version 0.01
MediaWiki 1.15
License MIT
Download https://sourceforge.net/projects/spatialwiki/files/
Hooks used
ArticleSaveComplete

ArticleDeleteComplete
LanguageGetMagic

Check usage (experimental)

Contents

[edit] Introduction

The SpatialWiki extension parses the wiki text after a page is saved and extracts a coded spatial reference and stores it in a standalone geospatial database. The spatial references can be displayed in wiki articles with click-able links to other spatially referenced content. This extension was originally developed for use in a talk at the 2011 FOSS4G Conference.

A tutorial that walks through setting up the back-end architecture including PostgreSQL/PostGIS, GeoServer, and OpenLayers is maintained in the AuSpatial Blog.

[edit] Installation

The installation notes below are generally for a Linux Ubuntu instance.

This extension can be used to simply display maps, but to make full-use of the capabilities you have to do a fair bit of back-end work to setup a spatial database to store the spatial references, along with a map server and web extension to serve the points to the wiki pages. These steps are outlined in the following posts:

The files for this extension are maintained on SourceForge, and can be downloaded from here:

Whether you download from the .zip file or Subversion you want to put the following files in an extensions/SpatialWiki folder:

SpatialWiki.php
SpatialWiki.body.php
SpatialWiki.i18n.php
SpatialWiki.js

Once the files are installed add the following to LocalSettings.php:

require_once("$IP/extensions/SpatialWiki/SpatialWiki.php");


The extension utilizes a number of configuration parameters which are setup in LocalSettings.php, for example like this:

$wgSpatialWikiDebugMessages = false;
$wgSpatialWikiDatabase = "spatialwiki";
$wgSpatialWikiUsername = "postgres";
$wgSpatialWikiPassword = "secret";
$wgSpatialWikiPointsTable = "wikipts";
$wgSpatialWikiOpenLayersPath = "http://[your server]/OpenLayers-2.11-rc3";
$wgSpatialWikiWmsPointsUrl = "http://[your server]:80/geoserver/spatialwiki/wms";
$wgSpatialWikiGeoServerPointsLayer = "spatialwiki:wikipts";

Configuration Parameter Notes

The following values should be setup in LocalSettings.php.

Parameter Description
$wgSpatialWikiDatabase Name of the PostgreSQL/PostGIS database that the spatial references will be written to. See notes above about setting up the database.
$wgSpatialWikiDebugMessages Flag to turn debug messages on/off. Values are true/false, default is false. Debug messages are written to the web server's error log.
$wgSpatialWikiGeoServerPointsLayer The name of the layer within the WMS service that you've setup with GeoServer to display the spatial references for the articles. See setup notes above.
$wgSpatialWikiOpenLayersPath The path to where you've installed OpenLayers (see above).
$wgSpatialWikiPassword The password to use when connecting to the spatial database.
$wgSpatialWikiPointsTable The database table to store the spatial references in. The table must be setup per the notes above about setting up the database.
$wgSpatialWikiUsername The username to use when connecting to the spatial database, must have read/write/delete privileges on the spatial points table.
$wgSpatialWikiWmsPointsUrl The URL for the GeoServer WMS layer you've setup (see notes above) that displays the points for the wiki articles from the spatial database.

[edit] Usage

The extension both writes spatial references and can be used to display maps. These two activites are not necessarily related and are described individually below.

[edit] Writing Spatial References

The extension makes use of a subset of the Wikipedia Coord Template to read spatial references from an article so simply add a reference like the following to your article:

{{Coord|41.4854|-82.6870|Test}}

If you don't have a Coord template setup you can use something like the example shown below to nicely format the spatial reference for display on the page. The extension does nothing with formatting the reference, it just reads it from the page once it's been saved and adds it to the spatial database.

The required template parameters are the decimal latitude for the point, the decimal longitude, and the point type. The point type must be a valid point type that exists in the Spatial Database.

[edit] Displaying Maps

Note, to display maps you must have OpenLayers installed as a minimum.

The map display is based on a "magic" word, SpatialWikiMap defined in the extension so you use it like this:

{{ #SpatialWikiMap: }}

This will display a basic map using default parameters as shown below.

File:Extension spatialwiki fig01.png
Extension:SpatialWiki basic map


The complete syntax for the SpatialWikiMap tag is:

{{ #SpatialWikiMap: centerLat | centerLong | zoom | width | height | includeWikiPoints | showMarker }}

Where:

Parameter Description
centerLat Center latitude for the map to display, in decimal degrees. Default is 12.0.
centerLong Center longitude for the map to display, in decimal degrees. Default is 20.0.
zoom Zoom factor, generally from 1 (farthest out) to 20 (closest in). Default is 2.
width Width for the map on the screen, can be a typical HTML type of width like 600px for 600 pixels or 80% for 80% of the page width. Default is 100%.
height Height for the map on the screen, can be a typical HTML type of width like 400px for 400 pixels. Default is 400px, this value cannot be 100%.
includeWikiPoints Value of true or false to include points from the spatially referenced articles or not. Default is false. When wiki points are displayed the $wgSpatialWikiWmsPointsUrl and $wgSpatialWikiGeoServerPointsLayer parameters must be set and the spatial back-end infrastructure must be in-place per notes above.
showMarker Value of true or false to display a star in the center of the map. Default is false. When used this is typically applicable with a template like the one shown below.

[edit] Example Template

The SpatialWikiMap magic word can be used in a template that also formats the spatial reference for a page. For example you might setup your Template:Coord like this:

{{ #SpatialWikiMap:{{{1|12.0}}} | {{{2|20.0}}} | 10 | 507px | 350px | true | true }}

{| border="0" cellpadding="4" cellspacing="0" style="border:0px solid darkgray;"
! width="500px"|
|- 
| valign="top" style="background:#e4f7dd; border-style: solid; border-width: 1px 0 1px 0; border-color:darkgray"| {{PAGENAME}}: Latitude {{{1|0.0}}} Longitude {{{2|0.0}}}, Type {{{3|Undefined}}}
|}

Which will display a map of the spatial location for the page along with a formatted box with the coordinates below the map like:

File:Extension spatialwiki fig02.png
Extension:SpatialWiki location page with formatted coordinates


[edit] Troubleshooting

The extension writes messages to the web server's error log. This will vary by OS, but for example under Ubuntu 10.04 this will be in /var/log/apache2/error.log and you can look at the end of it (the most recent entries) with something like:

tail error.log -n20

Error messages will be written no matter what, to also include debug messages set $wgSpatialWikiDebugMessages as noted above to true.

When working on this I also encountered page-refresh problems that didn't seem to get resolved via disabling the parser cache in the extension (this is still in there) so the recommended settings in LocalSetting.php to disable all caching are:

$wgMainCacheType = CACHE_NONE;
$wgMessageCacheType = CACHE_NONE;
$wgParserCacheType = CACHE_NONE;
$wgCachePages = false;

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox