Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
geopat
geopat
Commits
0b6de03d
Commit
0b6de03d
authored
Mar 15, 2019
by
Dumoulin Nicolas
Browse files
RPG patches joined with municipalities and exploitants
parent
6f21dbfd
Changes
2
Hide whitespace changes
Inline
Side-by-side
PATBuilder.py
View file @
0b6de03d
...
...
@@ -12,9 +12,9 @@ def load_MAJIC(majic_dir):
patches
.
append
(
gpd
.
GeoDataFrame
.
from_file
(
f
))
return
patches
def
build_initial_PAT
(
rpg_
filename
,
pat_municipalities
_dir
,
pat_
cultural_classes_filename
,
adminexpres
s_filename
,
bdv_filename
,
majic_dir
):
def
build_initial_PAT
(
rpg_
parcelles_filename
,
rpg_ilots_filename
,
pat_cultural_classes_filename
,
majic
_dir
,
pat_
municipalities_dir
,
bdv_filename
,
bdv_fixe
s_filename
,
adminexpress_com_filename
,
adminexpress_epci_filename
):
'''
This method build the initial patches set by consolidating the data sources
used by the project:
...
...
@@ -27,8 +27,32 @@ def build_initial_PAT(rpg_filename, pat_municipalities_dir,
Returns an object
'''
# TODO
pass
municipalities
=
build_PAT_municipalities
(
pat_municipalities_dir
,
bdv_filename
,
bdv_fixes_filename
,
adminexpress_com_filename
,
adminexpress_epci_filename
)
municipalities
=
gpd
.
GeoDataFrame
(
municipalities
[[
'INSEE_COM'
,
'CODE_EPCI'
,
'geometry'
,
'POPULATION'
,
'BV2012'
]])
rpg
=
gpd
.
GeoDataFrame
.
from_file
(
rpg_parcelles_filename
,
encoding
=
'utf-8'
)[[
'ID_PARCEL'
,
'CODE_CULTU'
,
'geometry'
]]
# we will use the centroid for doing the sjoin with municipalities
rpg
[
'patches'
]
=
rpg
.
geometry
rpg
.
geometry
=
rpg
.
geometry
.
centroid
patches
=
gpd
.
sjoin
(
rpg
,
municipalities
,
op
=
'intersects'
)
# 'op' is useless because sjoin between points and polygons
# sjoin with rpg_ilots for retrieving id of "exploitant"
rpg_ilots
=
gpd
.
GeoDataFrame
.
from_file
(
rpg_ilots_filename
,
encoding
=
'utf-8'
)[[
'id_ilot'
,
'id_expl'
,
'geometry'
]]
# restoring geometry instead of centroid
patches
.
geometry
=
patches
[
'patches'
]
del
patches
[
'patches'
]
del
patches
[
'index_right'
]
patches_expl
=
gpd
.
sjoin
(
patches
,
rpg_ilots
,
how
=
'left'
,
op
=
'intersects'
)
del
patches_expl
[
'index_right'
]
orphan_patches
=
patches_expl
[
patches_expl
[
'id_ilot'
].
isnull
()]
print
(
'{} patches without "id_expl" ({:.4f} % of total area)'
.
format
(
len
(
orphan_patches
),
orphan_patches
.
geometry
.
area
.
sum
()
/
patches_expl
.
geometry
.
area
.
sum
()
))
patches_expl
=
patches_expl
.
fillna
(
-
1
)
patches_expl
[
'id_ilot'
]
=
patches_expl
[
'id_ilot'
].
astype
(
int
)
patches_expl
[
'id_expl'
]
=
patches_expl
[
'id_expl'
].
astype
(
int
)
# TODO join with MAJIC
return
[
patches
,
rpg_ilots
,
patches_expl
]
def
build_PAT_municipalities
(
pat_municipalities_dir
,
bdv_filename
,
bdv_fixes_filename
,
adminexpress_com_filename
,
adminexpress_epci_filename
):
...
...
@@ -68,7 +92,11 @@ if __name__ == '__main__':
resources
=
{}
for
k
,
v
in
yaml
.
load
(
open
(
'resources/INDEX.yml'
,
'r'
)).
items
():
resources
[
v
[
'variable'
]]
=
'resources/'
+
v
[
'file'
]
if
'file'
in
v
else
k
municipalities
=
build_PAT_municipalities
(
resources
[
'pat_municipalities_dir'
],
patches
,
rpg_ilots
,
patches_expl
=
build_initial_PAT
(
resources
[
'rpg_parcelles_filename'
],
resources
[
'rpg_ilots_filename'
],
resources
[
'pat_cultural_classes_filename'
],
resources
[
'majic_filename'
],
resources
[
'pat_municipalities_dir'
],
resources
[
'bdv_filename'
],
resources
[
'bdv_fixes'
],
resources
[
'adminexpress_com_filename'
],
resources
[
'adminexpress_epci_filename'
])
patches_expl
.
to_file
(
'output/patches'
,
encoding
=
'utf-8'
)
gpd
.
GeoDataFrame
(
municipalities
).
to_file
(
'output/municipalities'
,
encoding
=
'utf-8'
)
resources/INDEX.yml
View file @
0b6de03d
...
...
@@ -29,8 +29,15 @@ ADMIN-EXPRESS-COG_1-1__SHP__FRA_2018-04-03-EPCI:
url
:
https://wxs-telechargement.ign.fr/x02uy2aiwjo9bm8ce5plwqmr/telechargement/prepackage/ADMINEXPRESS-COG-PACK_2018-05-04$ADMIN-EXPRESS-COG_1-1__SHP__FRA_2018-04-03/file/ADMIN-EXPRESS-COG_1-1__SHP__FRA_2018-04-03.7z
download-filename
:
ADMIN-EXPRESS-COG_1-1__SHP__FRA_2018-04-03.7z
RPG_2-0__SHP_LAMB93_R84-2016_2016-01-01
:
file
:
dl/RPG_2-0__SHP_LAMB93_R84-2016_2016-01-01/RPG/1_DONNEES_LIVRAISON_2016/RPG_2-0_SHP_LAMB93_R84-2016/PARCELLES_GRAPHIQUES.shp
variable
:
rpg_parcelles_filename
webpage
:
https://www.data.gouv.fr/fr/datasets/registre-parcellaire-graphique-rpg-contours-des-parcelles-et-ilots-culturaux-et-leur-groupe-de-cultures-majoritaire/
url
:
https://wxs-telechargement.ign.fr/0zf5kvnyfgyss0dk5dvvq9n7/telechargement/prepackage/RPG_REGION_PACK_DIFF_2016$RPG_2-0__SHP_LAMB93_R84-2016_2016-01-01/file/RPG_2-0__SHP_LAMB93_R84-2016_2016-01-01.7z
download-filename
:
RPG_2-0__SHP_LAMB93_R84-2016_2016-01-01.7z
l_ilot_anonyme_groupe_dominant_s_r84_2016.shp
:
variable
:
rpg_filename
variable
:
rpg_
ilots_
filename
file
:
private/0f2f3338-d845-45a9-a124-384032d70219_1549881773_7572/l_ilot_anonyme_groupe_dominant_s_r84_2016.shp
description
:
RPG with exploitants IDs
webpage
:
https://catalogue.datara.gouv.fr/geosource/panierDownloadFrontalParametrage/0f2f3338-d845-45a9-a124-384032d70219
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment