NDEVR
API Documentation
CoordinateProjectionManager.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, 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: Design
28File: CoordinateProjectionManager
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/CoordinateProjection.h>
35#include <NDEVR/Dictionary.h>
36#include <NDEVR/String.h>
37#include <NDEVR/Pointer.h>
38#include <NDEVR/File.h>
39#include <NDEVR/UUID.h>
40#include <functional>
41namespace NDEVR
42{
43 template<uint01 t_dims, class t_type, class t_vertex>
44 class Polyline;
45 class File;
47 class UnitOption;
48 class CustomUnit;
49 class Scanner;
50 class JSONNode;
51 class UnitManager;
52
60 class NDEVR_DESIGN_API LatLonUnit
61 {
62 public:
68
73 static constexpr StringView LatLonUnitName() { return "LatLonUnit"; }
74 };
75 template<class t_type>
76 class Resource;
77
83 {
85 uint04 authority_number = Constant<uint04>::Invalid;
87 };
88
95 class NDEVR_DESIGN_API CoordinateProjectionManager
96 {
97 public:
103
109
114 void writeCoordinateFile(File& file) const;
115
122 void readDirectoryStructure(File& top_dir, File& save_as);
123
129
134 void addProjection(const CoordinateProjection& projection);
135
140
144 void cleanup();
145
151 void processWKT(CoordinateProjection& projection, Scanner& scan);
152
158 void processJSON(CoordinateProjection& projection, JSONNode& json);
159
164 void setDownloader(std::function<void(const StringView&, std::function<void(const StringView&)>)> downloader);
165
170 bool hasDownloader() const;
171
176
184 bool downloadEPSGProjection(uint04 epsg_code, std::function<void(uint04 code, UUID projection)> finished_callback, bool force_download = false);
185
191 UUID getProjection(const StringView& name) const;
192
198
204 UUID epsgProjection(uint04 epsg_number) const;
205
211 Buffer<UUID> getProjections(const StringView& search_string = StringView()) const;
212
218 const CoordinateProjection& get(UUID id) const;
219
225
231 bool hasProjection(UUID projection_id) const;
232
239
246
252 UUID bestUTMProjectionMeters(const Vertex<2, fltp08>& northing_easting) const;
253
260
268
276
283 Bounds<2, fltp08> convertFromWGS84(UUID from_id, const Bounds<2, Angle<fltp08>>& bounds) const;
284
292
300
308
316
324
332
340
346
352
357 static bool HasEngine();
358
365
371
378 String createWKTString(UUID id, const UnitManager& manager) const;
379
385
391 static VerticalDatum GetVerticalDatum(uint04 authority_number);
392
397 void invalidateConverterCache(UUID projection_id);
398
405 void setVerticalDatum(UUID projection_id, const String& authority, uint04 authority_number);
406 public:
412
418 protected:
425 protected:
426
429 std::function<void(const StringView&, std::function<void(const StringView&)>)> m_downloader;
431 mutable UUID m_wgs84_id = Constant<UUID>::Invalid;
434 };
435}
436
437
438
439
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
Forward declaration of the File class.
Stores Coordinate Projections See https://ndevr.org/coordinate-projection/.
ConstPointer< Unit > unitFromString(const StringView &unit)
Looks up or creates a Unit from a string representation.
void addProjection(const CoordinateProjection &projection)
Adds a coordinate projection to the manager.
UUID m_wgs84_id
Cached UUID of the WGS 84 projection.
Buffer< UUID > m_utm_projections
List of UUIDs for the registered UTM projections.
static CoordinateProjection & BestUTMProjectionInfo()
Returns a mutable reference to the CoordinateProjection info for the auto-selected best UTM projectio...
static Buffer< VerticalDatum > GetVerticalDatums()
Returns a list of all known vertical datums.
Buffer< UUID > getProjections(const StringView &search_string=StringView()) const
Returns a list of projection UUIDs, optionally filtered by a search string.
Buffer< Vertex< 2, fltp08 > > convertToWGS84(UUID from_id, const Buffer< Vertex< 2, fltp08 > > &locations) const
Converts a buffer of 2D vertices from the specified projection to WGS 84.
void readDirectoryStructure(File &top_dir, File &save_as)
Reads coordinate projection definitions from a directory structure and saves the consolidated result.
Bounds< 2, fltp08 > convertToWGS84(UUID from_id, const Bounds< 3, fltp08 > &bounds) const
Converts 3D bounds from the specified projection to WGS 84 geographic coordinates.
void createUTMCoordinateProjections()
Creates and registers all standard UTM coordinate projections (zones 1-60, north and south).
static UUID UseBestUTMProjectionID()
Returns a sentinel UUID indicating that the best UTM projection should be auto-selected.
bool hasDownloader() const
Checks whether a downloader function has been configured.
void invalidateConverterCache(UUID projection_id)
Invalidates any cached converter for the specified projection, forcing re-creation on next use.
bool hasProjection(UUID projection_id) const
Checks whether a projection with the given UUID exists in the manager.
const Dictionary< UUID, CoordinateProjection > & projections() const
Returns a const reference to the dictionary of all stored projections.
Buffer< UUID > bestProjectionsLatLon(const Vertex< 2, fltp08 > &lat_lon) const
Returns a ranked list of projections suitable for a given latitude/longitude coordinate.
Bounds< 2, fltp08 > convertToWGS84(UUID from_id, const Bounds< 2, fltp08 > &bounds) const
Converts 2D bounds from the specified projection to WGS 84 geographic coordinates.
Dictionary< String, ConstPointer< Unit > > m_units
Cache of parsed units keyed by their string names.
void setCoordinateFile(File &file)
Sets the file used for reading and writing coordinate projection data.
Dictionary< UUID, CoordinateProjection > m_projections
Dictionary of all registered coordinate projections keyed by UUID.
ConstPointer< UnitOption > wGS84UnitOption()
Returns a UnitOption representing conversion to WGS 84.
void setVerticalDatum(UUID projection_id, const String &authority, uint04 authority_number)
Sets the vertical datum for a given projection.
Vertex< 3, fltp08 > convertFromWGS84(UUID from_id, const Vertex< 3, fltp08 > &location) const
Converts a 3D vertex from WGS 84 to the specified projection.
Dictionary< UUID, CoordinateConverter * > m_wgs_84_converter
Cache of converters from various projections to WGS 84.
Bounds< 2, fltp08 > convertFromWGS84(UUID from_id, const Bounds< 2, Angle< fltp08 > > &bounds) const
Converts 2D angle-based bounds from WGS 84 to the specified projection.
UUID bestUTMProjectionLatLon(const Vertex< 2, fltp08 > &lat_lon) const
Determines the best UTM projection for a given latitude/longitude coordinate.
LineSegment< 2, fltp08 > convertToWGS84(UUID from_id, const LineSegment< 2, fltp08 > &segment) const
Converts a 2D line segment from the specified projection to WGS 84.
CoordinateConverter * wgs84Converter(UUID from_id) const
Retrieves or creates a converter from the specified projection to WGS 84.
UUID bestUTMProjectionMeters(const Vertex< 2, fltp08 > &northing_easting) const
Determines the best UTM projection for a given coordinate in meters.
void writeCoordinateFile(File &file) const
Writes all stored coordinate projections to the specified file.
bool downloadEPSGProjection(uint04 epsg_code, std::function< void(uint04 code, UUID projection)> finished_callback, bool force_download=false)
Downloads the projection definition for a specific EPSG code.
Polyline< 2, fltp08, Vertex< 2, fltp08 > > convertToWGS84(UUID from_id, const Polyline< 2, fltp08, Vertex< 2, fltp08 > > &segment) const
Converts a 2D polyline from the specified projection to WGS 84.
const CoordinateProjection & get(UUID id) const
Returns the coordinate projection data for the given UUID.
void setDownloader(std::function< void(const StringView &, std::function< void(const StringView &)>)> downloader)
Sets the download function used to retrieve remote projection data.
ConstPointer< Unit > wGS84Unit(UUID from_id)
Returns a unit that converts from the specified projection to WGS 84.
static CoordinateProjectionManager & DefaultInstance()
Returns the singleton default instance of the CoordinateProjectionManager.
File m_coordinate_file
The file used for persistent coordinate projection storage.
Bounds< 2, fltp08 > convertFromWGS84(UUID from_id, const Bounds< 2, fltp08 > &bounds) const
Converts 2D bounds from WGS 84 to the specified projection.
void readCoordinateFile(File &file)
Reads coordinate projection definitions from the specified file.
UUID epsgProjection(uint04 epsg_number) const
Returns the UUID of the projection with the given EPSG number.
void cleanup()
Removes unused or invalid entries and frees associated resources.
static bool HasEngine()
Checks whether a coordinate projection engine (e.g., PROJ) is available.
std::function< void(const StringView &, std::function< void(const StringView &)>)> m_downloader
Callback used to download remote projection definitions.
String createWKTString(UUID id, const UnitManager &manager) const
Creates a Well-Known Text (WKT) string for the specified projection.
static VerticalDatum GetVerticalDatum(uint04 authority_number)
Returns the vertical datum matching the given authority number.
Bounds< 2, fltp08 > convertFromWGS84(UUID from_id, const Bounds< 3, fltp08 > &bounds) const
Converts 3D bounds from WGS 84 to the specified projection.
UUID getProjection(const StringView &name) const
Looks up a projection UUID by its name.
UUID wgs84Projection() const
Returns the UUID of the WGS 84 geographic projection.
Vertex< 3, fltp08 > convertToWGS84(UUID from_id, const Vertex< 3, fltp08 > &location) const
Converts a 3D vertex from the specified projection to WGS 84.
const CoordinateProjection & currentProjection() const
Returns the currently active coordinate projection.
void processWKT(CoordinateProjection &projection, Scanner &scan)
Parses a Well-Known Text (WKT) string and populates the given projection.
void readDirectoryStructure(File &top_dir)
Reads coordinate projection definitions from a directory structure.
void downloadAllProjections()
Downloads definitions for all known projections from the remote source.
void processJSON(CoordinateProjection &projection, JSONNode &json)
Parses a JSON node and populates the given projection.
A program-defined unit that can be used for some specific task different from a program-wide unit.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:149
A specific unit that can convert between coordinate projections.
static constexpr StringView LatLonUnitName()
Returns the canonical name identifier for the lat/lon unit.
static DynamicPointer< CustomUnit > CustomLatLonUnit()
Creates and returns a custom unit for latitude/longitude coordinates.
Class: LineSegment.
Definition Line.hpp:52
A sequence of connected line segments defined by ordered vertices along a path.
Definition PolyLine.hpp:55
Contains methods for easily reading objects in an ascii stream using set deliminators and line logic.
Definition Scanner.h:47
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
Manages a collection of units across multiple data categories with INI persistence.
A definition of how to describe a particular set of data to a custom category of unit.
Definition UnitManager.h:18
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
The primary namespace for the NDEVR SDK.
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.
Basic data about a particular coordinate projection.
Data about a vertical coordinate reference system (e.g.
TranslatedString name
The display name of the vertical datum.
String authority
The authority defining this vertical datum (e.g., "EPSG").
uint04 authority_number
The authority-assigned code for this vertical datum.