Php 将空间数据插入MySQL数据库

Php 将空间数据插入MySQL数据库,php,mysql,sql,spatial,spatial-query,Php,Mysql,Sql,Spatial,Spatial Query,我尝试通过以下方式将数据从PHP插入point()数据类型列: INSERT INTO table (coordinates) VALUES ("48.20 14.80"); 或 然后在每次插入或更新之前应用触发器: BEGIN SET @lat = SUBSTRING(NEW.coordinates, 1, LOCATE(' ', NEW.coordinates)); SET @lng = SUBSTRING(NEW.coordinates, LOCATE(' ', NEW.coordina

我尝试通过以下方式将数据从PHP插入point()数据类型列:

INSERT INTO table (coordinates) VALUES ("48.20 14.80");

然后在每次插入或更新之前应用触发器:

BEGIN
SET @lat = SUBSTRING(NEW.coordinates, 1, LOCATE(' ', NEW.coordinates));
SET @lng = SUBSTRING(NEW.coordinates, LOCATE(' ', NEW.coordinates) + 1);
SET @coor = PointFromWKB(POINT(@lat, @lng));
SET NEW.coordinates = @coor;
END

但它的回报是:

SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field
你们有谁知道问题出在哪里吗?谢谢。

你最好的选择是

  • 将柱坐标拆分为两个柱,例如coord_lat和coord_long,在将数据插入表格之前,将坐标值拆分为两个变量 或 2.将坐标列数据类型更改为文本。

    尝试以下操作:

    一,-

    2-

     INSERT INTO table (coordinates) VALUES (ST_GeomFromText('POINT(48.20 14.80)'));
    

    有点晚了,但我为这个问题创造了这个解决方案

    $cord= $long." ".$lat;
    
    在插页上我用了这个。注:我使用codeigniter活动记录插入数据

    $this->db->set("coord",'geomfromtext("POINT("'."'$cord'".'")")',false);
    $this->db->insert("gisdata");
    
    希望能有帮助。
    干杯

    检查Coordinates的数据类型很好的解决方案,但我忘了提到我希望在该列上应用一个空间索引。它可以工作,但仅当我手动添加数据时。我不知道如何发送“原始”数据(应用程序基于框架),这些数据应该作为命令执行(INSERT中的ST_GeomFromText(value))。因此,我在这一行开始后立即添加了:SET NEW.coordinates=ST_GeomFromText(NEW.coordinates)。当然,这不起作用。不起作用,因为wait
    value
    应该是
    text
    。我可以与您联系吗?关于这个问题,我还有几个问题。是的,我已经完成了。
     INSERT INTO table (coordinates) VALUES (ST_GeomFromText('POINT(48.20 14.80)'));
    
    $cord= $long." ".$lat;
    
    $this->db->set("coord",'geomfromtext("POINT("'."'$cord'".'")")',false);
    $this->db->insert("gisdata");