NDEVR
API Documentation
GeoTiffElevationService.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2020, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: GeoTiffElevation
28File: GeoTiffElevationService
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "Design/Headers/ElevationService.h"
34#include "TIFImageHandler/Headers/GeoTiffFactory.h"
35#include "Base/Headers/Dictionary.h"
36#include "Base/Headers/File.h"
37#include "Base/Headers/RWLock.h"
38#include <QObject>
39struct tiff;
40typedef struct tiff TIFF;
41
42namespace NDEVR
43{
44 class ItemDownloader;
48 struct TileKey
49 {
50 sint04 lat = Constant<sint04>::Invalid;
51 sint04 lon = Constant<sint04>::Invalid;
52 bool operator==(const TileKey& other) const
53 {
54 return lat == other.lat && lon == other.lon;
55 }
56 bool operator!=(const TileKey& other) const
57 {
58 return !operator==(other);
59 }
60 };
61}
62namespace std
63{
64 template<>
65 struct hash<TileKey>
66 {
67 size_t operator()(const TileKey& key) const
68 {
69 return hash<int>()(key.lat) ^ (hash<int>()(key.lon) << 16);
70 }
71 };
72}
73namespace NDEVR
74{
79 {
81 TIFF* tif_handle = nullptr;
83
85 bool is_tiled = false;
89
91
92 uint04 cached_tile_ox = Constant<uint04>::Max;
93 uint04 cached_tile_oy = Constant<uint04>::Max;
94 uint04 cached_scanline_row = Constant<uint04>::Max;
95 };
96
176}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
For a given coordinate, determines the elevation at that coordinate.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
void processRequest(ElevationRequest request)
Processes an elevation request by loading or downloading required tiles.
void downloadTile(const TileKey &key, LogPtr &log)
Initiates downloading of a tile from the remote source.
static void Initialize()
Registers this service as an available elevation provider.
Dictionary< UUID, Buffer< TileKey > > m_request_tiles
Tiles required per request.
void onTileDownloadedSlot(const TileKey &key)
Called when a tile download completes successfully.
fltp08 sampleElevation(CachedTile &tile, fltp08 lat, fltp08 lon)
Samples the elevation value from a cached tile at a geographic coordinate.
RWLock m_lock
Read-write lock for thread-safe tile access.
Dictionary< TileKey, ItemDownloader * > m_active_downloads
Active tile downloads in progress.
Dictionary< TileKey, Buffer< UUID > > m_pending_tile_downloads
Requests waiting on specific tile downloads.
Buffer< TileKey > requiredTiles(const ElevationRequest &request)
Determines which tiles are needed to fulfill an elevation request.
static TileKey TileKeyForCoord(fltp08 lat, fltp08 lon)
Computes the tile key for a given geographic coordinate.
void onTileDownloadFailedSlot(const TileKey &key)
Called when a tile download fails.
void resolveRequest(ElevationRequest &request)
Resolves an elevation request by sampling loaded tiles.
void checkAndResolve(const UUID &request_id)
Checks if all tiles for a request are available and resolves it if so.
Dictionary< TileKey, bool > m_unavailable_tiles
Tiles that failed to download or are missing.
~GeoTiffElevationService()
Destroys the service and releases cached tile resources.
String tileName(const TileKey &key) const
Returns the human-readable name for a given tile.
Dictionary< TileKey, CachedTile > m_loaded_tiles
Tiles that have been loaded into memory.
File m_cache_dir
Local directory for cached tile files.
bool loadTileFromDisk(const TileKey &key)
Attempts to load a tile from the local disk cache.
GeoTiffElevationService()
Constructs a GeoTiffElevationService.
File tileCachePath(const TileKey &key) const
Returns the local cache file path for a given tile.
Dictionary< UUID, ElevationRequest > m_pending_requests
Pending elevation requests by UUID.
String tileUrl(const TileKey &key) const
Returns the download URL for a given tile.
virtual void postRequest(const ElevationRequest &request) override
Submits an elevation request for asynchronous processing.
Used for Downloading resources from a network.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
A readers-writer lock allowing concurrent reads or exclusive writes.
Definition RWLock.h:49
The core String class for the NDEVR API.
Definition String.h:95
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
Definition Vector.hpp:673
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
STL namespace.
Stores a cached GeoTIFF tile with precomputed layout information for fast elevation sampling.
uint04 scanline_bytes
The number of bytes per scanline for strip-based TIFFs.
uint04 tile_height
The height of each TIFF tile in pixels.
GeoTiffInfo info
The GeoTIFF metadata for this tile.
uint04 band_index
The raster band index used for elevation data.
uint04 cached_scanline_row
The currently cached scanline row index.
uint04 cached_tile_ox
X origin of the currently cached tile.
uint04 cached_tile_oy
Y origin of the currently cached tile.
uint04 tile_width
The width of each TIFF tile in pixels.
TIFF * tif_handle
The open TIFF file handle.
File file_path
The file path to the cached tile on disk.
Buffer< uint01 > read_buf
Reusable read buffer sized to tile or scanline size.
bool is_tiled
Whether the TIFF is stored in tiles (vs. strips).
Stores options and receives data for determining the elevation at given coordinates.
Stores parsed GeoTIFF metadata including projection, tiepoints, and raster dimensions.
A key identifying a geographic tile by integer latitude and longitude.
sint04 lon
The integer longitude of the tile.
sint04 lat
The integer latitude of the tile.