I am trying to read a .kml file (here is an example of the input):
<name>99</name>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMPARABLES_APPARTS">
<SimpleData name="tessellate">-1</SimpleData>
<SimpleData name="extrude">0</SimpleData>
<SimpleData name="visibility">-1</SimpleData>
<SimpleData name="Titref">T5610/71()</SimpleData>
<SimpleData name="Mappe">28-17-a-16</SimpleData>
<SimpleData name="Nature">T</SimpleData>
<SimpleData name="Carnet">31</SimpleData>
<SimpleData name="Bon">14</SimpleData>
<SimpleData name="DateCB">04-07-2018</SimpleData>
<SimpleData name="Archive">T</SimpleData>
<SimpleData name="NUM_TITRE">T/5610/71/</SimpleData>
<SimpleData name="Titre">T/18403/71/</SimpleData>
<SimpleData name="Montant">1344000.000000000000000</SimpleData>
<SimpleData name="Superficie">56</SimpleData>
<SimpleData name="Prix_unita">24000</SimpleData>
<SimpleData name="Formalité">بيع كلي</SimpleData>
<SimpleData name="Date_Acte">2019/02/12</SimpleData>
<SimpleData name="Type Acte">عقد موثق</SimpleData>
<SimpleData name="Consista_1">شقة</SimpleData>
<SimpleData name="Origine">T/5610/71/</SimpleData>
<SimpleData name="Adresse">البيضاء- حي راسين</SimpleData>
<SimpleData name="Pdite">نورماندي ايطا36/1</SimpleData>
</SchemaData></ExtendedData>
<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>-7.64047383421453,33.5879835701317 -7.64066743631093,33.5884293463282 -7.64012881378832,33.5885680296946 -7.64007947841229,33.5884516406187 -7.64008802819036,33.5884487806223 -7.64003671338741,33.5882972444107 -7.64007756187161,33.5882929019069 -7.64007969352916,33.5882919614817 -7.64018375142164,33.5882305516264 -7.64031826698891,33.5881379222242 -7.64023531103129,33.5880555158574 -7.6402575429815,33.5880397802828 -7.64047383421453,33.5879835701317</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
</Placemark>
I found a suggestion on StackOverflow which I believe only reads the first part of the KML
Here is the code and the output
import geopandas as gpd
gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
df = gpd.read_file(path_to_data+transac_file+'.kml', driver='KML')
the output is as follows:
Name Description geometry
0 93 MULTIPOLYGON (((-7.64047 33.58798, -7.64067 33...
1 99 MULTIPOLYGON (((-7.64047 33.58798, -7.64067 33...
2 81 MULTIPOLYGON (((-7.64047 33.58798, -7.64067 33...
3 87 MULTIPOLYGON (((-7.64047 33.58798, -7.64067 33...
4 9 MULTIPOLYGON (((-7.64047 33.58798, -7.64067 33..
df.columns
[134 rows x 3 columns]
Index(['Name', 'Description', 'geometry'], dtype='object')
I can see from the output that the features have not been read.
I tried another way as follows:
gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
fp=path_to_data+transac_file+'.kml'
gdf_list = []
for layer in fiona.listlayers(fp):
gdf = gpd.read_file(fp, driver='KML', layer=layer)
gdf_list.append(gdf)
gdf = gpd.GeoDataFrame(pd.concat(gdf_list, ignore_index=True))
But I am still getiing the same result as before.
How can I extract all features and put them into a dataframe?