Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
b30bff8c
Commit
b30bff8c
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
fix: map return json structure, maybe
parent
80be3b43
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Clhp map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/map/__pycache__/get_relation.cpython-311.pyc
+0
-0
0 additions, 0 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
server/map/get_relation.py
+30
-12
30 additions, 12 deletions
server/map/get_relation.py
with
30 additions
and
12 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
b30bff8c
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
30
−
12
View file @
b30bff8c
import
geopandas
as
gpd
from
shapely.geometry
import
Polygon
,
LineString
,
MultiLineString
from
shapely.ops
import
linemerge
,
unary_union
,
polygonize
import
matplotlib.pyplot
as
plt
import
random
import
json
import
os
...
...
@@ -30,31 +32,47 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
divided_map
.
extend
(
combine_grid_with_poly
(
polygon
,
lines
))
####################### PLOTTIND ############################
tiles
=
[
gpd
.
GeoDataFrame
(
geometry
=
[
tile
])
for
tile
in
divided_map
]
sub_div_id
=
0
for
tile
in
tiles
:
tile
[
'
sub_div_id
'
]
=
sub_div_id
tile
[
'
sub_div_center
'
]
=
tile
[
'
geometry
'
].
centroid
.
apply
(
lambda
x
:
[
x
.
x
,
x
.
y
])
sub_div_id
+=
1
print
(
"
Plotting... This may take some time...
"
)
# NB test plot
fig
,
ax
=
plt
.
subplots
()
ax
.
set_aspect
(
1.5
)
tiles_json
=
{
'
type
'
:
'
FeatureCollection
'
,
'
features
'
:
[]}
# Plot each tile
for
tile
in
tiles
:
feature
=
{
random_color
=
"
#{:06x}
"
.
format
(
random
.
randint
(
0
,
0xFFFFFF
))
gpd
.
GeoSeries
(
tile
.
geometry
).
plot
(
ax
=
ax
,
facecolor
=
random_color
,
edgecolor
=
'
none
'
)
plt
.
show
()
##################### PLOTTIND END ###########################
features
=
[]
sub_div_id
=
0
for
tile
in
divided_map
:
tile_feature
=
{
'
type
'
:
'
Feature
'
,
'
geometry
'
:
tile
.
geometry
.
__geo_interface__
,
'
geometry
'
:
tile
.
__geo_interface__
,
'
properties
'
:
{
'
sub_div_id
'
:
int
(
tile
[
'
sub_div_id
'
].
iloc
[
0
])
,
'
sub_div_center
'
:
tile
[
'
sub_div_center
'
].
tolist
()
'
sub_div_id
'
:
sub_div_id
,
'
sub_div_center
'
:
tile
.
centroid
.
coords
[
0
]
}
}
tiles_json
[
'
features
'
].
append
(
feature
)
features
.
append
(
tile_feature
)
sub_div_id
+=
1
feature_collection
=
{
'
type
'
:
'
FeatureCollection
'
,
'
features
'
:
features
}
self
.
send_response
(
200
)
self
.
send_header
(
"
Content-type
"
,
"
application/json
"
)
self
.
end_headers
()
self
.
wfile
.
write
(
json
.
dumps
(
tiles_js
on
).
encode
(
'
utf-8
'
))
self
.
wfile
.
write
(
json
.
dumps
(
feature_collecti
on
).
encode
(
'
utf-8
'
))
def
create_grid
(
poly
:
Polygon
,
cell_size
):
...
...
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