MapGuide Open Source uses a binary XML data structure to store its site configuration. This contains things such as data1, layer definitions, map definitions, web layouts, and just about everything else. The existing data management tools don’t provide an easy way to reference external data2, but the advantages far outweigh this disadvantage.
The recent 1.0.0 release of MapGuide comes with a great feature that allows you to import and export portions of this XML data store, including any referenced spatial data, into something called a “package”. A package is just a zipfile with an .mgp extension, which contains XML data and any referenced files.
The only problem with this feature is that it could only be accessed via the web-based site administrator. I wanted to use this ability to automate data transfers from my intranet site to my externally hosted internet site, and really didn’t want to be staying up until midnight each night. Fortunately, MapGuide Open Source is, well, open source. The site administration interface is written in PHP, and uses the same well-documented web API as the web maps.
Armed with a hammer (what else would you use to drive screws?) I attacked the site administration import/export code, and came up with a couple PHP utilities for importing and exporting packages from the command line using the php CLI.
cli_loadpackage.php
Usage: php cli_loadpackage.php AdministratorPassword PackageName.mgp
cli_makepackage.php {watch line wrap}
Usage: php cli_makepackage.php AdministratorPassword PackageName.mgp Library://FolderPath "Package Description"
You can download mgpackageutils.zip from my site, but only with the understanding that I accept no responsibility for your use of these tools. Even if you turn into a chicken. This archive contains the PHP utilities, a readme file, a copy of the LGPL license, and a couple DOS batchfiles for testing:
http://www.jasonbirch.com/files/mgpackageutils.zip
Next job? Create a utility to unzip the .mgp file, rsync the results to the external site, and zip it back up before importing on the other side. I’ll just file that at the bottom of my 10-page TODO list…
Footnotes:
1. Although the data itself could potentially be stored as a byte stream in the XML file, spatial data is typically stored within the Library repository on the server.
2. At some point I hope to be able to provide some tools to define external data sources, based on a conversation on the MapGuide Users List)
.