3

I have an OpenLayers map with a vector layer to add points on. I'm using Google Maps as the base layer. After the point is added, I need to store the data in my database as lat/long and x/y. Can I transform the projection of the x/y points or convert the lat/long to x/y? The x/y that is on the point is in spherical mercator so it doesn't work for me.

Update: I'm not having any trouble converting the x/y to lat/long. I want to convert the x/y that I have to a different projection. I'm not sure that's the right terminology, but I need to convert the x/y values.

Update: The SRID I need is 3734. When I drop the point, the x/y is like: x: -9058948.6891836 y: 5035248.6338434

But what I need looks more like: x: 2282175.42 y: 545126.58

I'm also using PostGIS so if this is possible to do with PostGIS I'm open to that also.

2
  • To which particular projection do you want to project to? What is its SRID? Mar 7, 2013 at 6:48
  • I added more details above.
    – bl8rchk
    Mar 7, 2013 at 13:17

3 Answers 3

3

There's a library called proj4js can do this job, and you can use it together with OpenLayers. Have a look at OpenLayers Projection class.

2

As per your update, a PostGIS solution would work as well;

You need ST_Transform to project in the data Postgis from EPSG 3857 to EPSG 3734

SELECT ST_AsText( ST_Transform(
ST_GeomFromText('POINT(-9058948.6891836,5035248.6338434)',3857),3734)) As wgs_geom;
1
  • This worked! I'm very new to PostGIS so I didn't even think to use it to do the conversion.
    – bl8rchk
    Mar 7, 2013 at 14:51
2

Try to do more research before posting questions. I don't know openlayers, but I found the answer in googling your title "OpenLayers X/Y Projection" in 30 sec. See https://stackoverflow.com/questions/2601745/how-to-convert-vector-layer-coordinates-into-map-latitude-and-longitude-in-openl

var toProjection = new OpenLayers.Projection("EPSG:4326");
var fromProjection = new OpenLayers.Projection("EPSG:900913");
var convertedPoint = new OpenLayers.LonLat(x, y);
convertedPoint.transform(fromProjection, toProjection);
1
  • I'm not having any trouble converting the x/y to lat/long. I want to convert the x/y that I have to a different projection. I'm not sure that's the right terminology, but I need to convert the x/y values.
    – bl8rchk
    Mar 7, 2013 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.