OSGeo BC Meet-Up July 27 (during GeoWeb)

Martin recently announced that we will be holding an OSGeo British Columbia meet-up in Vancouver on July 27. We have timed this to coincide with GeoWeb; it falls on the Tuesday evening after the workshops are over and before the conference sessions start.

This session is open to all, so if you’re going to be at GeoWeb, or are in the area and want to hang out and eat pizza with some Cool GeoGeeks (oxymoron?) RSVP on the wiki!

We’re also looking for some presentation ideas; if you’ve got a burning desire, then please propose a topic on the wiki.

-J

MapGuide 2.1 Beta 1

Late last night, Tom announced the release of the first MapGuide 2.1 Beta.

Jackie Ng has a better description of this than I could write.

Apart from the improved scalability and stability of this release, I’m most excited about the WiX-based open source MSI installer that I got to work on alongside Jackie and Kenneth. Huge learning curve, but not having to count on Autodesk resources to build new installers should allow us to push new releases as needed. It also means that someone who understands the installer can easily create custom deployments for internal use.

Anyway, please give this beta a try. If you notice anything it’s not doing right, please let us know.

-J

Now we’re cooking! MgCooker for MapGuide Tile Seeding

The latest preview release of MapGuide Maestro (r3620 currently) comes with a nice little surprise:  a tool for pre-seeding tile caches.  MgCooker can be run from the command line (more on this later), or through the Maestro GUI.  It couldn’t be simpler.  Open up a Map Definition that has a Base Layer Group, highlight the group that you want to cook, and click on the MgCooker icon:

image

In the following dialog, either leave the default of all checked, or choose to only pre-render certain zoom levels of your data, the choice is yours (probably best to start with the smallest scale – in this case 100,000):

image

Then click "Build tiles now" and sit back and watch the tiles cook:

image

Of course, this isn’t practical for a production environment where you would want to batch this operation.  That’s where the second option comes in; clicking on "Save as script" generates a Windows batch file similar to the following that you can script to your heart’s desire:

"C:Program FilesOSGeoMapGuide MaestroMgCookerCommandline.exe" batch 
   --mapdefinitions="Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition"
   --basegroups="Base Layer Group" 
   --scaleindex=7 
   --mapagent="http://localhost:8008/mapguide/mapagent/mapagent.fcgi"

I have no idea if the MgCookerCommandLine.exe works under Mono, but given that the rest of Maestro seems to work fairly well there I would not be surprised.

Great job Kenneth; this is something we have been sorely missing since MapGuide 1.2, and it’s great to see it as part of Maestro!

-J

MapGuide REST Extension. Feedback wanted!

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 URIhttp://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 Resourceshttp://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.

OpenSearch link:

<link 
  rel="search" 
  type="application/opensearchdescription+xml" 
  title="Properties by Street" 
  href="/data/property/search_by_street.xml"
>

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 Representationhttp://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:

<link 
  rel="alternate" 
  type="application/vnd.google-earth.kml+xml" 
  title="KML representation of 2143 AARON WAY" 
  href="http://maps.nanaimo.ca/data/property/123170.kml" >
<link 
  rel="alternate" 
  type="application/json" 
  title="GeoJSON representation of 2143 AARON WAY" 
  href="http://maps.nanaimo.ca/data/property/123170.json" >
<link 
  rel="alternate" 
  type="text/xml" 
  title="XML representation of 2143 AARON WAY" 
  href="http://maps.nanaimo.ca/data/property/123170.xml" >

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.

<div class="adr">
  <span class="extended-address"></span>
  <span class="street-address">2143 AARON WAY</span>, 
  <span class="locality">NANAIMO</span>,
  <span class="region">BC</span>
  <span class="country-name" style="display:none;">CANADA</span>
</div>

<div class="geo">
  <span class="latitude">49.18882</span>, 
  <span class="longitude">-123.9785</span>
</div>

Example Property KML Representationhttp://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):

http://maps.nanaimo.ca/data/property/index.kml

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.

http://maps.nanaimo.ca/data/property/.html

http://maps.nanaimo.ca/data/property/.kmz

http://maps.nanaimo.ca/data/property/.json

http://maps.nanaimo.ca/data/property/.xml

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

http://maps.nanaimo.ca/data/property/.schema

This is a special "endpoint" that allows a smart client to determine the data schema for the XML representations of the feature.

Applications

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.

json001

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.

Weaknesses

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.

Updates

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.

Thanks!

-J

Changing selection colour in MapGuide AJAX viewer

One of the annoyances that people have faced with MapGuide Open Source is that the selection colour was hard-coded in one of the C++ rendering functions. There were a few ways of getting around this without recompiling, but they were all a lot of work. RFC 38 included some code changes that made it possible to modify this value on the fly, but it doesn’t look like this capability was taken advantage of by the AJAX viewer that was distributed with MGOS 2.0.x.

If you’re using MapGuide Open Source 2.0 (2.0.2 recommended) and are not happy with the default blue selection colour, you can easily change it on a per-install basis by modifying the mapviewerajax template file. This is located at:

(INSTALLDIR)\WebServerExtensions\www\viewerfiles\ajaxmappane.templ

You will need to find the function called RequestMapImage, which includes a line that looks like this:


url = webAgent +
"?OPERATION=GETDYNAMICMAPOVERLAYIMAGE&FORMAT=PNG&VERSION=1.0.0&SESSION="
+ sessionId + "&MAPNAME=" + encodeComponent(mapName)
+ "&SEQ=" + Math.random();

You will need to modify this to change the VERSION to 2.0.0, and add the BEHAVIOR and SELECTIONCOLOR parameters:


url = webAgent +
"?OPERATION=GETDYNAMICMAPOVERLAYIMAGE&FORMAT=PNG&VERSION=2.0.0&SESSION="
+ sessionId + "&MAPNAME=" + encodeComponent(mapName)
+ "&SEQ=" + Math.random() + "&BEHAVIOR=7&SELECTIONCOLOR=FF5300FF";

Before:

After:

The BEHAVIOR parameter is a bitmask that controls what is rendered, and is described in RFC 38. The SELECTIONCOLOR parameter is a hex string in RGBA format, or its integer equivalent. Note for geeks: the A (opacity) portion of the string is ignored; the server code masks this out of the passed value, and then adds 200 (C8) as the line opacity and 160 (A0) as the fill opacity.

Note, the mapagent call allows you the flexibility to add more complicated behaviour to your viewer, such as changing the selection colour dynamically based on the map name, but I’ll leave that as an exercise for the reader (mostly because I’m lazy and use Fusion anyway and wouldn’t benefit from the work).

-J