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
be2db7a2
Commit
be2db7a2
authored
1 year ago
by
Hoa Ben The Nguyen
Browse files
Options
Downloads
Patches
Plain Diff
change: move calclation functions to data processing, add: grid calculation
parent
28e896c6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/data_processing/area_processing.py
+51
-0
51 additions, 0 deletions
server/data_processing/area_processing.py
server/map/get_markers.py
+0
-36
0 additions, 36 deletions
server/map/get_markers.py
with
51 additions
and
36 deletions
server/data_processing/area_processing.py
0 → 100644
+
51
−
0
View file @
be2db7a2
from
math
import
pi
,
cos
EARTH
=
6378.137
# Radius of the earth in kilometer
METER
=
(
1
/
((
2
*
pi
/
360
)
*
EARTH
))
/
1000
# 1 meter in degree
def
calculate_corners
(
lat
,
lng
,
area_offset
):
"""
Calculate corners of polygon based on a center coordinate
Arguments:
lat -- center latitude
lng -- center longitude
"""
# From https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters
# Formulas:
lat_pos
=
lat
+
(
area_offset
*
METER
)
lng_pos
=
lng
+
(
area_offset
*
METER
)
/
cos
(
lat
*
(
pi
/
180
))
lat_neg
=
lat
-
(
area_offset
*
METER
)
lng_neg
=
lng
-
(
area_offset
*
METER
)
/
cos
(
lat
*
(
pi
/
180
))
return
[
(
lat_neg
,
lng_pos
),
# top left
(
lat_pos
,
lng_pos
),
# top right
(
lat_pos
,
lng_neg
),
# bottom right
(
lat_neg
,
lng_neg
)
# bottom left
]
'''
return [(60.7798, 10.7062), # NB: temporary hardcoded values
(60.7553, 10.7433),
(60.7718, 10.7975),
(60.7966, 10.7405)]
'''
def
define_gridareas
(
lat
,
lng
,
area_offset
,
grid_size
):
return_value
=
[]
main_area
=
calculate_corners
(
lat
,
lng
,
area_offset
)
area_size
=
(
main_area
[
0
][
0
]
-
main_area
[
2
][
0
],
main_area
[
0
][
1
]
-
main_area
[
2
][
1
])
dist_to_subcenter
=
(
area_size
[
0
]
/
(
grid_size
*
2
),
area_size
[
1
]
/
(
grid_size
*
2
))
subarea_offset
=
area_offset
/
grid_size
print
(
area_size
)
print
(
dist_to_subcenter
)
for
y
in
range
(
grid_size
-
1
):
relative_size_lng
=
y
/
grid_size
for
x
in
range
(
grid_size
-
1
):
relative_size_lat
=
x
/
grid_size
lat_pos
=
main_area
[
0
][
0
]
+
relative_size_lat
*
area_size
[
0
]
-
dist_to_subcenter
[
0
]
lng_pos
=
main_area
[
0
][
1
]
+
relative_size_lng
*
area_size
[
1
]
-
dist_to_subcenter
[
1
]
return_value
.
append
(
calculate_corners
(
lat_pos
,
lng_pos
,
subarea_offset
))
return
return_value
print
(
calculate_corners
(
60
,
10
,
1500
))
print
(
define_gridareas
(
60
,
10
,
1500
,
4
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/map/get_markers.py
+
0
−
36
View file @
be2db7a2
import
json
from
math
import
pi
,
cos
# get_markers requests all marker data or valid markers, converts the data to json, and writes
# the data to the response object
...
...
@@ -91,37 +89,3 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
# Write marker data to response object
self
.
wfile
.
write
(
marker_data
.
encode
(
'
utf-8
'
))
EARTH
=
6378.137
# Radius of the earth in kilometer
METER
=
(
1
/
((
2
*
pi
/
360
)
*
EARTH
))
/
1000
# 1 meter in degree
OFFSET
=
20
# Offset in meters
def
calculate_corners
(
lat
,
lng
):
"""
Calculate corners of polygon based on a center coordinate
Arguments:
lat -- center latitude
lng -- center longitude
"""
# From https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters
# Formulas:
'''
lat_pos = lat + (OFFSET * METER)
lng_pos = lng + (OFFSET * METER) / cos(lat * (pi / 180))
lat_neg = lat - (OFFSET * METER)
lng_neg = lng - (OFFSET * METER) / cos(lat * (pi / 180))
return [
(lat_neg, lng_pos),
(lat_pos, lng_pos),
(lat_pos, lng_neg),
(lat_neg, lng_neg)
]
'''
return
[(
60.7798
,
10.7062
),
# NB: temporary hardcoded values
(
60.7553
,
10.7433
),
(
60.7718
,
10.7975
),
(
60.7966
,
10.7405
)]
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