[MetaCRS] Problems when reprojecting with Proj4js

Hugo hfpmartins at gmail.com
Fri Mar 4 09:21:03 EST 2011


Hello all,

I'm developing an application using GeoExt and Openlayers. I'm implementing
a widget that will allow the user to enter coordinates in several SRS and
the map gets zoomed to it while, at the same time, a vector feature is added
to a specific layer. However i'm getting strange values after reprojecting
the coordinates. I really need to use proj4js because some of the epsg
definitions for Portuguese SRS do not have the local transformation
parameters. For example, i wish to reproject from EPSG:20791 to EPSG:900913.
This is what i have done:

1. Included proj4js-combined.js in the web page

2. Created the SRS defintions:
Proj4js.defs["EPSG:20791"] = "+proj=tmerc +lat_0=39.66666666666666 +lon_0=1
+k=1 +x_0=0 +y_0=0 +ellps=intl +pm=lisbon +units=m
+towgs84=-288.885,-91.744,+126.244,-1.691,0.410,-0.211,-4.598";

Proj4js.defs["EPSG:900913"] = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";

3. Then i tried the following:

var mercator = new OpenLayers.Projection("EPSG:900913");
var hglipcc = new OpenLayers.Projection("EPSG:20791");
xcoord = 19120.326567
ycoord = -293121.903092
var coordMarker = new OpenLayers.Geometry.Point(xcoord, ycoord);
var coordMarkerRep = coordMarker.transform (hglipcc, etrs);
var searchCoord = new OpenLayers.LonLat(xcoord, ycoord);
var searchCoordRep =  searchCoord.transform(hglipcc, mercator);

Both returned the same wrong coordiantes: x= -881483.8794817993 and y=
-7.081154551613622e-10
where they should be x= -881320.416615 and y= 4442714.696599.

Also, i have tried to use the projection definitions and reproject
transformation directly from Proj4js and the returned results were exactly
the same.

Finally i have tried to reproject to EPSG:4326 and still, the output
coordinates are strange: it returned lon=-7.918504416434706 and lat=0 where
it should be lon=-7.917036 and lat=37.025879.

Is this a known problem or is it something i'm doing wrong? Any sugestions
are more than welcome!
Thanks in advance.

Best regards,
Hugo






3. Defined projections using new OpenLayers.Projection('EPSG:xxxxx');

4. the code used to reproject:

var coordMarker = new OpenLayers.Geometry.Point(xcoord, ycoord); //these
coords in epsg 27492

OpenLayers.Projection.transform(coordMarker, hg73ipcc, mercator);

The coordinates introduced were x= 19300.924567 and y=-293208.893092 and the
output was x=-1897829.842341831 and y=4442821.889195204. The expected output
should be x=-881320.416615 and y=4442714.696599

I've tried to reproject from epsg:27492 to wgs84 and also got wrong
coordinates returned.
Am i missing something here??? Any sugestions to solve this?

-- 
Hugo Martins
LabNT - ISEGI UNL
Campus de Campolide
1070-312 Lisboa
N 38°43'56.84", W 9°9'35.74"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/metacrs/attachments/20110304/46e05c71/attachment.html


More information about the MetaCRS mailing list