ooRexx logo
   1: /* ---------------------------------------------------------------- */
   2: /* Some classes to facilitate GPX interaction:                      */
   3: /*                                                                  */
   4: /*   GeoPoint - a definition of a GPX ,  or      */
   5: /*   GeoSegment - an array of GeoPoints defining a GPX      */
   6: /*   GeoRoute - an array of GeoPoints defining a GPX           */
   7: /*   GeoWaypoints - an array of GeoPoints defining the GPX 's  */
   8: /*   GeoTrack - a list of GeoSegments defining a GPX           */
   9: /*                                                                  */
  10: /* ---------------------------------------------------------------- */
  11: /*                                                                  */
  12: /* Originally by Ruurd J. Idenburg                                  */
  13: /*                                                                  */
  14: /* No copyright, no licence, no guarantees or warrantees, be it     */
  15: /* explicit, implicit or whatever. Usage is totally and completely  */
  16: /* at the users own risk, the author shall not be liable for any    */
  17: /* damages whatsoever, for any reason whatsoever.                   */
  18: /*                                                                  */
  19: /* Please keep this comment block intact when modifying this code   */
  20: /* and add a note with date and a description.                      */
  21: /*                                                                  */
  22: /* ---------------------------------------------------------------- */
  23: /* 2014/01/26 - Initial version approximately                       */
  24: /* ---------------------------------------------------------------- */
  25: ::class "geoPoint" public
  26: 
  27: ::attribute latlon get    -- latitude and longitude in decimal degrees
  28: ::attribute elevation     -- elevation in meters of the point
  29: ::attribute time          -- creation/modification timestamp in UTC
  30: ::attribute name          -- name for the point
  31: ::attribute comment       -- comment for the point
  32: ::attribute description   -- description of the point
  33: ::attribute source        -- the source of it to indicate reliability
  34: ::attribute link          -- a link to additional info on the point 
  35: ::attribute symbol        -- text of a GPS symbol name
  36: ::attribute type          -- type/classification of the point
  37: ::attribute fix           -- the type of fix for this point
  38: ::attribute geoidheight     -- height (in meters) of geoid (mean sea level) 
  39:                             -- above WGS84 earth ellipsoid, as defined in
  40:                             -- NMEA GGA message.
  41:                            
  42: ::method init
  43:   expose latlon
  44:   use strict arg lat,lon
  45:   latlon = .geoloc~new(lat,lon)
  46: exit
  47: 
  48: ::method lat
  49:   expose latlon
  50:   return latlon~latitude
  51: exit
  52: 
  53: ::method lon
  54:   expose latlon
  55:   return latlon~longitude
  56: exit
  57: 
  58: ::method makeGPX
  59:   use arg indent, gpxTag='wpt'
  60:   say indent || '<'gpxTag 'lat="' || self~lat || '" lon="' || self~lon || '" >'
  61:   say indent''
  62: exit  
  63: 
  64:  
  65: ::class "geoArray" private subclass array inherit restrictable
  66: 
  67: ::attribute type get
  68: 
  69: -- geoArray is a one-dimensional array in one of 3 types; routepoints,
  70: -- trackpoints or waypoints, which all three can have only geoPoints as
  71: -- members of the collection.
  72: -- @param One of "R(outepoints), Trackpoints, W(aypoints), first character suffices.
  73: -- @result A newly created empty array of the type specified   
  74: ::method init
  75: expose type
  76:   use arg type
  77:   type = type~subchar(1)~upper
  78:   if "RTW"~pos(type)==0 
  79:     then raise syntax 93.914 array(1,"R(outepoints),T(rackpoints),W(aypoints)",type)
  80:   self~init:super
  81: exit  
  82: 
  83: ::method isAllowed 
  84:   use arg item
  85:   return (item~class~id==.geoPoint~id)
  86: exit
  87: 
  88: ::method makeGPX
  89:   expose type
  90:   use arg indent
  91:   arrayTag = "rte trkseg"~word("RTW"~pos(type)) 
  92:   -- the  parent tag is , which is not (yet) implemented
  93:   pointTag = "rtept trkpt wpt"~word("RTW"~pos(type))
  94:   if arrayTag\=="" then do
  95:     say indent'<'arrayTag'>'
  96:   end
  97:   do i=1 to self~items
  98:     self[i]~makeGPX(indent'  ',pointTag)
  99:   end
 100:   if arrayTag\=="" then do
 101:     say indent''
 102:   end
 103: exit
 104: 
 105: ::class "geoSegment" public subclass geoArray 
 106: 
 107: ::method init
 108:   if arg()>0
 109:     then raise syntax 93.902 array(0)
 110:   self~init:super('T')
 111: exit
 112:   
 113: ::class "geoRoute" public subclass geoArray
 114: 
 115: ::method init
 116:   if arg()>0
 117:     then raise syntax 93.902 array(0)
 118:   self~init:super('R')
 119: exit
 120: 
 121: ::class "geoWaypoints" public subclass geoArray
 122: 
 123: ::method init
 124:   if arg()>0
 125:     then raise syntax 93.902 array(0)
 126:   self~init:super('W')
 127: exit
 128:   
 129: ::class "geoTrack" public subclass geoArray 
 130:  
 131: ::method isAllowed
 132:   use arg item
 133:   return (item~class~id==.geoSegment~id)
 134: 
 135: ::method makeGPX
 136:   indent = ''
 137:   say ''
 138:   say ''  
 139:   indent = indent'  '
 140:   say indent''
 141:   do i=1 to self~items
 142:     self[i]~makeGPX(indent'  ')
 143:   end
 144:   say indent''
 145:   say ''
 146: exit
 147: 
 148: ::requires "restrictable.cls"
 149: ::requires "geoloc.cls"
All content © Ruurd Idenburg, 2007–2025, except where marked otherwise. All rights reserved. This page is primarily for non-commercial use only. The Idenburg website records no personal information and sets no ‘cookies’. This site is hosted on my on server at my home, falling under Dutch (privacy) laws.

This page updated on Wed, 28 May 2025 10:38:18 +0200.