MapGuide Open Source Package Utilities

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)

.

Related posts

3 Responses to “MapGuide Open Source Package Utilities”

  1. 1Paul Spencer on Apr 9, 2006 at 6:54 pm:

    A chicken? Jason, this is awesome. Thanks for sharing this. This is justification for Autodesk going open source with this technology and I hope that others will follow suit and get dug into the code, create great tools and share them.

  2. 2david on Jul 24, 2007 at 3:54 pm:

    Hi Jason,

    I just downloaded and installed mapguide 1.20rc2 and got the Sheboygan.mgp
    example working. The tile-server feature is what prompted my efforts and
    I am pleased to get it working.

    Are there other sample/example (contributor?) ‘*.mpg’ packages available?
    I am interested in a full globe lat-lon grid, continenet/ocean/river/lakes
    and geopolitcal boundaries and place names — but I don’t really need
    streets or highways, etc. If no such ‘*.mpg’ is available, how do I
    create it?

    I just need a tiled wms that allows be to overlay the above with
    satellite images. Thanks in advance for any feedback.

    Ceers,

    –david

  3. 3Jason Birch on Jul 24, 2007 at 11:47 pm:

    Hi David,

    I don’t provide tech support via my blog. This question would receive better response in the MapGuide Users mailing list.