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
48f8158b
Commit
48f8158b
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: divided into tiles
parent
c9003def
No related branches found
Branches containing commit
No related tags found
2 merge requests
!5
Clhp map
,
!4
Clhp map
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/main.py
+2
-5
2 additions, 5 deletions
server/main.py
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
+25
-29
25 additions, 29 deletions
server/map/get_relation.py
with
27 additions
and
34 deletions
server/main.py
+
2
−
5
View file @
48f8158b
...
...
@@ -37,10 +37,10 @@ class IceHTTP(BaseHTTPRequestHandler):
self
.
wfile
.
write
(
b
"
Root path hit!
"
)
elif
self
.
path
==
'
/update_map
'
:
# NB: should be POST?
get_all_markers
(
self
,
self
.
cursor
,
False
,
'
Mjosa
'
)
# Get all markers
get_all_markers
(
self
.
cursor
,
False
,
'
Mjosa
'
)
# Get all markers
# NB: temporary hardcoded waterBodyName
elif
self
.
path
==
'
/get_valid_markers
'
:
# NB: should be POST?
get_all_markers
(
self
,
self
.
cursor
,
True
,
'
Mjosa
'
)
# Get only valid markers
get_all_markers
(
self
.
cursor
,
True
,
'
Mjosa
'
)
# Get only valid markers
# NB: temporary hardcoded waterBodyName
elif
self
.
path
==
'
/get_relation
'
:
get_relation
(
self
,
'
Mjosa
'
)
# NB temp hardcoded value
...
...
@@ -49,9 +49,6 @@ class IceHTTP(BaseHTTPRequestHandler):
if
self
.
path
==
'
/get_weather_data
'
:
get_weather
(
self
)
elif
self
.
path
==
'
/new_lidar_data
'
:
input_new_Lidar_data
(
self
,
self
.
cursor
,
1
,
'
Mjosa
'
)
# hardcoded body of water must change later
# Terminate server on key press q
def
on_key_press
(
server
,
event
,
cursor
,
conn
):
if
event
.
name
==
'
q
'
:
...
...
This diff is collapsed.
Click to expand it.
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
48f8158b
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
25
−
29
View file @
48f8158b
...
...
@@ -16,16 +16,8 @@ def get_relation(self, body_of_water: str):
if
len
(
polygons
)
<=
1
:
print
(
"
Failed to convert to polygons
"
)
tiles
=
[]
for
polygon
in
polygons
:
tiles
.
extend
(
divide_relation
(
polygon
))
# Divide each polygon from relation and append to tiles
# Convert polygon coordinates to lists
tiles_json
=
[
list
(
tile
.
exterior
.
coords
)
for
tile
in
tiles
]
# Convert response data to JSON string
response_json
=
json
.
dumps
(
tiles_json
)
response_json
=
json
.
dumps
(
divide_relation
(
polygons
)
)
# Set headers
self
.
send_response
(
200
)
...
...
@@ -36,30 +28,34 @@ def get_relation(self, body_of_water: str):
self
.
wfile
.
write
(
response_json
.
encode
(
'
utf-8
'
))
def
divide_relation
(
polygon
):
def
divide_relation
(
polygon
s
):
# Define tile size
tile_size
=
0.01
x_min
,
y_min
,
x_max
,
y_max
=
polygon
.
bounds
rows
=
int
((
y_max
-
y_min
)
/
tile_size
)
cols
=
int
((
x_max
-
x_min
)
/
tile_size
)
id
=
1
tiles
=
[]
if
rows
==
0
or
cols
==
0
:
# Return if the polygon is too small
return
[]
for
row
in
range
(
rows
):
for
col
in
range
(
cols
):
tile_bbox
=
Polygon
([
(
x_min
+
col
*
tile_size
,
y_min
+
row
*
tile_size
),
(
x_min
+
(
col
+
1
)
*
tile_size
,
y_min
+
row
*
tile_size
),
(
x_min
+
(
col
+
1
)
*
tile_size
,
y_min
+
(
row
+
1
)
*
tile_size
),
(
x_min
+
col
*
tile_size
,
y_min
+
(
row
+
1
)
*
tile_size
)
])
tiles
.
append
(
tile_bbox
)
for
polygon
in
polygons
:
x_min
,
y_min
,
x_max
,
y_max
=
polygon
.
bounds
rows
=
int
((
y_max
-
y_min
)
/
tile_size
)
cols
=
int
((
x_max
-
x_min
)
/
tile_size
)
if
rows
==
0
or
cols
==
0
:
# Skip small polygons
continue
for
row
in
range
(
rows
):
for
col
in
range
(
cols
):
tile_bbox
=
Polygon
([
(
x_min
+
col
*
tile_size
,
y_min
+
row
*
tile_size
),
(
x_min
+
(
col
+
1
)
*
tile_size
,
y_min
+
row
*
tile_size
),
(
x_min
+
(
col
+
1
)
*
tile_size
,
y_min
+
(
row
+
1
)
*
tile_size
),
(
x_min
+
col
*
tile_size
,
y_min
+
(
row
+
1
)
*
tile_size
)
])
tiles
.
append
({
"
SubDivID
"
:
id
,
"
polygon
"
:
tile_bbox
})
id
+=
1
if
len
(
tiles
)
<=
1
:
print
(
"
Failed to divide polygon into tiles
"
)
print
(
"
Failed to divide polygon
s
into tiles
"
)
return
tiles
tiles_json
=
[{
"
SubDivID
"
:
tile
[
"
SubDivID
"
],
"
coordinates
"
:
list
(
tile
[
"
polygon
"
].
exterior
.
coords
)}
for
tile
in
tiles
]
return
tiles_json
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