QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
3d
qgstilingscheme.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgstilingscheme.cpp
3
--------------------------------------
4
Date : July 2017
5
Copyright : (C) 2017 by Martin Dobias
6
Email : wonder dot sk at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgstilingscheme.h
"
17
18
#include "
qgschunknode.h
"
19
#include "
qgsrectangle.h
"
20
21
QgsTilingScheme::QgsTilingScheme
(
const
QgsRectangle
&
fullExtent
,
const
QgsCoordinateReferenceSystem
&
crs
)
22
: mCrs(
crs
)
23
, mFullExtent(
fullExtent
)
24
{
25
mMapOrigin =
QgsPointXY
(
fullExtent
.xMinimum(),
fullExtent
.yMinimum() );
26
mBaseTileSide = std::max(
fullExtent
.width(),
fullExtent
.height() );
27
}
28
29
QgsPointXY
QgsTilingScheme::tileToMap
(
int
x,
int
y,
int
z )
const
30
{
31
const
double
tileSide = mBaseTileSide / pow( 2, z );
32
const
double
mx = mMapOrigin.x() + x * tileSide;
33
const
double
my = mMapOrigin.y() + y * tileSide;
34
return
QgsPointXY
( mx, my );
35
}
36
37
void
QgsTilingScheme::mapToTile
(
const
QgsPointXY
&pt,
int
z,
float
&x,
float
&y )
const
38
{
39
const
double
tileSide = mBaseTileSide / pow( 2, z );
40
x = ( pt.
x
() - mMapOrigin.x() ) / tileSide;
41
y = ( pt.
y
() - mMapOrigin.y() ) / tileSide;
42
}
43
44
QgsRectangle
QgsTilingScheme::tileToExtent
(
int
x,
int
y,
int
z )
const
45
{
46
const
QgsPointXY
pt0 =
tileToMap
( x, y, z );
47
const
QgsPointXY
pt1 =
tileToMap
( x + 1, y + 1, z );
48
return
QgsRectangle
( pt0, pt1 );
49
}
50
51
QgsRectangle
QgsTilingScheme::tileToExtent
(
const
QgsChunkNodeId &nodeId )
const
52
{
53
return
tileToExtent
( nodeId.x, nodeId.y, nodeId.d );
54
}
55
56
void
QgsTilingScheme::extentToTile
(
const
QgsRectangle
&extent,
int
&x,
int
&y,
int
&z )
const
57
{
58
x = y = z = 0;
// start with root tile
59
while
(
true
)
60
{
61
// try to see if any child tile fully contains our extent - if so, go deeper
62
if
(
tileToExtent
( x * 2, y * 2, z + 1 ).contains( extent ) )
63
{
64
x = x * 2;
65
y = y * 2;
66
}
67
else
if
(
tileToExtent
( x * 2 + 1, y * 2, z + 1 ).contains( extent ) )
68
{
69
x = x * 2 + 1;
70
y = y * 2;
71
}
72
else
if
(
tileToExtent
( x * 2, y * 2 + 1, z + 1 ).contains( extent ) )
73
{
74
x = x * 2;
75
y = y * 2 + 1;
76
}
77
else
if
(
tileToExtent
( x * 2 + 1, y * 2 + 1, z + 1 ).contains( extent ) )
78
{
79
x = x * 2 + 1;
80
y = y * 2 + 1;
81
}
82
else
83
{
84
return
;
// cannot go deeper
85
}
86
z++;
87
}
88
}
QgsCoordinateReferenceSystem
Represents a coordinate reference system (CRS).
Definition
qgscoordinatereferencesystem.h:216
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsPointXY::y
double y
Definition
qgspointxy.h:66
QgsPointXY::x
double x
Definition
qgspointxy.h:65
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
QgsTilingScheme::mapToTile
void mapToTile(const QgsPointXY &pt, int z, float &x, float &y) const
Returns tile coordinates for given map coordinates and Z level.
Definition
qgstilingscheme.cpp:37
QgsTilingScheme::crs
QgsCoordinateReferenceSystem crs() const
Returns CRS of the tiling scheme.
Definition
qgstilingscheme.h:60
QgsTilingScheme::fullExtent
QgsRectangle fullExtent() const
Returns the full extent used in the constructor, which might not be square.
Definition
qgstilingscheme.h:67
QgsTilingScheme::extentToTile
void extentToTile(const QgsRectangle &extent, int &x, int &y, int &z) const
Returns coordinates of a tile that most tightly fits the whole extent.
Definition
qgstilingscheme.cpp:56
QgsTilingScheme::tileToMap
QgsPointXY tileToMap(int x, int y, int z) const
Returns map coordinates at tile coordinates (for lower-left corner of the tile).
Definition
qgstilingscheme.cpp:29
QgsTilingScheme::QgsTilingScheme
QgsTilingScheme()=default
Creates invalid tiling scheme.
QgsTilingScheme::tileToExtent
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
Definition
qgstilingscheme.cpp:44
qgschunknode.h
qgsrectangle.h
qgstilingscheme.h
Generated on
for QGIS API Documentation by
1.17.0