001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.gpx;
003
004import java.awt.Color;
005import java.util.Arrays;
006import java.util.Collections;
007import java.util.List;
008import java.util.Map;
009import java.util.TreeMap;
010
011import org.openstreetmap.josm.data.Bounds;
012import org.openstreetmap.josm.spi.preferences.Config;
013
014/**
015 * Constants for GPX handling.
016 */
017public interface GpxConstants {
018
019    /** Prefix used for attributes when converting to OSM data */
020    String GPX_PREFIX = "gpx:";
021
022    /** GPS name of the element. This field will be transferred to and from the GPS.
023     *  GPX does not place restrictions on the length of this field or the characters contained in it.
024     *  It is up to the receiving application to validate the field before sending it to the GPS. */
025    String GPX_NAME = "name";
026
027    /** GPS element comment. Sent to GPS as comment. */
028    String GPX_CMT = "cmt";
029
030    /** Text description of the element. Holds additional information about the element intended for the user, not the GPS. */
031    String GPX_DESC = "desc";
032
033    /** Source of data. Included to give user some idea of reliability and accuracy of data. */
034    String GPX_SRC = "src";
035
036    /**
037     * Prefix used for all meta values.
038     */
039    String META_PREFIX = "meta.";
040    /**
041     * A constant for the metadata hash map: the author name of the file
042     * @see GpxData#get(String)
043     */
044    String META_AUTHOR_NAME = META_PREFIX + "author.name";
045    /**
046     * A constant for the metadata hash map: the author email of the file
047     * @see GpxData#get(String)
048     */
049    String META_AUTHOR_EMAIL = META_PREFIX + "author.email";
050    /**
051     * A constant for the metadata hash map: a link to a page about the author
052     * @see GpxData#get(String)
053     */
054    String META_AUTHOR_LINK = META_PREFIX + "author.link";
055    /**
056     * A constant for the metadata hash map: the author field for the copyright information in the gpx file
057     * @see GpxData#get(String)
058     */
059    String META_COPYRIGHT_AUTHOR = META_PREFIX + "copyright.author";
060    /**
061     * A constant for the metadata hash map: the license of the file
062     * @see GpxData#get(String)
063     */
064    String META_COPYRIGHT_LICENSE = META_PREFIX + "copyright.license";
065    /**
066     * A constant for the metadata hash map: the year of the license for the file
067     * @see GpxData#get(String)
068     */
069    String META_COPYRIGHT_YEAR = META_PREFIX + "copyright.year";
070    /**
071     * A constant for the metadata hash map: a description of the file
072     * @see GpxData#get(String)
073     */
074    String META_DESC = META_PREFIX + "desc";
075    /**
076     * A constant for the metadata hash map: the keywords of the file
077     * @see GpxData#get(String)
078     */
079    String META_KEYWORDS = META_PREFIX + "keywords";
080    /**
081     * A constant for the metadata hash map: the links. They are stored as list of {@link GpxLink} objects
082     * @see GpxData#get(String)
083     */
084    String META_LINKS = META_PREFIX + "links";
085    /**
086     * A constant for the metadata hash map: the name of the file (stored in the file, not the one on the disk)
087     * @see GpxData#get(String)
088     */
089    String META_NAME = META_PREFIX + "name";
090    /**
091     * A constant for the metadata hash map: the time as string
092     * @see GpxData#get(String)
093     */
094    String META_TIME = META_PREFIX + "time";
095    /**
096     * A constant for the metadata hash map: the bounding box. This is a {@link Bounds} object
097     * @see GpxData#getMetaBounds()
098     */
099    String META_BOUNDS = META_PREFIX + "bounds";
100
101    /**
102     * The creator element that will be written when exporting a GPX file
103     * @since 18287
104     */
105    String JOSM_CREATOR_NAME = "JOSM GPX export";
106
107    /**
108     * Namespace for the XSD
109     */
110    String XML_URI_XSD = "http://www.w3.org/2001/XMLSchema-instance";
111
112    /**
113     * Namespace for JOSM GPX extensions
114     */
115    String XML_URI_EXTENSIONS_JOSM = Config.getUrls().getXMLBase() + "/gpx-extensions-1.1";
116    /**
117     * Location of the XSD schema for JOSM GPX extensions
118     */
119    String XML_XSD_EXTENSIONS_JOSM = Config.getUrls().getXMLBase() + "/gpx-extensions-1.1.xsd";
120
121    /**
122     * Namespace for GPX drawing extensions
123     */
124    String XML_URI_EXTENSIONS_DRAWING = Config.getUrls().getXMLBase() + "/gpx-drawing-extensions-1.0";
125    /**
126     * Location of the XSD schema for GPX drawing extensions
127     */
128    String XML_XSD_EXTENSIONS_DRAWING = Config.getUrls().getXMLBase() + "/gpx-drawing-extensions-1.0.xsd";
129
130    /**
131     * Namespace for Garmin GPX extensions
132     */
133    String XML_URI_EXTENSIONS_GARMIN = "http://www.garmin.com/xmlschemas/GpxExtensions/v3";
134    /**
135     * Location of the XSD schema for GPX drawing extensions
136     */
137    String XML_XSD_EXTENSIONS_GARMIN = "http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd";
138
139    /** Elevation (in meters) of the point. */
140    String PT_ELE = "ele";
141
142    /** Creation/modification timestamp for the point.
143     *  Date and time in are in Coordinated Universal Time (UTC), not local time!
144     *  Conforms to ISO 8601 specification for date/time representation.
145     *  Fractional seconds are allowed for millisecond timing in tracklogs. */
146    String PT_TIME = "time";
147
148    /** True Course/Bearing angle over ground.
149     * @since 19387
150     */
151    String PT_COURSE = "course";
152
153    /** Magnetic variation (in degrees) at the point. 0.0 <= value < 360.0 */
154    String PT_MAGVAR = "magvar";
155
156    /** Height, in meters, of geoid (mean sea level) above WGS-84 earth ellipsoid. (NMEA GGA message) */
157    String PT_GEOIDHEIGHT = "geoidheight";
158
159    /** Text of GPS symbol name. For interchange with other programs, use the exact spelling of the symbol on the GPS, if known. */
160    String PT_SYM = "sym";
161
162    /** Type (textual classification) of element. */
163    String PT_TYPE = "type";
164
165    /** Type of GPS fix. none means GPS had no fix. Value comes from list: {'none'|'2d'|'3d'|'dgps'|'pps'} */
166    String PT_FIX = "fix";
167
168    /** Number of satellites used to calculate the GPS fix. (not number of satellites in view). */
169    String PT_SAT = "sat";
170
171    /** Horizontal dilution of precision. */
172    String PT_HDOP = "hdop";
173
174    /** Vertical dilution of precision. */
175    String PT_VDOP = "vdop";
176
177    /** Position dilution of precision. */
178    String PT_PDOP = "pdop";
179
180    /** Number of seconds since last DGPS update. */
181    String PT_AGEOFDGPSDATA = "ageofdgpsdata";
182
183    /** Represents a differential GPS station. 0 <= value <= 1023 */
184    String PT_DGPSID = "dgpsid";
185
186    /** Standard horizontal major deviation */
187    String PT_STD_HDEV = "stdhdev";
188    
189    /** Standard vertical major deviation */
190    String PT_STD_VDEV = "stdvdev";
191    
192    /**
193     * Ordered list of all possible waypoint keys.
194     */
195    List<String> WPT_KEYS = Collections.unmodifiableList(Arrays.asList(PT_ELE, PT_TIME, PT_MAGVAR, PT_GEOIDHEIGHT,
196            GPX_NAME, GPX_CMT, GPX_DESC, GPX_SRC, META_LINKS, PT_SYM, PT_TYPE, PT_FIX, PT_SAT, PT_COURSE,
197            PT_HDOP, PT_VDOP, PT_PDOP, PT_AGEOFDGPSDATA, PT_DGPSID, PT_STD_HDEV, PT_STD_VDEV));
198
199    /**
200     * Ordered list of all possible route and track keys.
201     */
202    List<String> RTE_TRK_KEYS = Collections.unmodifiableList(Arrays.asList(
203            GPX_NAME, GPX_CMT, GPX_DESC, GPX_SRC, META_LINKS, "number", PT_TYPE));
204
205    /**
206     * Map with all supported Garmin colors
207     */
208    Map<String, Color> GARMIN_COLORS = getGarminColors();
209
210    /**
211     * Helper method for {@link #GARMIN_COLORS}
212     * @return Map with all supported Garmin colors
213     */
214    static Map<String, Color> getGarminColors() {
215        TreeMap<String, Color> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
216        m.put("Black", Color.BLACK);
217        m.put("DarkRed", new Color(139, 0, 0));
218        m.put("DarkGreen", new Color(0, 100, 0));
219        m.put("DarkYellow", new Color(255, 170, 0));
220        m.put("DarkBlue", new Color(0, 0, 139));
221        m.put("DarkMagenta", new Color(139, 0, 139));
222        m.put("DarkCyan", new Color(0, 139, 139));
223        m.put("LightGray", Color.LIGHT_GRAY);
224        m.put("DarkGray", Color.DARK_GRAY);
225        m.put("Red", Color.RED);
226        m.put("Green", Color.GREEN);
227        m.put("Yellow", Color.YELLOW);
228        m.put("Blue", Color.BLUE);
229        m.put("Magenta", Color.MAGENTA);
230        m.put("Cyan", Color.CYAN);
231        m.put("White", Color.WHITE);
232        m.put("Transparent", new Color(0, 0, 0, 255));
233        return Collections.unmodifiableMap(m);
234    }
235
236    /**
237     * Enum with color formats that can be written by JOSM
238     */
239    enum ColorFormat {
240        /** Drawing extension format */
241        GPXD,
242        /** Garmin track extension format */
243        GPXX
244    }
245
246    /**
247     * Map with all supported extension abbreviations for easier readability in OSM layers
248     */
249    Map<String, String> EXTENSION_ABBREVIATIONS = getExtensionAbbreviations();
250
251    /**
252     * Helper method for {@link #EXTENSION_ABBREVIATIONS}
253     * @return Map with all supported extension abbreviations
254     */
255    static Map<String, String> getExtensionAbbreviations() {
256        TreeMap<String, String> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
257        m.put("gpx:extension:gpxx:TrackExtension:DisplayColor", "gpxx:DisplayColor");
258        m.put("gpx:extension:gpxd:color", "gpxd:color");
259        return m;
260    }
261
262    /**
263     * Possible fix values. NMEA 0183 Version 4.00
264     */
265    List<String> FIX_VALUES = Collections.unmodifiableList(
266            Arrays.asList("none", "2d", "3d", "dgps", "pps", "rtk", "float rtk", "estimated", "manual", "simulated"));
267
268    /**
269     * The flag which indicates the solution quality.<ul>
270     * <li>1 : Fixed, solution by carrier‐based relative positioning and the integer ambiguity is properly resolved.</li>
271     * <li>2 : Float, solution by carrier‐based relative positioning but the integer ambiguity is not resolved.</li>
272     * <li>3 : Reserved</li>
273     * <li>4 : DGPS, solution by code‐based DGPS solutions or single point positioning with SBAS corrections</li>
274     * <li>5 : Single, solution by single point positioning</li></ul>
275     * @since 15247
276     */
277    String RTKLIB_Q = "Q";
278    /** N (north) component of the standard deviations in m. */
279    String RTKLIB_SDN = "sdn";
280    /** E (east) component of the standard deviations in m. */
281    String RTKLIB_SDE = "sde";
282    /** U (up) component of the standard deviations in m. */
283    String RTKLIB_SDU = "sdu";
284    /**
285     * The absolute value of sdne means square root of the absolute value of NE component of the estimated covariance matrix.
286     * The sign represents the sign of the covariance. */
287    String RTKLIB_SDNE = "sdne";
288    /**
289     * The absolute value of sdeu means square root of the absolute value of EU component of the estimated covariance matrix.
290     * The sign represents the sign of the covariance. */
291    String RTKLIB_SDEU = "sdeu";
292    /**
293     * The absolute value of sdun means square root of the absolute value of UN component of the estimated covariance matrix.
294     * The sign represents the sign of the covariance. */
295    String RTKLIB_SDUN = "sdun";
296    /** The time difference between the observation data epochs of the rover receiver and the base station in second. */
297    String RTKLIB_AGE = "age";
298    /**
299     * The ratio factor of ʺratio‐testʺ for standard integer ambiguity validation strategy.
300     * The value means the ratio of the squared sum of the residuals with the second best integer vector to with the best integer vector. */
301    String RTKLIB_RATIO = "ratio";
302}