[mapguide-users] GetFeaturesKml and GetLayerKml

Rodolfo Moreno rmoreno at voxiva.com
Tue Feb 24 19:01:39 EST 2009


Hi alucas,
did you get use the GetLayerKml for generating KML. I have not had succesful
with it.

This is my code:

String s_basePath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
        MapGuideApi.MgInitializeWebTier(s_basePath + "../webconfig.ini");

        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(new MgUserInformation("Administrator",
"admin"));

        MgKmlService kmlService =
(MgKmlService)siteConnection.CreateService(MgServiceType.KmlService);
        MgResourceService resService =
(MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featService =
(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

        MgLayer layer = new MgLayer(new
MgResourceIdentifier("Library://xxx.FeatureSource"), resService);
        MgSpatialContextReader contexts1 =
featService.GetSpatialContexts(new
MgResourceIdentifier("Library:xxx.FeatureSource"), true);
        contexts1.ReadNext();
        MgByteReader byteReader = contexts1.GetExtent();

        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        MgGeometry geometry = agfReaderWriter.Read(byteReader);
        MgEnvelope env = geometry.Envelope();

        String mapagentURI =
"http://localhost/mapguide/mapagent/mapagent.fcgi";

        MgByteReader byteReader1 = kmlService.GetLayerKml(layer, env, 796,
717, 96, 0, mapagentURI, MgMimeType.Xml);

        XmlDocument doc = new XmlDocument(); 
        doc.LoadXml(byteReader1.ToString()); // The error is raised in this
line

        Response.ContentType = "application/vnd.google-earth.kml+xml";
        Response.Write( doc );

The error is raised in the line: 
  doc.LoadXml(byteReader1.ToString());
  ERROR: Invalid mime type: application/vnd.google-earth.kml+xml

any help will be very appreciated, thanks
 


alucas-3 wrote:
> 
> Hi Jason,
> 
> It seems that with the GetFeaturesKML() method there is no dependency from
> the server session. If I generate the .kml with this method the file size
> is in my example about 4 MB. So, it seems that the features are in the kml
> and not connected vía mapagent and session.
> 
> If you want some sample code I can send you how it works.
> 
> Regards,
> 
> JasonBirch wrote:
>> 
>> Hi,
>> 
>> Absolutely you can, it's just that the original RFC intended these as
>> interactive APIs created from the initial GetMapKML rather than
>> individual layer/feature access APIs.  I don't think there's any problem
>> with it, but haven't seen a lot of experimentation either...
>> 
>> That would be the approach that I'd take as well if I was going to try
>> using the build-in functions; DMSG wrote something similar to that for
>> me that basically reads an existing layer definition, uses a bit of DOM
>> manipulation to swap out the filter element's text, and uses the
>> modified layerdefinition in a new map.  GetLayerKML should allow a
>> similar strategy; please let us know how you make out.
>> 
>> Good luck!
>> 
>> Jason
>> 
>> -----Original Message-----
>> From: mapguide-users-bounces at lists.osgeo.org
>> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of alucas
>> Sent: Thursday, November 13, 2008 00:23
>> To: mapguide-users at lists.osgeo.org
>> Subject: RE: [mapguide-users] GetFeaturesKml and GetLayerKml
>> 
>> 
>> Hi Jason,
>> 
>> Actually, I can use this operations calling directly the agent as well
>> from
>> the web extensions API (i.e Java) from the MgKmlService. For my current
>> project, I need to publish one entire layer and some features from this
>> layer. For now, publish the layer via MgKmlService::GetLayerKml(...)
>> works
>> fine. Otherwise, GetFeaturesKml(...) does not work for me or it does the
>> same that GetLayerKml.
>> 
>> So, my next step is create a filter for the layer and then call
>> GetLayerKml
>> in order to see if it only export the filtered features.
>> 
>> P.D: Sorry for my english.
>> 
>> Thanks.
>> 
>> 
>> JasonBirch wrote:
>>> 
>>> These functions aren't actually supposed to be called directly be the
>>> user.
>>> 
>>> http://trac.osgeo.org/mapguide/wiki/MapGuideRfc4
>>> 
>>> There are quite a few other limitations here, such as being
>>> session-based (if the user saves in Google Earth, it'll break when the
>>> session expires), etc.
>>> 
>>> I'd personally recommend hand-coding the KML that you emit.  There is
>> a
>>> sample app here with source included that shows how to do this:
>>> 
>>> http://data.mapguide.com/mapguide/DynamicKml/GoogleEarth.php
>>> 
>>> Jason
>>> 
>>> -----Original Message-----
>>> From: alucas
>>> Subject: [mapguide-users] GetFeaturesKml and GetLayerKml
>>> 
>>> What is the diference between these methods? How can I get only some
>>> features from my layer and then export to kml? I suposed that with
>>> GetFeaturesKml I was able to filter features in a layer...
>>> _______________________________________________
>>> mapguide-users mailing list
>>> mapguide-users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/GetFeaturesKml-and-GetLayerKml-tp20459874p20476499
>> .html
>> Sent from the MapGuide Users mailing list archive at Nabble.com.
>> 
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>> 
>> 
> 
> 


-----
Rodolfo Moreno
CivilEng

-- 
View this message in context: http://n2.nabble.com/GetFeaturesKml-and-GetLayerKml-tp1818790p2381181.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list