Python_scripts/3_AZALEE/tmp/manip_invPS_platière.py

65 lines
1.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import pandas as pd
import geopandas as gpd
import pycen
path0 = '/home/colas/Documents/9_PROJETS/2_PS/TO IMPORT/'
path = 'cartohabitatsplatiere/'
file = 'Habitats I33 2008.gpkg'
df = gpd.read_file(path0+path+file)
df.rename_geometry('geom', inplace=True)
if file == 'Habitats I33 2008.gpkg' :
df.columns = df.columns.str.lower()
df.rename(columns={'date_maj':'date'}, inplace=True)
df['remarques'] = \
'détails : ' + df['type_détaillé'] + ';' +\
' regroupement : ' + df['type_regroupé'] + ';'\
' code_n2000 : ' + df['code_n2000'] + ';'\
' age : ' + df['age'] + ';'
del df['id']
del df['code_enjeu']
del df['enjeu_numérique']
del df['complexe_hab']
del df['echelle']
del df['entretien']
del df['type_détaillé']
del df['type_regroupé']
del df['surface']
del df['num_site']
del df['code_n2000']
del df['age']
# df.set_index('num_site',inplace=True)
df['auteur'] = 'PONT Bernard'
df['structure'] = "AAIP"
lst_hab = ['34.1','34.3','34.4','34.7','35.2','62.3','64.1']
df = df[df.code_cb.str.contains('|'.join(lst_hab))]
lst_hab2 = ['41','42','43','44','81','82','83']
df = df[~df.code_cb.str.contains('|'.join(lst_hab2))]
df.replace({'IC':'Communautaire'}, inplace=True)
df.index.name = 'ident'
df.reset_index(inplace=True, drop=False)
df.rename(columns={'code_cb':'code_hab1'}, inplace=True)
df['n_hab1'] = 100
ps = pycen.ps.get_sitesGeom()
# nv = gpd.read_file(path0+'PS_nature_vivante_2014.shp')
# nv.geometry = nv.buffer(50)
intersect = gpd.sjoin(df,ps,op='intersects')['ident'].tolist()
drop_index = df[df['ident'].isin(intersect)].index
df.drop(drop_index,inplace=True)
df.reset_index(inplace=True, drop=True)
# df.to_file(path0+path+'Habitats I33 2008 (manquants).gpkg', driver='GPKG')
# df = gpd.read_file(path0+path+'Habitats I33 2008 (manquants).gpkg')