Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

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();
  $site->Open($user);

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

  // get the map object
  $map = new MgMap($site);
  $map->Open([MAPNAME]);

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

  // 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));
  $bs->SetMimeType(MgMimeType::Xml);
  $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->SetName('new_shp_data');
  $new_layer->SetVisible(true);
  $new_layer->SetSelectable(true);
  $new_layer->SetLegendLabel('New Uploaded Data');
  $new_layer->SetDisplayInLegend(true);
  $new_layer->SetGroup(NULL);

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

  $map->Save($res);

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
1  
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
add comment

Your Answer

 
discard

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.