[英]How can I correctly set the value of a field having type point in a MySql database?
I am not so into geospatial data and I have the following problem. 我不太喜欢地理空间数据,但存在以下问题。 I am using MySql and I am finding some difficulties trying to add the value of a field having point as type in this table rows. 我正在使用MySql,并且在尝试添加此表行中类型为point的字段的值时遇到了一些困难。
I have a table like this: 我有一张这样的桌子:
CREATE TABLE MarketDetails (
id BigInt(20) NOT NULL AUTO_INCREMENT,
localization_id BigInt(20) NOT NULL,
market_name VarChar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
market_cod VarChar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci,
description Text CHARACTER SET latin1 COLLATE latin1_swedish_ci,
gps point,
PRIMARY KEY (
id
)
)
As you van see this table contains the gps field having type point . 如您所见,该表包含类型为point的gps字段。 It seems to me that this data type is the best for store the GPS coordinates of a point. 在我看来,此数据类型最适合存储点的GPS坐标。
I have tryied to insert the values of this field using an IDE but it doesn't works...using my IDE I can insert all the other fields value but not the gps field value. 我试图使用IDE插入该字段的值,但是它不起作用...使用我的IDE,我可以插入所有其他字段值,但不能插入gps字段值。
How can I try to do it manually? 如何尝试手动进行? For example I have inserted this record: 例如,我插入了以下记录:
id localization_id market_name market_cod description gps
---------------------------------------------------------------------------------------------------------------
1 31 Kibuye cod001 Kibuye Village Market
How can I correctly create an update SQL query that update this record setting the gps field with these coordinates?: 如何正确创建一个更新 SQL查询,以使用以下坐标设置此gps字段来更新此记录?:
lat: -2,17897
long: 29,371491
I was trying something like this but it doesn't works: 我正在尝试这样的事情,但它不起作用:
UPDATE MarketDetails
SET gps = Point(ST_GeomFromText('POINT(1 1)'))
WHERE id = 1
I obtain this error message: 我收到此错误消息:
#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE id = 1' at line 2
What is wrong? 怎么了? What am I missing? 我想念什么? How can I fix this issue? 如何解决此问题?
if you are able to import the lat/lon values in separated columns as eg DOUBLE data type, then you can try this: 如果您能够在分开的列中导入纬度/经度值,例如DOUBLE数据类型,则可以尝试以下操作:
ALTER TABLE table ADD coords Point;
UPDATE table SET coords = POINT(lat, lon);
In this case I added the column "coords" as a POINT type. 在这种情况下,我将“ coords”列添加为POINT类型。 Then update the coords column by using the lan and lon columns. 然后,使用lan和lon列更新coords列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.