Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a C# mechanism for Loading shapefiles into PostreSQL/PostGIS now I would like to dynamically load it on Mapguide fusion template.In either C# or VB.NET code behind.

Use case is: 1.use uploads a zip folder with shapefile 2. .NET code behind checks for certain attributes then uploads it to PostgreSQL/PostGIS Database 3. upon successful upload, display the layer into Mapguide Fusion template 4.Overlay it over base layers

share|improve this question
up vote 2 down vote accepted

Not sure how familiar you are with the MapGuide Web API, but that's what you'll have to use to achieve this.

Basically, you'll have to dynamically generate a Layer Definition XML. You can see the XML of your existing layers for a reference or even load a generic one and modify the source of the data to the newly loaded data that the user uploaded... here's an example (PHP):

  // some initialization
  $user = new MgUserInformation([SESSION_ID]);
  $site = new MgSiteConnection();

  // get the services
  $res = $site->CreateService(MgServiceType::ResourceService);

  // get the map object
  $map = new MgMap($site);

  // get the XML content of a generic layer, returns MgByteReader
  $layer_definition = $res->GetResourceContent(new MgResourceIdentifier('Library://Layers/generic.LayerDefinition'));
  $dom = new DOMDocument();

  // Modify where the data source is
  $node = $dom->getElementsByTagName('FeatureName')->item(0);
  $node->nodeValue = "schema.new_shp_table";
  $new_def = $dom->saveXML();

  // create and save the new layer to the current session only
  $bs = new MgByteSource($new_def, strlen($new_def));
  $new_resource_id = new MgResourceIdentifier("Session:[SESSION_ID]//new_shp_layer.LayerDefinition");
  $res->SetResource($new_resource_id, $bs->GetReader(), null);

  $new_layer = new MgLayer($new_resource_id, $res);
  $new_layer->SetLegendLabel('New Uploaded Data');

  $layers->Insert(1, $new_layer);


Where [MAPNAME] and [SESSION_ID] are passed into the script. This is all assuming you want the new data to be only available to the current session map. Otherwise you'll have to be able to SAVE the new layer into the MapDefinition on the server.

Hope this helps!

share|improve this answer
Thank you. Even though the requirements are .NET fortunately I know PHP.It would be great if this example was in C# or VB.NET. I will have to find the equivalence or hopefully someone else can offer .NET suggestions. – user15083 Feb 12 '13 at 18:15
The MapGuide API is the exact same for PHP and .NET. if you know both languages, you'll be able to translate :) – janechii Feb 12 '13 at 23:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.