[postgis-users] Transformation problem using transform()
Mark Cave-Ayland
m.cave-ayland at webbased.co.uk
Mon May 8 04:16:37 PDT 2006
> From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Marc
Angelo
> Sent: 04 May 2006 04:42
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] Transformation problem using transform()
>
> Hi Everyone
> Thank you very much for your answer's. Unfortunately I am very new to all
the GIS stuff
> so I'm flying blind most of the time. Even the questions you have asked me
have actually
> helped my understanding.
>
> What I'll d here is explain a little more of what I am trying to achieve
therefore
> isolating what I'm doing wrong maybe more apparent. The following is the
version() I am > using (Windows):-
>
> "POSTGIS="1.1.1" GEOS="2.2.1-CAPI-1.0.1" PROJ="Rel. 4.4.9, 29 Oct 2004"
USE_STATS"
>
>
> What I have been doing is carrying out the following SQL INSERT into
Postgres. The text
> Lon/Lat are only there for me while I'm testing and try to get a better
idea of what is
> happening. The E00.... number is an rfid tag id. The Lat and Long come
from a GPS
> reading using WGS84 datum
>
> "INSERT INTO waypoints(rfid,
date,text_lat,text_long,position)VALUES('E004010001CC1B0F',
> '04May2006','-45.879185','170.50196',GeometryFromText('POINT(170.50196
-45.879185)',
> 4326))"
>
> Next is the record that is created:-
>
> "8";"E004010001CC1B0F";"2006-05-02";"-
>
45.879185";"170.50196";"0101000020E6100000CEFC6A0E105065401F11532289F046C0"
>
> The 8 is the SERIAL Primary key.
>
>
> Now that this is sitting nicely in the Database I am connecting to it and
I want to be
> able to place the "waypoint" in a map (I'm playing with a .Net component
called
> mapWindow) in a projection of the user's choice(ie into the projection of
the
> shapefile). My current level of understanding is I understand the
difference between a
> datum and projection but that's about it. I have bought a small book
called "Basic GIS
> Coordinates" which I'm working through:)
> I am connecting to the database using NPGSQL data connector.
>
> I have also tried overlaying the above record in QGIS over a NZ coastline
shape file
> using NZTM and NZMG projections but the waypoint is several hundred miles
to the South
> of where it should be.
>
> I suppose Rene is correct in asking what am I trying to do. I thought that
if I had a
> NZGD 2000 (for example) shape file, to show the above waypoint on a shape
file, I would
> need to reproject the waypoint into the NZGD 2000 proection first. I
realise this is
> probably where I am going wrong.
>
> Mark - I copied the functions from your response into the arbituary SQL
window (eg
> select asewkt(transform(geomfromtext('POINT(170.50196
> -45.879185)', 4326), 2029));) and got the same result as in your email
> ("SRID=2029;POINT(-2815521.73265803 -12147021.3686016)"). This tells me I
have things in
> the correct order now :) but what is -2815521.73265803 -12147021.3686016 ?
Is this the
> coordinate projected into x, y coords in NAD27(76) projection? (by the
way, I tested all
> the functions from your response and they all worked)
>
> Again I apologise for these simplistic questions. I know once I get my
head around
> projections/datums and the various functions I'll be fine.
>
> Thank you in advance for any assistance that can be given.
>
> Cheers
> Marc
Hi Marc,
The best way to think about projections is to imagine that a SRID contains
information about the units used for the X and Y coordinates. For example,
if I have a database table which contains a column of representing lengths
of blocks of wood such as 10.0, 5.1, 111320 then comparing them is useless
unless I know which units they are in (such as mm, cm, or inches) and that
they are all measured in the same unit.
So a SRID contains this information in terms of map projections; it defines
characteristics such as the spheroid used to map the Earth; the origin (0,
0) point for the projection and its units (decimal degrees, feet, metres).
The SRID is stored along with the geometry (effectively specifying its
units) so that it becomes possible to use the transform() function to
convert on-the-fly from the stored coordinates system to any other.
Therefore if you are converting coordinates from one projection to another
using PostGIS, you need to know three things: i) the coordinates, ii) the
SRID (and hence coordinate system) the coordinates were captured with, and
iii) the SRID (and hence coordinate system) of the output coordinate system
you require.
>From your email, it looks as if you're capturing data in WGS84 (lat/lon)
format and then trying to view the information on a NZGD2000 shapefile. We
already know that the SRID for lat/lon is 4326, but what about the SRID for
NZGD2000? Well the easy way to search through the PostGIS spatial_ref_sys
table to find the correct SRID. For example, running the following SQL will
locate SRIDs for all projections containing the text NZGD:
select * from spatial_ref_sys where srtext ilike '%NZGD%';
As an example, say that we determine the correct SRID for your NZGD
shapefile is 2105 using the SQL above. In order to convert your lat/lon
point from lat/lon into NZGD format to superimpose it on top of your
shapefile then you would do something like:
postgis=# select asewkt(transform(geomfromtext('POINT(170.50196
-45.879185)', 4326), 2105));
asewkt
-----------------------------------------------------
SRID=2105;POINT(69159.7892062111 -208236.291585477)
(1 row)
Note that some data suppliers can be a little bit lax about documenting the
exact parameters for a projection; however you can experiment by doing a
transform() for each possible SRID and superimposing the transformed on your
shapefile. Given that you know the area of your data, it should be fairly
easy to determine the correct SRID by using a visual check.
Kind regards,
Mark.
------------------------
WebBased Ltd
17 Research Way
Plymouth
PL6 8BT
T: +44 (0)1752 797131
F: +44 (0)1752 791023
http://www.webbased.co.uk
http://www.infomapper.com
http://www.swtc.co.uk
This email and any attachments are confidential to the intended recipient
and may also be privileged. If you are not the intended recipient please
delete it from your system and notify the sender. You should not copy it or
use it for any purpose nor disclose or distribute its contents to any other
person.
More information about the postgis-users
mailing list