Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
map to kml
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
map to kml
Commits
69719bdf
Commit
69719bdf
authored
Apr 04, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix rotation
parent
adcb2289
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
14 deletions
+25
-14
map_to_kml.py
map_to_kml.py
+25
-14
No files found.
map_to_kml.py
View file @
69719bdf
...
...
@@ -103,18 +103,29 @@ def add_polygone(root, coordinate_tuple_list, style_map_id):
coordinates
.
text
=
' '
.
join
(
(
','
.
join
(
str
(
x
)
for
x
in
coor_tuple
)
for
coor_tuple
in
coordinate_tuple_list
))
def
build_rectangle
(
root
,
lat
,
lon
,
length
,
width
,
height
,
style_map_id
,
map_info
,
map_size
):
def
rotate
(
x
,
y
,
x_o
,
y_o
,
rotation
):
"""Apply rotation to coordinates."""
return
(
x_o
+
math
.
cos
(
rotation
)
*
(
x
-
x_o
)
-
math
.
sin
(
rotation
)
*
(
y
-
y_o
),
y_o
+
math
.
sin
(
rotation
)
*
(
x
-
x_o
)
+
math
.
cos
(
rotation
)
*
(
y
-
y_o
),
)
def
build_rectangle
(
root
,
lat
,
lon
,
length
,
width
,
height
,
rotation
,
style_map_id
,
map_info
,
map_size
):
"""Build a rectangle."""
local_x
,
local_y
=
convert_to_local_coordinates
(
lat
,
lon
,
map_info
,
map_size
)
max_lon
,
_
=
convert_to_geo_coordinates
(
local_x
+
length
,
local_y
,
map_info
,
map_size
)
_
,
max_lat
=
convert_to_geo_coordinates
(
local_x
,
local_y
+
width
,
map_info
,
map_size
)
add_polygone
(
root
,
(
(
lat
,
lon
,
height
),
(
lat
,
max_lon
,
height
),
(
max_lat
,
max_lon
,
height
),
(
max_lat
,
lon
,
height
),
(
lat
,
lon
,
height
),
),
style_map_id
)
min_x
=
local_x
-
length
/
2
max_x
=
local_x
+
length
/
2
min_y
=
local_y
-
width
/
2
max_y
=
local_y
+
width
/
2
polygone_coordinates
=
[]
for
x
,
y
in
((
min_x
,
min_y
),
(
max_x
,
min_y
),
(
max_x
,
max_y
),
(
min_x
,
max_y
),
(
min_x
,
min_y
)):
rotated_x
,
rotated_y
=
rotate
(
x
,
y
,
local_x
,
local_y
,
rotation
)
corner_lon
,
corner_lat
=
convert_to_geo_coordinates
(
rotated_x
,
rotated_y
,
map_info
,
map_size
)
polygone_coordinates
.
append
((
corner_lat
,
corner_lon
,
height
))
add_polygone
(
root
,
polygone_coordinates
,
style_map_id
)
def
write_kml
(
filename
,
map_dict
):
...
...
@@ -151,14 +162,14 @@ def write_kml(filename, map_dict):
for
obstacle
in
map_dict
[
'obstacle_list'
]:
position
=
obstacle
[
'position'
]
scale
=
obstacle
[
'scale'
]
rotation
=
obstacle
[
'rotation'
][
'z'
]
*
math
.
pi
/
180
build_rectangle
(
document
,
position
[
'latitude'
],
position
[
'longitude'
],
scale
[
'x'
]
*
math
.
cos
(
rotation
)
+
scale
[
'y'
]
*
math
.
sin
(
rotation
)
,
-
scale
[
'x'
]
*
math
.
sin
(
rotation
)
+
scale
[
'y'
]
*
math
.
cos
(
rotation
)
,
scale
[
'x'
],
scale
[
'y'
]
,
position
[
'altitude'
]
+
scale
[
'z'
],
-
obstacle
[
'rotation'
][
'z'
]
*
math
.
pi
/
180
,
'obstacle'
,
map_info
,
map_size
,
...
...
@@ -167,7 +178,7 @@ def write_kml(filename, map_dict):
for
flag
in
map_dict
[
'flag_list'
]:
position
=
flag
[
'position'
]
build_rectangle
(
document
,
position
[
'latitude'
],
position
[
'longitude'
],
1
,
1
,
position
[
'altitude'
],
'flag'
,
map_info
,
map_size
)
1
,
1
,
position
[
'altitude'
],
0
,
'flag'
,
map_info
,
map_size
)
tree
=
ET
.
ElementTree
(
root
)
ET
.
indent
(
tree
,
' '
)
...
...
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