Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
coordinate.h
Go to the documentation of this file.
1 /*
2  * coordinate.h
3  *
4  * Created on: 31 May 2018
5  * Author: billy
6  */
7 
8 
9 #ifndef TOOLS_GRASSROOTS_GEOCODER_INCLUDE_COORD_H_
10 #define TOOLS_GRASSROOTS_GEOCODER_INCLUDE_COORD_H_
11 
12 #include <math.h>
13 
15 #include "typedefs.h"
16 #include "jansson.h"
17 
18 
19 /*
20  * Taken from https://stackoverflow.com/questions/15965166/what-is-the-maximum-length-of-latitude-and-longitude
21  *
22  * The valid range of latitude in degrees is -90 and +90 for the southern and northern hemisphere respectively.
23  * Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively.
24  *
25  * So our value being outside this range means that the coordinate value hasn't been set
26  */
27 #define COORD_UNSET (-1000.0)
28 
34 typedef struct
35 {
39  double64 co_x;
40 
45  double64 co_y;
46 
52  double64 *co_elevation_p;
53 } Coordinate;
54 
55 
56 
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 
59 #ifdef ALLOCATE_COORDINATE_TAGS
60  #define COORDINATE_PREFIX GRASSROOTS_GEOCODER_API
61  #define COORDINATE_VAL(x) = x
62 #else
63  #define COORDINATE_PREFIX extern GRASSROOTS_GEOCODER_API
64  #define COORDINATE_VAL(x)
65 #endif
66 
67 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
68 
69 
70 
76 COORDINATE_PREFIX const char *CO_LATITUDE_S COORDINATE_VAL ("latitude");
77 
78 
84 COORDINATE_PREFIX const char *CO_LONGITUDE_S COORDINATE_VAL ("longitude");
85 
86 
92 COORDINATE_PREFIX const char *CO_ELEVATION_S COORDINATE_VAL ("elevation");
93 
94 
95 
96 #ifdef __cplusplus
97 extern "C"
98 {
99 #endif
100 
101 
111 GRASSROOTS_GEOCODER_API Coordinate *AllocateCoordinate (double64 x, double64 y);
112 
113 
122 
123 
132 
133 
142 GRASSROOTS_GEOCODER_API json_t *GetCoordinateAsJSON (const Coordinate * const coord_p);
143 
144 
157 GRASSROOTS_GEOCODER_API bool AddCoordinateToJSON (const Coordinate *coord_p, json_t *dest_p, const char * const coord_key_s);
158 
159 
169 GRASSROOTS_GEOCODER_API bool SetCoordinateFromJSON (Coordinate *coord_p, const json_t *value_p);
170 
171 
172 
173 GRASSROOTS_GEOCODER_API bool SetCoordinateFromCompoundJSON (Coordinate *coord_p, const json_t *value_p, const char * const coord_key_s);
174 
175 
185 GRASSROOTS_GEOCODER_API bool SetCoordinateElevation (Coordinate *coord_p, double64 elevation);
186 
187 
196 
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 
203 
204 #endif /* #ifndef TOOLS_GRASSROOTS_GEOCODER_INCLUDE_COORD_H_ */
CO_ELEVATION_S
const char * CO_ELEVATION_S
The key for the elevation of for a location object for a given record.
Definition: coordinate.h:92
CO_LATITUDE_S
const char * CO_LATITUDE_S
The key for the latitude of for a location object for a given record.
Definition: coordinate.h:76
Coordinate::AllocateCoordinate
Coordinate * AllocateCoordinate(double64 x, double64 y)
Allocate a coordinate for a given latitude and longitude.
Coordinate::GetCoordinateAsJSON
json_t * GetCoordinateAsJSON(const Coordinate *const coord_p)
Get the JSON representation of a Coordinate.
Coordinate::InitCoordinate
void InitCoordinate(Coordinate *coord_p)
Initialise a coordinate as 0,0.
Coordinate::ClearCoordinateElevation
void ClearCoordinateElevation(Coordinate *coord_p)
Clear the elevation for a given Coordinate.
Coordinate::AddCoordinateToJSON
bool AddCoordinateToJSON(const Coordinate *coord_p, json_t *dest_p, const char *const coord_key_s)
Add the JSON representation for a given Coordinate to a JSON fragment using a given key.
CO_LONGITUDE_S
const char * CO_LONGITUDE_S
The key for the longitude of for a location object for a given record.
Definition: coordinate.h:84
Coordinate::SetCoordinateFromJSON
bool SetCoordinateFromJSON(Coordinate *coord_p, const json_t *value_p)
Set the Coordinate from a JSON representation.
Coordinate::co_x
double64 co_x
The latitude, in degrees, which has a valid range from -90 and +90 for the southern and northern hemi...
Definition: coordinate.h:39
typedefs.h
SetCoordinateFromCompoundJSON
bool SetCoordinateFromCompoundJSON(Coordinate *coord_p, const json_t *value_p, const char *const coord_key_s)
grassroots_geocoder_library.h
Coordinate::co_y
double64 co_y
The longitude, in degrees, which has a valid range from -180 and +180 specifying coordinates west and...
Definition: coordinate.h:45
GRASSROOTS_GEOCODER_API
#define GRASSROOTS_GEOCODER_API
Definition: grassroots_geocoder_library.h:46
Coordinate::co_elevation_p
double64 * co_elevation_p
A pointer to the elevation value, in metres, for this Coordinate.
Definition: coordinate.h:52
Coordinate::SetCoordinateElevation
bool SetCoordinateElevation(Coordinate *coord_p, double64 elevation)
Set the elevation for a given Coordinate.
Coordinate::FreeCoordinate
void FreeCoordinate(Coordinate *coord_p)
Free a Coordinate.
Coordinate
A datatype for storing a geographic coordinate.
Definition: coordinate.h:34