[postgis-tickets] [PostGIS] #2564: Implement the inverse of the ST_AsLatLonText function

PostGIS trac at osgeo.org
Sat Jan 11 13:48:11 PST 2014


#2564: Implement the inverse of the ST_AsLatLonText function
-------------------------+--------------------------------------------------
 Reporter:  andrewxhill  |       Owner:  pramsey      
     Type:  enhancement  |      Status:  new          
 Priority:  low          |   Milestone:  PostGIS 2.2.0
Component:  postgis      |     Version:  2.1.x        
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by dbaston):

 I see how the idea for regex tutorial came about!  I was thinking a format
 string seemed necessary too, but as I thought more about it, I'm not sure.

 Say you're willing to require the following about the input.
 1) Latitude and Longitude have the same formatting (they're both DMS or
 DD.DDDD, etc., but not mixed)
 2) Either cardinal directions are provided, or latitude can be assumed to
 come before longitude.
 3) If N, S, E, and W appear in the input string, they can be assumed to
 represent cardinal directions
 4) Some kind of delimiter is used between degrees, minutes, and seconds.
 (you don't have 431720.33 for 43°17'20.33)

 I put together a function that parses under these assumptions, and I'm
 getting good results on a pretty broad set of inputs.  The lines below
 show raw input strings, followed by the returned lat/lon or error
 condition.

 I put code for this on github at https://github.com/dbaston/parse_dms .
 If you're comfortable with the approach, I can work on a patch to
 liblwgeom (or wherever it would be appropriate)

 raw: 2°19'29.928"S 3°14'3.243"W ;
  lat:-2.324980  lon:-3.234234
 raw: 2 degrees, 19 minutes, 30 seconds to the S 3 degrees, 14 minutes, 3
 seconds to the W
  lat:-2.325000  lon:-3.234167
 raw: -2°19'29.928" -3°14'3.243"
  lat:-2.324980  lon:-3.234234
 raw: 2.3250 degrees S 3.2342 degrees W
  lat:-2.325000  lon:-3.234200
 raw: 44° 8.156', -72° 16.194'
  lat:44.135933  lon:-72.269900
 raw: 32° 18' 23.1" N 122° 36' 52.5" W
  lat:32.306417  lon:-122.614583
 raw: 32° 18.385' N 122° 36.875' W
  lat:32.306417  lon:-122.614583
 raw: 32.30642° N 122.61458° W
  lat:32.306420  lon:-122.614580
 raw: +32.30642, -122.61458
  lat:32.306420  lon:-122.614580
 raw: the coordinates were 122° 36' 52.5" W and 32° 18'     23.1" N
  lat:32.306417  lon:-122.614583
 raw: 40:26:46.302N 079:58:55.903W
  lat:40.446195  lon:-79.982195
 raw: 40°26′46″N 079°58′56″W
  lat:40.446111  lon:-79.982222
 raw: 40d 26′ 46″ N 079d 58′ 56″ W
  lat:40.446111  lon:-79.982222
 raw: 40.446195N 79.982195W
  lat:40.446195  lon:-79.982195
 raw: 40.446195, -79.982195
  lat:40.446195  lon:-79.982195
 raw: 40.446195,-79.982195
  lat:40.446195  lon:-79.982195
 raw: 40° 26.7717, -79° 58.93172
  lat:40.446195  lon:-79.982195
 raw: N40:26:46.302 W079:58:55.903
  lat:40.446195  lon:-79.982195
 raw: N40°26′46″ W079°58′56″
  lat:40.446111  lon:-79.982222
 raw: N40d 26′ 46″ W079d 58′ 56″
  lat:40.446111  lon:-79.982222
 raw: N40.446195 W79.982195
  lat:40.446195  lon:-79.982195
 raw: -16 deg. 23.44 min. S, -44 deg. 32.2 min. W
  lat:-16.390667  lon:-44.536667
 raw: 32.30642° NE 122.61458° W (problem is too many cardinal directions)
  too many cardinal directions
 raw: 32°23.45' N 122.61458° W (problem is differing numbers of components
 DM vs D)
  invalid # numeric components.
 raw: N40d 26′ 46″ W079d 58′ 56″ 24ms (problem is too many components)
  invalid # numeric components.
 raw: 40.446.195, -79.982195 (unparseable number)
  numeric parse error
 raw: 32°26′46″ N 122.61458° W (inconsistent format)
  coordinates not same format

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/2564#comment:5>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list