FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tilemaker/src/coordinates.cpp at master · cyclemap/tilemaker · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
cyclemap
/
tilemaker
Public
forked from
systemed/tilemaker
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tilemaker
/
src
/
coordinates.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (58 loc) · 2.64 KB
Breadcrumbs
tilemaker
/
src
/
coordinates.cpp
Copy path
File metadata and controls
67 lines (58 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
include
"
coordinates.h
"
#
include
<
math.h
>
#
include
<
algorithm
>
TileCoordinates_::TileCoordinates_
() {
this
->
x
=
0
;
this
->
y
=
0
;
}
TileCoordinates_::TileCoordinates_
(TileCoordinate x, TileCoordinate y) {
this
->
x
= x;
this
->
y
= y;
}
double
deg2rad
(
double
deg) {
return
(
M_PI
/
180.0
) * deg; }
double
rad2deg
(
double
rad) {
return
(
180.0
/
M_PI
) * rad; }
//
Project latitude (spherical Mercator)
//
(if calling with raw coords, remember to divide/multiply by 10000000.0)
static
inline
double
clamp
(
double
value,
double
limit) {
return
(value < -limit ? -limit : (value > limit ? limit : value));
}
double
lat2latp
(
double
lat) {
return
rad2deg
(
log
(
tan
(
deg2rad
(
clamp
(lat,
85.06
)+
90.0
)/
2.0
))); }
double
latp2lat
(
double
latp) {
return
rad2deg
(
atan
(
exp
(
deg2rad
(latp)))*
2.0
)-
90.0
; }
//
Tile conversions
double
lon2tilexf
(
double
lon,
uint8_t
z) {
return
scalbn
((lon+
180.0
) * (
1
/
360.0
), (
int
)z); }
double
latp2tileyf
(
double
latp,
uint8_t
z) {
return
scalbn
((
180.0
-latp) * (
1
/
360.0
), (
int
)z); }
double
lat2tileyf
(
double
lat,
uint8_t
z) {
return
latp2tileyf
(
lat2latp
(lat), z); }
uint32_t
lon2tilex
(
double
lon,
uint8_t
z) {
return
lon2tilexf
(lon, z); }
uint32_t
latp2tiley
(
double
latp,
uint8_t
z) {
return
latp2tileyf
(latp, z); }
uint32_t
lat2tiley
(
double
lat,
uint8_t
z) {
return
lat2tileyf
(lat, z); }
double
tilex2lon
(
uint32_t
x,
uint8_t
z) {
return
scalbn
(x, -(
int
)z) *
360.0
-
180.0
; }
double
tiley2latp
(
uint32_t
y,
uint8_t
z) {
return
180.0
-
scalbn
(y, -(
int
)z) *
360.0
; }
double
tiley2lat
(
uint32_t
y,
uint8_t
z) {
return
latp2lat
(
tiley2latp
(y, z)); }
//
Get a tile index
TileCoordinates
latpLon2index
(LatpLon ll,
uint8_t
baseZoom) {
return
TileCoordinates
(
lon2tilex
(ll.
lon
/
10000000.0
, baseZoom),
latp2tiley
(ll.
latp
/
10000000.0
, baseZoom));
}
//
Convert to actual length
double
degp2meter
(
double
degp,
double
latp) {
return
RadiusMeter *
deg2rad
(degp) *
cos
(
deg2rad
(
latp2lat
(latp)));
}
double
meter2degp
(
double
meter,
double
latp) {
return
rad2deg
((
1
/RadiusMeter) * (meter /
cos
(
deg2rad
(
latp2lat
(latp)))));
}
//
the range between smallest y and largest y is filled, for each x
void
fillCoveredTiles
(std::unordered_set<TileCoordinates>& tileSet) {
std::vector<TileCoordinates>
tileList
(tileSet.
begin
(), tileSet.
end
());
std::sort
(tileList.
begin
(), tileList.
end
(),
TileCoordinatesCompare
());
TileCoordinate prevX =
0
, prevY =
static_cast
<TileCoordinate>(-
2
);
for
(TileCoordinates index: tileList) {
TileCoordinate tileX = index.
x
, tileY = index.
y
;
if
(tileX == prevX) {
//
this loop has no effect at the first iteration
for
(TileCoordinate fillY = prevY+
1
; fillY < tileY; fillY++) {
tileSet.
insert
(
TileCoordinates
(tileX, fillY));
}
}
prevX = tileX, prevY = tileY;
}
}
Back
|
FazBrowse Home
|
New Git URL