Traditionally, access to municipal geospatial data has been application-centric, either through a web interface with a steep learning curve, or through data downloads or services for use in desktop GIS. While these are both much better than not providing access at all, neither strategy is particularly effective in getting the data to the people most interested in it: local residents. This limitation has become painfully clear in an age when you can find almost any other information by typing a few words into a search engine. Also, in the absence of ready access to our data, citizens are spending countless hours re-creating it, when they could instead be adding value and stimulating the economy.
By linking to open source components such as MapGuide, FDO, POCO, CTemplate, and libkml, the MapGuide REST framework is very simple and powerful. With absolutely no programming, a site administrator can build out customised HTML and KML representations of their data, and enable access to default GeoJSON and FDO-based XML representations. Pair these representations with static HTML pages that expose "service metadata", and you have data that is easily crawlable by search engine spiders, and easily understood by anyone wanting to access the data for other applications. Enough talk; let’s go over some examples from the City of Nanaimo’s live web site.
Data URI: http://maps.nanaimo.ca/data/
This is where all of the City’s RESTful GeoData will be exposed. Currently, there is a single resource type exposed for Property information, but more is on the way and will be interlinked when it makes sense. The index page for this directory is a static HTML page pointing to various features of the Property resource type.
Property Resources: http://maps.nanaimo.ca/data/property/
This currently displays a page that allows users to search by one of three attributes by HTML forms, and contains links to OpenSearch (with draft Geo) documents that define some of the other search and representation capabilities.
As well, there is a link to a Street Index which acts as a form of sitemap, providing web crawlers with an equal-length trip to every property in the City.
Example Property HTML Representation: http://maps.nanaimo.ca/data/property/123170.html
As much as this looks like a regular web page, it is cram-packed with features that make it distinguishable as a geospatial resource. Most visibly, it displays an image of the property’s shape in context, and provides a link to the KML representation of that property. Digging a little bit deeper, the page header contains links to alternate representations:
and some simple geotags:
<meta name="ICBM" content="49.18882, -123.9785">
<meta name="geo.region" content="CA-BC">
<meta name="geo.placename" content="Nanaimo">
<meta name="geo.position" content="49.18882;-123.9785">
Finally, within the page content itself, you will find both adr and geo microformats.
<span class="street-address">2143 AARON WAY</span>,
<span class="country-name" style="display:none;">CANADA</span>
Example Property KML Representation: http://maps.nanaimo.ca/data/property/123170.kml
The KML representation uses Atom Author and Link elements to define the publisher of the data, and to store the KML’s URI and that of its alternate HTML representation. It also uses a combination of ExtendedData and BalloonStyle entities to separate data from presentation, though I have also included a link to the HTML representation in the Description entity for earlier clients. Finally, it uses external Style and Schema definitions to reduce the size of the file and to maintain consistency across the site. I’d encourage you to view the source of the KML file to see how these elements work together.
Example JSON Representation: http://maps.nanaimo.ca/data/property/123170.json
Example XML Representation: http://maps.nanaimo.ca/data/property/123170.xml
Example PNG Representation: http://maps.nanaimo.ca/data/property/123170.png
The native GeoJSON and FDO XML representations are provided by the extension. No customization is possible, which ensures a consistent implementation from site to site. The PNG representation is also native (not template), but allows you to specify a MapGuide map definition and a layer for selection.
"Endpoints" (because I’m not sure what to call them):
This is a static file that allows KML clients to interact with the property information dynamically through View Based Refresh. Basically, this file tells Google Earth to request the .kmz endpoint below using a BBOX element that will be used to return only features in view, or a warning if the viewport is too large.
These allow users to perform queries on the data. There are quite a few variations possible, but they basically support standard FDO filters, bbox, count, and start GET parameters. There are also some funky parameter patterns that allow for easy searching from HTML forms, in the format: filter_[0-9]_(and|or)_(equal|like|likeleft|likeright|lt|gt)_attributename
This is a special "endpoint" that allows a smart client to determine the data schema for the XML representations of the feature.
Now, providing read-only representations of these features is pretty cool on its own, and that is all that the City of Nanaimo is prepared to do at this point. However, the extension can be configured to allow full RESTful data access: GET, POST, PUT, DELETE. Combined with a yet-to-be-released FDO REST provider, users of applications that implement FDO (such as AutoCAD Map 3D, Safe Software‘s FME, 1Spatial‘s MapRelate and Radius Studio, and MapGuide) will be able to read, write, update, and delete data from this extension the same way as they would from local data stores. I was experimenting with this against an internal server using Map 3D, and it was pretty cool to be able to edit data directly from a web site.
Applications that implement GeoJSON, such as Safe Software’s FME can also take advantage of this format to read and (untested) write to the exposed data.
The GeoJSON representation has a considerable upside for light-weight mobile data editing, for instance in an OpenLayers application running inside Google Chrome (or another Gears-enabled browser) and for minimal-packet data access from mobile phone applications.
All of these are really cool applications from a geospatial professional standpoint, but they don’t really address the primary goal of the original requirement: enabling easier access to spatial information by residents. That’s OK though, just by making these representations available and well-linked, the search engines will pick them up and do this part of the work for me.
This site has been active for less than two weeks, and Google is already ranking some of the property reports first in the results for generic searches within British Columbia and specific searches elsewhere. For instance, when I search from home for "881 Hunter St" (one of the properties Google has indexed) it comes up as number 1. When Haris searches from Slovenia, that isn’t the case, but if he searches for "881 Hunter St, Nanaimo, BC" then it does. Most municipalities have high authority for their location name, and this is a great way of taking advantage of that authority to provide a higher level of service to our residents.
The current implementation has a few issues. Unfortunately these will require a substantial refactoring to resolve, so we’re looking at another month or so before we have a public-ready build of the code. Some of these problems are as follows:
- HTTP status codes are often not correct. For instance, a search that returns a single feature should redirect to that representation rather than displaying the single feature under the search representation.
- Fine control over methods is required, such as enabling/disabling specific methods, requiring SSL, requiring certain group access, etc.
- Existing configuration system grew in odd ways as the code was modified, and needs to be de-Frankenstein-ed
- More control over URI patterns needs to be extended to users, for instance to allow the creation of -edit representations that return pre-populated HTML forms.
- Need revision numbering or data checksum to reduce chance of overlapping writes.
- Need parameter/http header overrides for method (to deal with firewalls) and format (to allow selection from HTML forms)
- Other miscellaneous issues.
Based on feedback, Haris has enabled JSONP for the .json representations. Just add the argument _callback to the URI, with the name of your desired function as the value. e.g.: http://maps.nanaimo.ca/data/property/.json?filter_1_and_equal_street=ROSSTOWN+ROAD&_callback=rosstown
Call for Feedback
If you have a chance to look at the current implementation and see any areas where it could be improved, we’re really interested in making changes required to meet REST best practices. We’ve been trying to pay attention to current guidance, but without a real implementation it has been hard to truly understand what is needed.