[OpenLayers-Users] transform providing wrong coordinates

Dash jimlug at co.clackamas.or.us
Wed Oct 2 17:12:32 PDT 2013


Well, I'm absolutely stumped.  I'm trying to transform coordinates (using
OpenLayers.LonLat.transform) from state plane (EPSG:2913) to wgs84
(EPSG:4326) and my results are totally wrong.  First I thought maybe I don't
have the definition in my proj4js library but upon further investigation I
do have it.  Just to make sure, I rebuilt the proj4js.js file.  Then I
thought it might be the customization of the OpenLayer.js file so I switched
to the full version.  Still no luck.

So, I decided to use the proj4js API to transform the coordinates.  Well,
that did not work either.  Below is an example of what I'm working with and
the methods I've tried.  Any help would be greatly appreciated.  

Some additional info - During the map setup I've specified my projection as
EPSG:2913.  Everything works (spatial functions and queries) except the
transform command.  I've also tested this using PostGIS and the transform
function works just fine.  We don't use the ST_Transform function because we
are displaying scrolling coordinates and don't want to make constant queries
to the database.

// Original code
var point = this.map.getLayerPxFromViewPortPx(event.xy);
var xy = this.map.getLonLatFromPixel(point);
document.getElementById(div).innerHTML = "X:" + xy.lon + ", Y:" + xy.lat;
var coord = xy.clone();
var lonlat = coord.transform(new OpenLayers.Projection("EPSG:2913"), new
OpenLayers.Projection("EPSG:4326"));
document.getElementById(div).innerHTML += " Long:" + lonlat.lon + ", Lat:" +
lonlat.lat; 

// Test scenario 1
var fromProjection = new OpenLayers.Projection("EPSG:2913");
var toProjection = new OpenLayers.Projection("EPSG:4326");
var position = new
OpenLayers.LonLat(547737.861,76641613.755).transform(fromProjection,
toProjection);

// Test scenario 2
Proj4js.defs["WGS84"] = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
Proj4js.defs["EPSG:2913"]= "+title=Stateplane +proj=lcc +lat_1=46
+lat_2=44.33333333333334 +lat_0=43.66666666666666 +lon_0=-120.5
+x_0=2500000.0001424 +y_0=0 +ellps=GRS80 +units=ft +no_defs";
var source = new Proj4js.Proj("EPSG:2913");
var dest = new Proj4js.Proj("WGS84");
var p = new Proj4js.Point(76641613.755,547737.861);
var newproj = Proj4js.transform(source,dest,p);

Here is what the output looks like: x=-12.063461164796582,
y=-80.73484965308273

Thanks.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/transform-providing-wrong-coordinates-tp5081537.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list