1

I have downloaded the KML file of 'Sentinel 1 Acquisition Segments' from this url. I have written this code to read KML file into GeoDataFrame, but the code returns empty GeoDataFrame.

>>>import fiona
>>>import geopandas as gpd
>>> gpd.__version__
'0.8.1'
>>> fiona.__version__
'1.8.17'
>>>gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
>>>fp = 'Sentinel-1A_MP_20201006T160000_20201026T180000.kml'
>>>gdf = gpd.read_file(fp, driver='KML')
>>>gdf
Empty GeoDataFrame
Columns: [Name, Description, geometry]
Index: []

Is there any code that I missed, or should I have to manipulate the KML file before?

3
  • @BERA, is the path too long or contain an invalid character? Fyi, I used the relative path.
    – Suhendra
    Oct 11, 2020 at 0:09
  • Its not a valid path to the file. For example r"C:\somefolder\Sentinel-1A_MP_20201006T160000_20201026T180000.kml" could be valid. Python does not know where the file is
    – BERA
    Oct 11, 2020 at 9:22
  • I have done on that way, but it returned same result (empty). I assume that the KML contains multiple folders, and I have done by using fiona listlayers method by the following answer gis.stackexchange.com/a/328554/133557, but it returned empty as well.
    – Suhendra
    Oct 12, 2020 at 0:30

1 Answer 1

2

Finally, I fixed the issue inspired by the following answer https://gis.stackexchange.com/a/328554/133557, I changed the driver to 'LIBKML', so the final code as following:

import fiona
import pandas as pd
import geopandas as gpd

gpd.io.file.fiona.drvsupport.supported_drivers['LIBKML'] = 'rw'

fp = 'Sentinel-1A_MP_20201006T160000_20201026T180000.kml'

gdf_list = []
for layer in fiona.listlayers(fp):
    if 'S1' in layer:
        gdf = gpd.read_file(fp, driver='LIBKML', layer=layer)
        gdf_list.append(gdf)

gdf = gpd.GeoDataFrame(pd.concat(gdf_list, ignore_index=True))

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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