1

I am new to QGIS and I am struggling to read in a KML file of polygons.

I have a KML file that contains polygon information for a number of squares formatted as follows:

<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Place@001@001@010</name>
<Polygon><outerBoundaryIs><LinearRing>
<coordinates>
25.271,-13.416
25.271,-13.415
25.272,-13.415
25.272,-13.416
25.271,-13.416
</coordinates>
</LinearRing></outerBoundaryIs></Polygon>
</Placemark>

<Placemark>
<name>Place@001@001@011</name>
<Polygon><outerBoundaryIs><LinearRing>
<coordinates>
25.371,-13.426
25.371,-13.425
25.372,-13.425
25.372,-13.426
25.371,-13.426
</coordinates>
</LinearRing></outerBoundaryIs></Polygon>
</Placemark>

<Placemark>
<name>Place@001@001@011</name>
<Polygon><outerBoundaryIs><LinearRing>
<coordinates>
25.391,-13.456
25.391,-13.455
25.392,-13.455
25.392,-13.456
25.391,-13.456
</coordinates>
</LinearRing></outerBoundaryIs></Polygon>
</Placemark>

</kml>

When I do: Layer -> Add Layer -> Add Vector Layer and choose my file, it does load into QGIS but only a single square is plotted. I imagine I am making an elementary mistake (likely in the format of the KML file), but I cannot find a reference to figure it out.

QGIS Version: 3.8 Zanzibar

  • Have you tried loading the KML into GoogleEarth? What happens? – Erik Jun 25 '19 at 11:21
  • 1
    Post a minimal full KML to reproduce this, your example just has one polygon. – bugmenot123 Jun 25 '19 at 11:32
  • One difference I noticed between your kml and the example on Wikipedia, is the one on Wikipedia has <document> tags nested inside the <kml> tags. – csk Jun 25 '19 at 15:40
1

Your example KML file is not valid. It's easy to test by opening the file in Google Earth Pro (or just copy the KML text and paste it into Earth)... this file indicates "invalid KML". As @csk indicated in their comment, it needs a Document or Folder tag. Any KML file with more than one feature in it (eg: more than one Placemark) must have all the features surrounded by a single container tag: either a Document or a Feature tag, like this:

<kml>
  <Document>
    <Placemark>
      ...
    </Placemark>
    <Placemark>
      ...
    </Placemark>
    <Placemark>
      ...
    </Placemark>
  </Document>
</kml>

Try adding that and let us know if it doesn't work.

For the full KML reference documentation, see: https://developers.google.com/kml/documentation/kmlreference

| improve this answer | |
  • Thanks for confirming my hunch. The trouble for a beginner learning KML, is that the full documentation you linked is so technical it's difficult for a beginner to understand. And the easy-to-understand tutorials only include one polygon in their examples. – csk Jun 25 '19 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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