Convert lat/long from EPSG:27700 to EPSG:4326

1,471 views
Skip to first unread message

MrChimp

unread,
Mar 22, 2012, 7:41:26 AM3/22/12
to MapInfo-L
I have a table in EPSG:27700. I am trying to save the centroid
coordinates in columns in this table in order to show them on another
map which uses EPSG:4326.

Saving a copy of the table with a different projection would solve the
problem but I would much rather do this without creating extra files.
This will be a recurring job so I'm trying to make it as streamlined
as possible. Ideally I'd like to make an "update coords columns"
function in MapBasic.

My problem is: how can I convert a single pair of coordinates from one
coordinate system to another?

Greg

unread,
Mar 22, 2012, 8:58:23 AM3/22/12
to mapi...@googlegroups.com
If you're doing this in MapBasic, simply set the coordinate system to EPSG:4326 using the appropriate set coordsys statement.  Then, when you return the coordinates of an object they'll be in the new coordinate system.

HTH

Greg.

MrChimp

unread,
Mar 22, 2012, 10:32:28 AM3/22/12
to MapInfo-L
Thanks Greg. That sounds nice and easy! I must be missing something
though as it doesn't seem to be working quite right...

The code I am using is as follows:


Declare Sub Main

Sub Main
Print "----------------------------------------------"
Print "EPSG:27700 = " & EPSGToCoordSysString$("EPSG:27700")
Print "EPSG:3857 = " & EPSGToCoordSysString$("EPSG:3857")

' Set coord sys to EPSG:27700 and save coords (1)
run command("Set " + EPSGToCoordSysString$("EPSG:27700"))
Update test1 set xref_1 = CentroidX(Obj)
Update test1 set yref_1 = CentroidY(Obj)

' set to EPSG:3857 and save coords (2)
Run command("Set " + EPSGToCoordSysString$("EPSG:3857"))
Set Map XY Units "degree" ' No effect - see comments
below...
Update test1 set xref_2 = CentroidX(Obj)
Update test1 set yref_2 = CentroidY(Obj)

Note "done."
End Sub

xref_1 and yref_1 are populated correctly. (values are in the region
of 348,000, 175,000).
xref_2 and yref_2 should be roughly 51.5, -2.6. However they are off
by a long way (-314,193.85, 6,706,415.24). By the look if they are
still in meters rather than degrees. The only way I can see of
changing the coordinate units to degrees is with "Set Map" which
doesn't appear to have any effect.

Any ideas?
Thanks again

David R Sherrod

unread,
Mar 22, 2012, 10:41:43 AM3/22/12
to mapi...@googlegroups.com

I can't help with the MapBasic, but I might ask about the conceptual steps in the hope that sparks a solution for you.

Using the pulldown menus the steps would be
(1) Change the coord sys of the map window to the scheme that drives your updating.
(2) Set Coordsys Window FrontWindow()
(3) Update the columns in your table that you entitled 4326_lat and 4326_long

Is that correct?
-----------------------------------------



From: MrChimp <chim...@gmail.com>
To: MapInfo-L <mapi...@googlegroups.com>
Date: 03/22/2012 07:32 AM
Subject: [MI-L] Re: Convert lat/long from EPSG:27700 to EPSG:4326
Sent by: mapi...@googlegroups.com





--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en


MrChimp

unread,
Mar 22, 2012, 10:53:21 AM3/22/12
to MapInfo-L
Pretty much. I am changing the session coordsys rather than the map
coordsys though. Changing the map coordsys doesn't appear to have any
effect.

It's basically a two step process:

-Set Session coordsys
-Update columns



On Mar 22, 2:41 pm, David R Sherrod <dsher...@usgs.gov> wrote:
> I can't help with the MapBasic, but I might ask about the conceptual steps
> in the hope that sparks a solution for you.
>
> Using the pulldown menus the steps would be
> (1) Change the coord sys of the map window to the scheme that drives your
> updating.
> (2) Set Coordsys Window FrontWindow()
> (3) Update the columns in your table that you entitled 4326_lat and
> 4326_long
>
> Is that correct?
> -----------------------------------------
>
> From:
> MrChimp <chimp...@gmail.com>
> To:
> MapInfo-L <mapi...@googlegroups.com>
> Date:
> 03/22/2012 07:32 AM
> Subject:
> [MI-L] Re: Convert lat/long from EPSG:27700 to EPSG:4326
> Sent by:
> mapi...@googlegroups.com
>

Greg

unread,
Mar 22, 2012, 10:57:26 AM3/22/12
to mapi...@googlegroups.com
Not too sure but I think it migth be to do with setting the coordinate system using the run command, which i don't think actual sets the coordinate system for the current Mapbasic session.  Have you tried doing something like this: Set coordsys EPSGToCoordSysString$("EPSG:27700")

I'm not familiar with the EPSGToCoordSysString$("EPSG:27700") statement, but look at the MB guide I think you should be able to use it liek this.

HTH

Greg.

MrChimp

unread,
Mar 22, 2012, 11:09:50 AM3/22/12
to MapInfo-L
EPSGToCoordSysString$() produces a MapInfo coordsys string from a
given EPSG code. The result is something like "CoordSys Earth
Projection 8, 79, "m", -2, 49, 0.9996012717, 400000, -100000 Bounds
(-7845061.1011, -15524202.1641) (8645061.1011, 4470074.53373)"

The Set command only accepts coordsys clauses. You can't provide
expressions, functions or even strings at runtime. Your example will
not compile.

You may be onto something though... "Run command" is a runtime thing,
so maybe it it is passing that command out to the MapInfo application
rather than setting the coordsys that is used by my MapBasic program?
If that is the case I'm not sure how to get around it...

Andy Harfoot

unread,
Mar 22, 2012, 11:20:14 AM3/22/12
to mapi...@googlegroups.com
Have a look at the Coordinate Extractor Tool, in the Tool Manager by default.
-- 
Andy Harfoot

GeoData Institute
University of Southampton
Southampton
SO17 1BJ

Tel:  +44 (0)23 8059 2719
Fax:  +44 (0)23 8059 2849

www.geodata.soton.ac.uk

MrChimp

unread,
Mar 22, 2012, 12:07:57 PM3/22/12
to MapInfo-L
Thanks Andy, I hadn't spotted that tool and it look perfect. However
it is giving me the same numbers as in my first reply to Greg.

Jake


On Mar 22, 3:20 pm, Andy Harfoot <a...@geodata.soton.ac.uk> wrote:
> Have a look at the Coordinate Extractor Tool, in the Tool Manager by default.
> MrChimp wrote:I have a table in EPSG:27700. I am trying to save the centroid coordinates in columns in this table in order to show them on another map which uses EPSG:4326. Saving a copy of the table with a different projection would solve the problem but I would much rather do this without creating extra files. This will be a recurring job so I'm trying to make it as streamlined as possible. Ideally I'd like to make an "update coords columns" function in MapBasic. My problem is: how can I convert a single pair of coordinates from one coordinate system to another?-- Andy Harfoot GeoData Institute University of Southampton Southampton SO17 1BJ Tel: +44 (0)23 8059 2719 Fax: +44 (0)23 8059 2849www.geodata.soton.ac.uk

Andy Harfoot

unread,
Mar 22, 2012, 1:22:31 PM3/22/12
to mapi...@googlegroups.com
Hi Jake,

Looking at the code you posted in your reply to Greg you are setting the session coordsys to EPSG:3857 - this is Google Mercator which has units in metres, so the values you were obtaining are as expected. If you want WGS84 Lat/Lon coordinates then use EPSG:4326

Andy

MrChimp

unread,
Mar 22, 2012, 1:25:08 PM3/22/12
to MapInfo-L
Aha! Thank you very much indeed!


On Mar 22, 5:22 pm, Andy Harfoot <a...@geodata.soton.ac.uk> wrote:
> Hi Jake,
> Looking at the code you posted in your reply to Greg you are setting the session coordsys to EPSG:3857 - this is Google Mercator which has units in metres, so the values you were obtaining are as expected. If you want WGS84 Lat/Lon coordinates then use EPSG:4326
> Andy
> MrChimp wrote:Thanks Andy, I hadn't spotted that tool and it look perfect. However it is giving me the same numbers as in my first reply to Greg. Jake On Mar 22, 3:20 pm, Andy Harfoot<a...@geodata.soton.ac.uk>wrote:Have a look at the Coordinate Extractor Tool, in the Tool Manager by default. MrChimp wrote:I have a table in EPSG:27700. I am trying to save the centroid coordinates in columns in this table in order to show them on another map which uses EPSG:4326. Saving a copy of the table with a different projection would solve the problem but I would much rather do this without creating extra files. This will be a recurring job so I'm trying to make it as streamlined as possible. Ideally I'd like to make an "update coords columns" function in MapBasic. My problem is: how can I convert a single pair of coordinates from one coordinate system to another?-- Andy Harfoot GeoData Institute University of Southampton Southampton SO17 1BJ Tel: +44 (0)23 8059 2719 Fax: +44 (0)23 8059 2849www.geodata.soton.ac.uk-- Andy Harfoot GeoData Institute University of Southampton Southampton SO17 1BJ Tel: +44 (0)23 8059 2719 Fax: +44 (0)23 8059 2849www.geodata.soton.ac.uk

Lars I. Nielsen (GisPro)

unread,
Mar 23, 2012, 2:19:33 AM3/23/12
to mapi...@googlegroups.com
Using a single "Run Command" will definitely not work, as it runs in the interactive/MB window session, not the session in which the mbx runs. They're separate.

But EPSG:4326 is just Coordsys Earth 1,104, so that's pretty easy to set in MB.

So to return to your original question: how to save copies of the centroid coordinates in a different projection:

Set Coordsys Earth Projection 1,104
Update MyTable set CX = CentroidX(OBJ), CY = CentroidY(OBJ)

You can also issue both of these commands with Run Command, which would facilitate using the EPSGToCoordSysString$() function:

Run Command "Set " + EPSGToCoordSysString$("EPSG:4326")
Run Command "Update MyTable set CX = CentroidX(OBJ), CY = CentroidY(OBJ)"

The two methods are not identical, there are subtle differencies, but they probably don't matter much here.


But I'm a little puzzled about your sentence "to show them on another map which uses EPSG:4326"

Do you need to show the centroids as points in a map, or do you need to label with them ?

Pro of course handles projection-to-projection conversions when viewing tables i a mapper, so the first case is as easy as creating a table with centroids:

'create a copy as a temp table in 1,104 (Commit As)
Update TempTable Set OBJ = Centroid(OBJ)
'add to map


Best regards / Med venlig hilsen
Lars I. Nielsen
GIS & DB Integrator
GisPro
Reply all
Reply to author
Forward
0 new messages