<div dir="ltr"><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Hi,<br><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">I've been meaning to submit a patch for awhile to libkml driver but have not had time to do so.<br><br>The fix is a one line change highlighted below:<br><br><br>int OGRLIBKMLDataSource::OpenKml (<br> const char *pszFilename,<br> int bUpdate )<br>{<br> std::string oKmlKml;<br> char szBuffer[1024+1];<br><br> VSILFILE* fp = VSIFOpenL(pszFilename, "rb");<br> if (fp == NULL)<br> {<br> CPLError ( CE_Failure, CPLE_OpenFailed,<br> "Cannot open %s", pszFilename );<br> return FALSE;<br> }<br> int nRead;<br> while ((nRead = VSIFReadL(szBuffer, 1, 1024, fp)) != 0)<br> {<br> try<br> {<br> oKmlKml.append(szBuffer, nRead);<br> }<br> catch(std::bad_alloc& e)<br> {<br> VSIFCloseL(fp);<br> return FALSE;<br> }<br> }<br> OGRLIBKMLPreProcessInput(oKmlKml);<br> VSIFCloseL(fp);<br><br> CPLLocaleC oLocaleForcer;<br><br> /***** create a SRS *****/<br><br> OGRSpatialReference *poOgrSRS =<br> new OGRSpatialReference ( OGRLIBKMLSRSWKT );<br><br> /***** parse the kml into the DOM *****/<br><br> std::string oKmlErrors;<br><br> ElementPtr poKmlRoot = kmldom::Parse ( oKmlKml, &oKmlErrors );<br><br> if ( !poKmlRoot ) {<br> CPLError ( CE_Failure, CPLE_OpenFailed,<br> "ERROR Parseing kml %s :%s",<br> pszFilename, oKmlErrors.c_str ( ) );<br> delete poOgrSRS;<br><br> return FALSE;<br> }<br><br> /***** get the container from root *****/<br><br> if ( !( m_poKmlDSContainer = GetContainerFromRoot ( m_poKmlFactory, poKmlRoot ) ) ) {<br> CPLError ( CE_Failure, CPLE_OpenFailed,<br> "ERROR Parseing kml %s :%s %s",<br> pszFilename, "This file does not fit the OGR model,",<br> "there is no container element at the root." );<br> delete poOgrSRS;<br><br> return FALSE;<br> }<br><br> m_isKml = TRUE;<br><br> /***** get the styles *****/<br><br> ParseStyles ( AsDocument ( m_poKmlDSContainer ), &m_poStyleTable );<br><br> /***** parse for layers *****/<br><br> int nPlacemarks = ParseLayers ( m_poKmlDSContainer, poOgrSRS );<br><br> /***** if there is placemarks in the root its a layer *****/<br><br><b> if ( nPlacemarks ) {</b> // <------------------------------------------------------------------------------------------This line<br> AddLayer ( CPLGetBasename ( pszFilename ),<br> poOgrSRS, wkbUnknown,<br> this, poKmlRoot, m_poKmlDSContainer, pszFilename, FALSE, bUpdate, 1 );<br> }<br><br> delete poOgrSRS;<br><br> return TRUE;<br>}<br><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Regards<br></div>Damian</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 February 2016 at 17:00, Jan Vaillant <span dir="ltr"><<a href="mailto:jvail@gmx.de" target="_blank">jvail@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 02/24/2016 12:53 AM, Even Rouault wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le mardi 23 février 2016 14:50:35, jan vaillant a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi list,<br>
<br>
I am reading a zipped kml with gdal's libkml driver. I am trying to access<br>
the name tag of the document:<br>
<br>
<kml><br>
<Document><br>
<name>a_name</name><br>
</blockquote>
<br>
I did a quick testing It appears that the driver will report a <name> as the<br>
layer name only if it inside a <Folder> tag, but not as a direct child of<br>
<Document><br>
</blockquote>
<br></span>
Yes, thank you. I tried the kml driver as well and it stores the Document/name and makes it available with layer.getName().<br>
<br>
Bye<div class="HOEnZb"><div class="h5"><br>
Jan<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a></div></div></blockquote></div><br></div>