postgresql Postgis:错误:解析错误 - 几何图形无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25861052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:37:05  来源:igfitidea点击:

Postgis : ERROR: parse error - invalid geometry

postgresqlpostgis

提问by user3129056

I'm using POSTGIS="2.0.1 r9979" and facing following error :

我正在使用 POSTGIS="2.0.1 r9979" 并面临以下错误:

ERROR:  parse error - invalid geometry
HINT:  "POINT(18.570275,7" <-- parse error at position 17 within geometry
CONTEXT:  SQL function "st_dwithin" during inlining

while trying sql :

尝试 sql 时:

 SELECT addressid FROM maddress 
  WHERE ST_DWithin(geocode, 'POINT(20.0924758 72.7341809 19.137381,72.837223)' , 100.0);

i wish to select the addresses between the points mentioned in query.

我希望选择查询中提到的点之间的地址。

I have checked syntax and as per syntax i have put values in query.Please let me know the correction.

我检查了语法,并根据语法在查询中输入了值。请让我知道更正。

采纳答案by John Powell

If you are trying to find points that are between two points, you probably need to use ST_DWithin twice, so that you get the points that are in the intersection of a circle based on point 1 and a circle based on point 2, eg,

如果您试图找到两点之间的点,您可能需要使用 ST_DWithin 两次,以便您获得基于点 1 的圆和基于点 2 的圆的交点中的点,例如,

SELECT addressid FROM maddress 
WHERE ST_DWithin(geocode, ST_MakePoint(20.0924758, 72.7341809), 100.0)
AND ST_DWithin(geocode, ST_MakePoint(19.137381, 72.837223), 100.0);

Note that the units are in SRID units, which in your case appears to be 4326, so you might want to convert your coordinates to meters, use a geography data type, so the distance will be in meters, or convert the distance to degrees -- there are various choices. I'm sure you have seen the ST_DWithin docsthat explains these options. You might also want to consider the use_spheroidparameter.

请注意,单位是 SRID 单位,在您的情况下似乎是 4326,因此您可能希望将坐标转换为米,使用地理数据类型,因此距离将以米为单位,或将距离转换为度 - - 有多种选择。我确定您已经看过解释这些选项的ST_DWithin 文档。您可能还需要考虑use_spheroid参数。

Instead of ST_MakePointabove, you can also use ST_GeomFromTextwhich takes the form 'POINT(x y)' as you are originally had an optionally allows you to specify the SRID, eg, using 4326, you can also write the query as:

除了ST_MakePoint上述之外,您还可以使用ST_GeomFromTextwhich 形式为“POINT(xy)”,因为您最初有一个可选的允许您指定 SRID,例如,使用 4326,您还可以将查询编写为:

SELECT addressid FROM maddress 
WHERE ST_DWithin(geocode, ST_GeomFromText('POINT(20.0924758 72.7341809)',4326), 100.0)
AND ST_DWithin(geocode, ST_GeomFromText('POINT(19.137381 72.837223)', 4326), 100.0);

EDITFollowing comments from OP, it turns out that geocode is not a geometry column. You can fix this by running.

编辑根据 OP 的评论,事实证明地理编码不是几何列。您可以通过运行来解决此问题。

ALTER TABLE maddress ADD COLUMN geom GEOMETRY  (POINT, 4326);
UPDATE maddress set geom=ST_MakePoint(lng,lat);
CREATE INDEX ix_spatial_geom on maddress using gist(geom);

You will then need to use geom instead of geocode in the queries above. I am assuming that your points are in 4326.

然后,您将需要在上述查询中使用 geom 而不是地理编码。我假设你的分数是 4326。

回答by Hala

I hade the same error when using:

我在使用时遇到了同样的错误:

select ST_GeomFromText('POINT(-27.75 ,114.75)', 3857)

instead of:

代替:

select ST_GeomFromText('POINT(-27.75 114.75)', 3857)

You need to remove the comma separator.

您需要删除逗号分隔符。

回答by Neldo Marcelino

Go to Migrations and change the type of field if you use Leaflet:

如果您使用传单,请转到迁移并更改字段类型:

  • django.contrib.gis.db.models.fields.MultiPointField
  • django.contrib.gis.db.models.fields.MultiPointField

To

  • from djgeojson.fields import MultiPointField
  • 从 djgeojson.fields 导入 MultiPointField