init
This commit is contained in:
parent
0ddb7631b1
commit
98a3a545e0
38
5_GEONATURE/EXPORT/get_zh_fromapi.py
Normal file
38
5_GEONATURE/EXPORT/get_zh_fromapi.py
Normal file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import geopandas as gpd
|
||||
import requests
|
||||
from os import path
|
||||
import io
|
||||
|
||||
def get_zh(geom=None):
|
||||
url = 'https://geonature.cen-isere.fr/geonature/api/exports/api/9?limit=30000&{geo}'
|
||||
if not geom.empty :
|
||||
if geom.crs.srs.lower() != 'epsg:4326':
|
||||
geom.to_crs(4326,inplace=True)
|
||||
if gpd.__version__ >='1.0.0':
|
||||
geometry = 'geometry={geom}'.format(geom=geom.union_all().wkt)
|
||||
else:
|
||||
geometry = 'geometry={geom}'.format(geom=geom.unary_union.wkt)
|
||||
else:
|
||||
geom = ''
|
||||
r = requests.get(url.format(geo=geometry))
|
||||
if r.status_code == 200:
|
||||
d = r.json()
|
||||
data = d['items']['features']
|
||||
p = [i['properties'] for i in data]
|
||||
g = [i['geometry'] for i in data]
|
||||
df = gpd.GeoDataFrame.from_features(data,crs=4326)
|
||||
|
||||
return df
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
PATH = '/media/colas/Disk2/tmp/GEONATURE/ST MARTIN URIAGE'
|
||||
FILE = 'ZH ENS POUR CEN 14102025.gpkg'
|
||||
f = gpd.read_file(path.join(PATH,FILE))
|
||||
df = get_zh(f)
|
||||
# df[df.dtypes==object] = df[df.dtypes==object].astype(str)
|
||||
df.to_file(path.join(PATH,'inventaire_zoneshumides_seglieres.gpkg'))
|
||||
# df.to_file(path.join(PATH,'inventaire_zoneshumides_seglieres.geojson'))
|
||||
Loading…
x
Reference in New Issue
Block a user