/
XYZ
225 lines (183 loc) · 6.87 KB
/
XYZ
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_XYZ_H
#define OSGEARTH_XYZ_H
#include <osgEarth/Common>
#include <osgEarth/ImageLayer>
#include <osgEarth/ElevationLayer>
#include <osgEarth/URI>
#include <osgEarth/Threading>
/**
* XYZ layers. These are general purpose tiled layers that conform
* to a X/Y/Z prototype where Z is the tiling level and X/Y are the
* tile offsets on that level.
*/
//! XYZ namespace contains support classes used to the Layers
namespace osgEarth { namespace XYZ
{
/**
* Underlying XYZ driver that does the actual I/O
*/
class OSGEARTH_EXPORT Driver
{
public:
Status open(
const URI& uri,
osg::ref_ptr<const Profile>& profile,
const std::string& format,
DataExtentList& out_dataExtents,
const osgDB::Options* readOptions);
ReadResult read(
const URI& uri,
const TileKey& key,
bool invertY,
ProgressCallback* progress,
const osgDB::Options* readOptions) const;
protected:
std::string _format;
std::string _template;
std::string _rotateChoices;
std::string _rotateString;
std::string::size_type _rotateStart, _rotateEnd;
mutable std::atomic_int _rotate_iter;
};
// Internal serialization options
class OSGEARTH_EXPORT XYZImageLayerOptions : public ImageLayer::Options
{
public:
META_LayerOptions(osgEarth, XYZImageLayerOptions, ImageLayer::Options);
OE_OPTION(URI, url);
OE_OPTION(bool, invertY);
OE_OPTION(std::string, format);
static Config getMetadata();
virtual Config getConfig() const;
private:
void fromConfig(const Config& conf);
};
// Internal serialization options
class OSGEARTH_EXPORT XYZElevationLayerOptions : public ElevationLayer::Options
{
public:
META_LayerOptions(osgEarth, XYZElevationLayerOptions, ElevationLayer::Options);
OE_OPTION(URI, url);
OE_OPTION(bool, invertY);
OE_OPTION(std::string, format);
OE_OPTION(std::string, elevationEncoding);
static Config getMetadata();
virtual Config getConfig() const;
private:
void fromConfig(const Config& conf);
};
} }
namespace osgEarth
{
/**
* Image layer connected to a generic, raw tile service and accesible
* via a URL template.
*
* The template pattern will vary depending on the structure of the data source.
* Here is an example URL:
*
* http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png
*
* {z} is the level of detail. {x} and {y} are the tile indices at that
* level of detail. The [] delimiters indicate a URL "rotation"; for each
* subsequent request, one and only one of the characters inside the []
* will be used.
*
* XYZ accesses a "raw" data source and reads no metadata. Thus you must
* expressly provide a geospatial Profile by calling setProfile() on the
* layer before opening it or adding it to the Map. For example, for the
* pattern above you might want a spherical mercator profile:
*
* layer->setProfile( Profile::create(Profile::SPHERICAL_MERCATOR) );
*/
class OSGEARTH_EXPORT XYZImageLayer : public ImageLayer
{
public: // serialization
typedef XYZ::XYZImageLayerOptions Options;
public:
META_Layer(osgEarth, XYZImageLayer, Options, ImageLayer, XYZImage);
public:
//! Base URL for requests
void setURL(const URI& value);
const URI& getURL() const;
//! Tiling profile (required)
void setProfile(const Profile* profile) override;
//! Whether to flip the Y axis for tile indexing
void setInvertY(const bool& value);
const bool& getInvertY() const;
//! Data format to request from the service
void setFormat(const std::string& value);
const std::string& getFormat() const;
public: // Layer
//! Establishes a connection to the data
virtual Status openImplementation() override;
//! Creates a raster image for the given tile key
virtual GeoImage createImageImplementation(const TileKey& key, ProgressCallback* progress) const override;
protected: // Layer
//! Called by constructors
virtual void init();
protected:
//! Destructor
virtual ~XYZImageLayer() { }
private:
XYZ::Driver _driver;
};
/**
* Elevation layer that pulls from an XYZ encoded URL
*/
class OSGEARTH_EXPORT XYZElevationLayer : public ElevationLayer
{
public:
typedef XYZ::XYZElevationLayerOptions Options;
public:
META_Layer(osgEarth, XYZElevationLayer, Options, ElevationLayer, XYZElevation);
//! Base URL for requests
void setURL(const URI& value);
const URI& getURL() const;
//! Tiling profile (required)
void setProfile(const Profile* profile) override;
//! Whether to flip the Y axis for tile indexing
void setInvertY(const bool& value);
const bool& getInvertY() const;
//! Data format to request from the service
void setFormat(const std::string& value);
const std::string& getFormat() const;
//! Encoding encoding type
void setElevationEncoding(const std::string& value);
const std::string& getElevationEncoding() const;
public: // Layer
//! Establishes a connection to the XYZ data
virtual Status openImplementation() override;
//! Creates a heightfield for the given tile key
virtual GeoHeightField createHeightFieldImplementation(const TileKey& key, ProgressCallback* progress) const override;
protected: // Layer
//! Called by constructors
virtual void init();
protected:
//! Destructor
virtual ~XYZElevationLayer() { }
private:
osg::ref_ptr<XYZImageLayer> _imageLayer;
};
} // namespace osgEarth
OSGEARTH_SPECIALIZE_CONFIG(osgEarth::XYZImageLayer::Options);
OSGEARTH_SPECIALIZE_CONFIG(osgEarth::XYZElevationLayer::Options);
#endif // OSGEARTH_XYZ_H