简体   繁体   English

如何正确设置MySql数据库中具有类型point的字段的值?

[英]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 . 如您所见,该表包含类型为pointgps字段。 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.

相关问题 如何在MySql数据库表中正确设置“点”字段的值? - How to correctly set the value of a “point” field into a MySql database table? 如何将“空”POINT() 几何值输入到 POINT 类型的 MySQL 字段中? - How do I enter an “empty” POINT() geometry value into a MySQL field of type POINT? 我如何在mysql字段中将默认值设置为NULL - how i can set default value in mysql field to be NULL 如何在具有特定别名的表上正确选择MySql函数值? - How can I correctly select a MySql function value on a table having a specific alias? 如何在CodeIgniter 2中扩展Doctrine 2来处理MySQL空间(“点”字段类型)? - How can I extend Doctrine 2 to handle MySQL spatial (“point” field type) in CodeIgniter 2? 如何在PHP中处理MySQL POINT()字段? - How can I handle a MySQL POINT() field in PHP? 如何将“值”字段的值放入数据库中输入类型为复选框的形式? - how can i put the value of “value” field in a form where input type is checkbox from database? mysql-如何在字段中选择具有0或1值的记录集,仅在值存在的情况下才选择值1的记录? - How to select in a set of records having 0 or 1 value in a field, the record with value 1 only if exists, in mysql? 如何从 MySQL 数据库获取最后一个插入值并更新 Access 中的字段? - How can I get the last insert value from MySQL database and update a field in Access? 我怎样才能保存我的价值<input type='checkbox'>使用 Laravel 5.7 代码到 MySQL 数据库? - How can I save the value of my <input type='checkbox'> to MySQL Database with laravel 5.7 code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM