MySQL Spatial - Convert from SRID 31287 to 4326

笑着哭i 提交于 2019-12-10 18:10:28

问题


In MySQL I have a a database with around 100 tables.

They all contain a column called ´shape´, this is a polygon type field.

It contains information in what I believe (st_srid returns 1, but it's wrong) is SRID 31287.

I would like to convert it to SRID 4326, how would I go about to do this?


回答1:


You have two problems here.

  1. Your internal representation is wrong, it's SRID 1, and it should be SRID 31287. Changing an internal representation is possible in every database: MySQL will get a mutator for it in version 8, ST_SRID, PostGIS has ST_SetSRID
  2. You need to actually convert from SRID 31287 to SRID 4326. This is possible ONLY in PostGIS. Neither MySQL nor Microsoft SQL can reproject an SRID.

To tackle the first problem in PostGIS, you'd use ST_SetSRID, and to tackle the second problem you'd use ST_Transform.




回答2:


This worked for me

(For MySQL)

UPDATE Table SET SpatialColumn = ST_GeomFromText(ST_AsText(SpatialColumn), 4326);



回答3:


In MySQL it looks like this:

UPDATE `table name` SET `column name` = ST_GeomFromText(ST_AsText(`column name`), 4326);

Hope this helps




回答4:


I can only hope this will help you (either directly or as a pointer) as its an answer for SQL Server, but how about...

UPDATE Table SET SpatialColumn = Geometry::STGeomFromText(SpatialColumn.STAsText(), 4326);

Naturally, you can swap Geometry for Geography if you're using Geography columns. You'll need to replace Table with your table name and SpatialColumn with the name of your Spatial Column.

NOTE: This assumes your SRID of 31287 defines coordinates as decimal latitude / longitude values.



来源:https://stackoverflow.com/questions/21877179/mysql-spatial-convert-from-srid-31287-to-4326

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!