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
b9e4136f
Commit
b9e4136f
authored
Jun 18, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use width and depth to do projections
parent
69719bdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
31 deletions
+28
-31
map_to_kml.py
map_to_kml.py
+28
-31
No files found.
map_to_kml.py
View file @
b9e4136f
...
...
@@ -34,33 +34,31 @@ def lat_lon_distance(lat1, lon1, lat2, lon2):
c
=
2
*
math
.
atan2
(
math
.
sqrt
(
a
),
math
.
sqrt
(
1
-
a
))
return
6371e3
*
c
def
longitude_to_X
(
lon
,
map_size
):
def
longitude_to_X
(
lon
,
width
):
"""Mercator projection of longitude."""
return
(
map_size
/
360
)
*
(
180
+
lon
)
return
(
width
/
360
)
*
(
180
+
lon
)
def
latitude_to_Y
(
lat
,
map_size
):
def
latitude_to_Y
(
lat
,
depth
):
"""Mercator projection latitude."""
return
(
map_size
/
180
)
*
(
90
-
lat
)
return
(
depth
/
180
)
*
(
90
-
lat
)
def
convert_to_local_coordinates
(
latitude
,
longitude
,
map_info
,
map_size
):
def
convert_to_local_coordinates
(
latitude
,
longitude
,
map_info
):
"""Convert coordinates into local values."""
x
=
longitude_to_X
(
longitude
,
map_size
)
y
=
latitude_to_Y
(
latitude
,
map_size
)
local_x
=
((
x
-
map_info
[
'min_x'
])
/
(
map_info
[
'max_x'
]
-
map_info
[
'min_x'
]))
\
*
1000
-
map_size
/
2
local_y
=
((
y
-
map_info
[
'min_y'
])
/
(
map_info
[
'max_y'
]
-
map_info
[
'min_y'
]))
\
*
1000
-
map_size
/
2
x
=
longitude_to_X
(
longitude
,
map_info
[
'width'
])
y
=
latitude_to_Y
(
latitude
,
map_info
[
'depth'
])
local_x
=
(((
x
-
map_info
[
'min_x'
])
/
(
map_info
[
'max_x'
]
-
map_info
[
'min_x'
]))
-
0.5
)
*
map_info
[
'width'
]
local_y
=
(((
y
-
map_info
[
'min_y'
])
/
(
map_info
[
'max_y'
]
-
map_info
[
'min_y'
]))
-
0.5
)
*
map_info
[
'depth'
]
return
local_x
,
local_y
def
convert_to_geo_coordinates
(
x
,
y
,
map_info
,
map_size
):
def
convert_to_geo_coordinates
(
x
,
y
,
map_info
):
"""Convert local values to coordinates."""
lon
=
(
x
+
map_size
/
2
)
/
1000
lon
=
(
x
/
map_info
[
'width'
])
+
0.5
lon
=
lon
*
(
map_info
[
'max_x'
]
-
map_info
[
'min_x'
])
+
map_info
[
'min_x'
]
lon
=
lon
/
(
map_
size
/
360
)
-
180
lon
=
lon
/
(
map_
info
[
'width'
]
/
360
)
-
180
lat
=
(
y
+
map_size
/
2
)
/
1000
lat
=
(
y
/
map_info
[
'depth'
])
+
0.5
lat
=
lat
*
(
map_info
[
'max_y'
]
-
map_info
[
'min_y'
])
+
map_info
[
'min_y'
]
lat
=
90
-
lat
/
(
map_
size
/
180
)
lat
=
90
-
lat
/
(
map_
info
[
'depth'
]
/
180
)
return
lon
,
lat
...
...
@@ -111,9 +109,9 @@ def rotate(x, y, x_o, y_o, rotation):
)
def
build_rectangle
(
root
,
lat
,
lon
,
length
,
width
,
height
,
rotation
,
style_map_id
,
map_info
,
map_size
):
style_map_id
,
map_info
):
"""Build a rectangle."""
local_x
,
local_y
=
convert_to_local_coordinates
(
lat
,
lon
,
map_info
,
map_size
)
local_x
,
local_y
=
convert_to_local_coordinates
(
lat
,
lon
,
map_info
)
min_x
=
local_x
-
length
/
2
max_x
=
local_x
+
length
/
2
min_y
=
local_y
-
width
/
2
...
...
@@ -122,7 +120,7 @@ def build_rectangle(root, lat, lon, length, width, height, rotation,
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
)
corner_lon
,
corner_lat
=
convert_to_geo_coordinates
(
rotated_x
,
rotated_y
,
map_info
)
polygone_coordinates
.
append
((
corner_lat
,
corner_lon
,
height
))
add_polygone
(
root
,
polygone_coordinates
,
style_map_id
)
...
...
@@ -146,17 +144,17 @@ def write_kml(filename, map_dict):
(
map_dict
[
'min_lat'
],
map_dict
[
'min_lon'
],
0
),
),
'terrain'
)
map_size
=
math
.
ceil
(
max
(
lat_lon_distance
(
map_dict
[
'min_lat'
],
map_dict
[
'min_lon'
],
map_dict
[
'min_lat'
],
map_dict
[
'max_lon'
]),
lat_lon_distance
(
map_dict
[
'min_lat'
],
map_dict
[
'min_lon'
],
map_dict
[
'max_lat'
],
map_dict
[
'min_lon'
]),
))
depth
=
lat_lon_distance
(
map_dict
[
'min_lat'
],
map_dict
[
'min_lon'
],
map_dict
[
'max_lat'
],
map_dict
[
'min_lon'
])
width
=
lat_lon_distance
(
map_dict
[
'min_lat'
],
map_dict
[
'min_lon'
],
map_dict
[
'min_lat'
],
map_dict
[
'max_lon'
])
map_info
=
{
'min_x'
:
longitude_to_X
(
map_dict
[
'min_lon'
],
map_size
),
'min_y'
:
latitude_to_Y
(
map_dict
[
'min_lat'
],
map_size
),
'max_x'
:
longitude_to_X
(
map_dict
[
'max_lon'
],
map_size
),
'max_y'
:
latitude_to_Y
(
map_dict
[
'max_lat'
],
map_size
),
'depth'
:
depth
,
'min_x'
:
longitude_to_X
(
map_dict
[
'min_lon'
],
width
),
'min_y'
:
latitude_to_Y
(
map_dict
[
'min_lat'
],
depth
),
'max_x'
:
longitude_to_X
(
map_dict
[
'max_lon'
],
width
),
'max_y'
:
latitude_to_Y
(
map_dict
[
'max_lat'
],
depth
),
'width'
:
width
,
}
for
obstacle
in
map_dict
[
'obstacle_list'
]:
...
...
@@ -172,13 +170,12 @@ def write_kml(filename, map_dict):
-
obstacle
[
'rotation'
][
'z'
]
*
math
.
pi
/
180
,
'obstacle'
,
map_info
,
map_size
,
)
for
flag
in
map_dict
[
'flag_list'
]:
position
=
flag
[
'position'
]
build_rectangle
(
document
,
position
[
'latitude'
],
position
[
'longitude'
],
1
,
1
,
position
[
'altitude'
],
0
,
'flag'
,
map_info
,
map_size
)
1
,
1
,
position
[
'altitude'
],
0
,
'flag'
,
map_info
)
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