Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
shapefile
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sarah Abrishami
shapefile
Commits
4eedffb2
Commit
4eedffb2
authored
Apr 11, 2022
by
Sarah Abrishami
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated file
parent
e0cc029e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
create_multi_polygon.py
create_multi_polygon.py
+4
-3
No files found.
create_multi_polygon.py
View file @
4eedffb2
import
json
import
json
import
geopandas
as
gpd
import
geopandas
as
gpd
from
shapely.geometry
import
Polygon
,
MultiPolygon
,
Point
from
shapely.geometry
import
Polygon
,
MultiPolygon
,
Point
import
fiona
def
find_center
(
mlp
):
def
find_center
(
mlp
):
...
@@ -8,9 +9,9 @@ def find_center(mlp):
...
@@ -8,9 +9,9 @@ def find_center(mlp):
area
=
0
area
=
0
for
p
in
mlp
.
geoms
:
for
p
in
mlp
.
geoms
:
if
p
.
area
>
area
:
if
p
.
area
>
area
:
center
=
Point
(
p
.
centroid
.
x
,
p
.
centroid
.
y
)
center
=
json
.
dumps
([
p
.
centroid
.
x
,
p
.
centroid
.
y
]
)
elif
isinstance
(
mlp
,
Polygon
):
elif
isinstance
(
mlp
,
Polygon
):
center
=
Point
(
mlp
.
centroid
.
x
,
mlp
.
centroid
.
y
)
center
=
json
.
dumps
([
mlp
.
centroid
.
x
,
mlp
.
centroid
.
y
]
)
else
:
else
:
raise
TypeError
(
'object not polygon nor multipolygon'
)
raise
TypeError
(
'object not polygon nor multipolygon'
)
return
center
return
center
...
@@ -25,4 +26,4 @@ for climate in df['clmd_id'].unique():
...
@@ -25,4 +26,4 @@ for climate in df['clmd_id'].unique():
gdf
=
gdf
.
append
(
a
,
ignore_index
=
True
)
gdf
=
gdf
.
append
(
a
,
ignore_index
=
True
)
gdf
[
'center'
]
=
gdf
[
'geometry'
]
.
apply
(
find_center
)
gdf
[
'center'
]
=
gdf
[
'geometry'
]
.
apply
(
find_center
)
# gdf.to_file()
gdf
.
to_file
(
'output.json'
,
driver
=
'GeoJSON'
)
\ No newline at end of file
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