0

I want to use ogr2ogr command line to convert KML files to shapefile file, however, I can't get correct shapefile when I type the ogr2ogr convert command.

However, I can succeed in converting the continent.shp to correct KML file inside ArcGIS software by means of ogr2ogr. Besides, the conversion between acquired KML file in last step to shapefile.

I guess maybe my KML file is not the strict standard format. So I paste the KML file contents.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:gml="http://www.opengis.net/gml" 
  xmlns:xfdu="urn:ccsds:schema:xfdu:1" 
  xmlns:safe="http://www.esa.int/safe/sentinel-1.0" 
  xmlns:s1="http://www.esa.int/safe/sentinel-1.0/sentinel-1" 
  xmlns:s1sar="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar" 
  xmlns:s1sarl1="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" 
  xmlns:s1sarl2="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-2" 
  xmlns:gx="http://www.google.com/kml/ext/2.2">
  <Document>
    <name>Sentinel-1 Map Overlay</name>
    <Folder>
      <name>Sentinel-1 Scene Overlay</name>
        <GroundOverlay>
          <name>Sentinel-1 Image Overlay</name>
          <Icon>
            <href>quick-look.png</href>
          </Icon>
          <gx:LatLonQuad>
            <coordinates>-113.892487,68.977577 -124.235062,69.902451 -122.225281,73.452110 -109.974060,72.393707</coordinates>
          </gx:LatLonQuad>
       </GroundOverlay>
    </Folder>
  </Document>
</kml>

I don't know the reason to the conversion problems. Could you give me some advice?

  • What you have is probably a KML SuperOverlay developers.google.com/kml/documentation/…. That is actually raster data that is georeferenced with a little KML file. I do not believe that GDAL can convert the KML part of a SuperOverlay into shapefile as it can do with KML that contains vectors. – user30184 Sep 28 '17 at 5:23
  • Thanks for your reply.However,I can achieve the conversion in ArcGIS Destop. – Falcon_Baikal Sep 28 '17 at 9:13
  • Sorry, KML SuperOverlay is actually a normal KML vector file and GDAL can find the geometry (polygon that represents the footprint of the image or "Icon") from the KML but it needs some fiddling. See my answer. – user30184 Sep 28 '17 at 12:00
  • How about just taking out the image file (quick-look.png) and give it coordinates as GCPs? For instance there is another nice answer by @user30184 jpg to geotiff transformation with gdal_translate and gcps fails. – Kazuhito Sep 28 '17 at 12:40
  • Eh, it's doesn't matter. – Falcon_Baikal Sep 28 '17 at 13:13
3

Conversion fails because GDAL is trying to read the data as GML instead of KML. You can see that this happens by running your command with GDAL debug flag.

ogr2ogr -f "ESRI Shapefile" overlay.shp overlay.kml --debug on
...
GDAL: GDALOpen(overlay.kml, this=0000000002A479F0) succeeds as GML.

KML is XML as well as GML and now GDAL selects for some reason wrong driver for this data. Conversion succeeds if it is run with the GDAL_SKIP configuration option https://trac.osgeo.org/gdal/wiki/ConfigOptions

ogr2ogr -f "ESRI Shapefile" overlay.shp overlay.kml --config GDAL_SKIP GML --debug on
...
GDAL: AutoSkipDriver(GML)
GDAL: GDALOpen(overlay.kml, this=0000000002420F10) succeeds as LIBKML.
GDAL: GDALDriver::Create(ESRI Shapefile,overlay.shp,0,0,0,Unknown,0000000000000000)
Shape: DBF Codepage = LDID/87 for overlay.shp
Shape: Treating as encoding 'ISO-8859-1'.
Warning 6: Normalized/laundered field name: 'description' to 'descriptio'
Warning 6: Field timestamp create as date field, though DateTime requested.
Warning 6: Field begin create as date field, though DateTime requested.
Warning 6: Field end create as date field, though DateTime requested.
Warning 6: Normalized/laundered field name: 'altitudeMode' to 'altitudeMo'
GDALVectorTranslate: 1 features written in layer 'overlay'
GDAL: GDALClose(overlay.kml, this=0000000002420F10)
GDAL: GDALClose(overlay.shp, this=0000000000420CF0)

What is odd is that ogrinfo opens the data correctly as KML without a need to skip the GML driver.

The shapefile contains the footprint of the image and a link to image file. There is really nothing more in the KML file. If ArcGIS finds something more, please tell what.

enter image description here

  • Thanks for your advice,I have tried as you said.However, this method is not correct although I run with the GDAL_SKIP configuration option. – Falcon_Baikal Sep 28 '17 at 9:53
  • So what goes wrong? It does work for me. – user30184 Sep 28 '17 at 9:57
  • The run process is normal as you displayed.However,the destination file is wrong. – Falcon_Baikal Sep 28 '17 at 11:49
  • user30184 think my KML may be SuperOverlay, however, I don't know the difference between them. – Falcon_Baikal Sep 28 '17 at 11:51
  • 2
    @Falcon_Baikal As your OP was asking for the method to convert your KML to Shapefile by ogr2ogr, I believe this is the correct answer. I suspect the reason you think it failure is because you wanted to see sentinel image on top of it. – Kazuhito Sep 28 '17 at 13:51

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.