GPS points

GPS|GPS

Homework
The aim is to update a PostgreSQL/PostGIS table with GPS waypoints.

GPSBabel

 * http://www.gpsbabel.org
 * http://www.gpsbabel.org/htmldoc-1.5.0/filter_height.html
 * http://www.gpsbabel.org/htmldoc-1.5.1/fmt_unicsv.html

PostGIS geography type

 * http://postgis.net/docs/manual-2.0/using_postgis_dbmanagement.html#PostGIS_Geography

The geography type provides native support for spatial features represented on "geographic" coordinates (sometimes called "geodetic" coordinates, or "lat/lon", or "lon/lat"). Geographic coordinates are spherical coordinates expressed in angular units (degrees).

The basis for the PostGIS geographic type is a sphere. The shortest path between two points on the sphere is a great circle arc. That means that calculations on geographies (areas, distances, lengths, intersections, etc) must be calculated on the sphere, using more complicated mathematics. For more accurate measurements, the calculations must take the actual spheroidal shape of the world into account, and the mathematics becomes very complicated indeed.

One restriction is that it only supports WGS 84 long lat (SRID:4326). It uses a new data type called geography. None of the GEOS functions support this new type. As a workaround one can convert back and forth between geometry and geography types.

Unlike GEOMETRY, there is no need to run a separate AddGeometryColumns process to register the column in metadata.


 * http://postgis.org/documentation/manual-2.0/ST_GeogFromText.html

ST_GeogFromText — Return a specified geography value from Well-Known Text representation or extended (WKT).

--- converting lon lat coords to geography ALTER TABLE sometable ADD COLUMN geog geography(POINT,4326); UPDATE sometable SET geog = ST_GeogFromText('SRID=4326;POINT(' || lon || ' ' || lat || ')');

PostGIS geometry type

 * http://postgis.net/docs/manual-2.0/using_postgis_dbmanagement.html#PostGIS_GeographyVSGeometry

If your data is contained in a small area, you might find that choosing an appropriate projection and using GEOMETRY is the best solution, in terms of performance and functionality available.


 * http://postgis.org/documentation/manual-2.0/ST_GeomFromText.html

ST_GeomFromText — Return a specified ST_Geometry value from Well-Known Text representation (WKT).

--- converting lat lon coords to geometry SELECT AddGeometryColumn ('public','table','geom','4326','POINT',3); UPDATE sometable SET geom = ST_GeomFromText('POINT(-71.064544 42.28787)',4326);


 * http://postgis.org/documentation/manual-2.0/ST_GeomFromEWKT.html

ST_GeomFromEWKT — Return a specified ST_Geometry value from Extended Well-Known Text representation (EWKT).

UPDATE sometable SET geom = ST_GeomFromEWKT('SRID=4326;POINT(-71.064544 42.28787)');

If you are building points from long lat coordinates and care more about performance and accuracy than OGC compliance, use ST_MakePoint or OGC compliant alias ST_Point.


 * http://postgis.org/documentation/manual-2.0/ST_MakePoint.html

ST_MakePoint — Creates a 2D,3DZ or 4D point geometry.

--Return point marked as WGS 84 long lat UPDATE sometable SET geom = ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829, z),4326);


 * http://postgis.org/documentation/manual-2.0/ST_Point.html

ST_Point — Returns an ST_Point with the given coordinate values. OGC alias for ST_MakePoint.

UPDATE sometable SET geom = ST_SetSRID(ST_Point(-71.1043443253471, 42.3150676015829),4326);

SQL

 * http://postgis.org/documentation/manual-2.0/using_postgis_dbmanagement.html#id564650

Edit Waypoints.csv:

SET CLIENT_ENCODING TO UTF8; SET STANDARD_CONFORMING_STRINGS TO ON; BEGIN; UPDATE public.findspot SET geom = ST_SetSRID(ST_MakePoint(23.432615, 40.541465, 149.7),4326) WHERE id = 1; UPDATE public.findspot SET geom = ST_SetSRID(ST_MakePoint(23.432544, 40.540410, 158.7),4326) WHERE id = 2; UPDATE public.findspot SET geom = ST_SetSRID(ST_MakePoint(23.432638, 40.541472, 150.0),4326) WHERE id = 3; UPDATE public.findspot SET geom = ST_SetSRID(ST_MakePoint(23.432472, 40.541471, 144.5),4326) WHERE id = 4; COMMIT;

GDAL/OGR

 * http://www.gdal.org/ogr2ogr.html
 * http://www.surfaces.co.il/manipulating-gps-tracks-in-spatialite/

ogr2ogr converts simple features data between file formats.

This program can be used to convert simple features data between file formats performing various operations during the process such as spatial or attribute selections, reducing the set of attributes, setting the output coordinate system or even reprojecting the features during translation.