Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
7
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Savanovic Djordjevic
PROG2900
Commits
f2d90fc5
Commit
f2d90fc5
authored
10 months ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: rename tile to cell in add_new_lake
parent
5ab3e2b8
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Clhp map into main
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/map_handler/add_new_lake.py
+9
-7
9 additions, 7 deletions
server/map_handler/add_new_lake.py
with
9 additions
and
7 deletions
server/map_handler/add_new_lake.py
+
9
−
7
View file @
f2d90fc5
...
...
@@ -33,8 +33,10 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
bounds
=
polygons
[
0
].
bounds
start_x
,
start_y
,
_
,
_
=
bounds
# Calculate the cell width and height in degrees of latitude and longitude
cell_width
=
cell_size_in_km
/
111.3200
cell_height
=
cell_width
/
cos
(
start_x
*
0.01745
)
# List to store new GeoJSON feature objects
features
=
[]
# List to store new GeoJSON feature objects
sub_div_id
=
0
# Tracker to create unique subdivision ids
...
...
@@ -45,7 +47,7 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
# Generate a grid based on the calculated cell size
lines
=
create_grid
(
polygon
,
cell_width
*
2
,
cell_height
)
lines
.
append
(
polygon
.
boundary
)
# Merge the grid lines into a single
gri
d object
# Merge the grid lines into a single
polygonize
d object
lines
=
unary_union
(
lines
)
lines
=
linemerge
(
lines
)
lines
=
list
(
polygonize
(
lines
))
...
...
@@ -53,16 +55,16 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
# Combine the polygon and the grid to form the subdivisions
for
line
in
lines
:
if
line
.
intersects
(
polygon
):
# Add the geometry which intersects the gird
tile
=
(
line
.
intersection
(
polygon
))
divided_map
.
append
(
tile
)
cell
=
(
line
.
intersection
(
polygon
))
divided_map
.
append
(
cell
)
# Calculate
tile
center based on bounds, and round down to two decimals
min_x
,
min_y
,
max_x
,
max_y
=
tile
.
bounds
# Calculate
cell
center based on bounds, and round down to two decimals
min_x
,
min_y
,
max_x
,
max_y
=
cell
.
bounds
center
=
round
(
max_y
-
(
max_y
-
min_y
),
6
),
round
(
max_x
-
(
max_x
-
min_x
),
6
)
rounded_coordinates
=
[]
if
isinstance
(
tile
,
Polygon
):
for
coords
in
tile
.
exterior
.
coords
:
if
isinstance
(
cell
,
Polygon
):
for
coords
in
cell
.
exterior
.
coords
:
rounded_coords
=
(
round
(
coords
[
0
],
4
),
round
(
coords
[
1
],
4
))
rounded_coordinates
.
append
(
rounded_coords
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment