question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import Simple Data from KML Files

See original GitHub issue

Hello, this is maybe also a question related to fiona but I will start here. I have a KML file (formerly a shape file with attribute columns) and want to load this KML with GeoPandas. So far so good, however, when returning the geodataframe, the attribute columns that are marked as “Simple Data” in the KML file are missing. Below, I posted a snipped of the KML file, how I load it and what the gdf looks like and what I want it to look like. The KML contains one folder. A google search was not sucessful until now.

Thanks for the help!

KML file:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="interfaces1" id="interfaces1">
	<SimpleField name="id" type="float"></SimpleField>
	<SimpleField name="formation" type="string"></SimpleField>
</Schema>
<Folder><name>interfaces1</name>
  <Placemark>
	<ExtendedData><SchemaData schemaUrl="#interfaces1">
		<SimpleData name="formation">Ton</SimpleData>
	</SchemaData></ExtendedData>
      <Point><coordinates>19.1501280458077,293.313485355882</coordinates></Point>
  </Placemark>
..........
</Folder>
</Document></kml>
import fiona
import geopandas as gpd

gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
# empty GeoDataFrame
gdf = gpd.GeoDataFrame()

# iterate over layers
for layer in fiona.listlayers('../../gemgis/data/Test1/KML/interfaces1.kml'):
    s = gpd.read_file(
        '../../gemgis/data/Test1/KML/interfaces1.kml', driver='KML', layer=layer)
    gdf = gdf.append(s, ignore_index=True)

gdf.head()

What I get:

image

What I want:

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
andhuang-CLGXcommented, Aug 20, 2021

As a workaround, I was able to do this to extract simpledata tags

import fiona
fiona.drvsupport.supported_drivers['LIBKML'] = 'rw'

with fiona.open(file_path) as collection:
    gdf = gpd.GeoDataFrame.from_features(collection)
0reactions
and-viceversacommented, Aug 10, 2022

@andhuang-CLGX solution worked for me on a simple single layer point .kml

It also works on @AlexanderJuestel kml snippet showing “formation” as an attribute field.

                 geometry  Name description  ...  icon    id formation
0  POINT (19.150 293.313)  None        None  ...  None  None       Ton

Not to say this is a solved issue, but some version of the base case lets you get by. Maybe the multi layer kml is the sticking point as others have mentioned.

EDIT: Note that my KML was also written from geopandas.

System info below (conda installed yesterday)

SYSTEM INFO
-----------
python     : 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:03:09) [Clang 13.0.1 ]
executable : /usr/local/anaconda3/envs/nssda/bin/python
machine    : macOS-12.5-x86_64-i386-64bit

GEOS, GDAL, PROJ INFO
---------------------
GEOS       : 3.11.0
GEOS lib   : /usr/local/anaconda3/envs/nssda/lib/libgeos_c.dylib
GDAL       : 3.5.1
GDAL data dir: /usr/local/anaconda3/envs/nssda/share/gdal
PROJ       : 9.0.1
PROJ data dir: /usr/local/anaconda3/envs/nssda/share/proj

PYTHON DEPENDENCIES
-------------------
geopandas  : 0.11.1
numpy      : 1.23.1
pandas     : 1.4.3
pyproj     : 3.3.1
shapely    : 1.8.2
fiona      : 1.8.21
geoalchemy2: None
geopy      : None
matplotlib : 3.5.2
mapclassify: 2.4.3
pygeos     : None
pyogrio    : None
psycopg2   : None
pyarrow    : None
rtree      : 1.0.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Import KML map data into Google Earth - Android
Import KML map data into Google Earth · On your Android phone or tablet, open the Google Earth app Google Earth . ·...
Read more >
KML Tutorial | Keyhole Markup Language - Google Developers
KML is a file format used to display geographic data in an Earth browser such as Google Earth. KML uses a tag-based structure...
Read more >
Import your KML map data into Google Earth Web - YouTube
In this video, we will see, How to Import your KML map data into Google Earth Web. Google Earth is a GIS Application...
Read more >
Importing KMZ and KML Files for Property Research - YouTube
As you can see - this subscription database imports data to Google Earth from thousands of counties across the U.S. Most notably, ...
Read more >
KML files, import and export them with DeltaTracking tools and ...
Import your KML files into DeltaTracking in a simple way, you will not lose your data when changing software ... DeltaTracking allows the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found