[英]Using inverse function with transforming geometry into coordinates results into mixed SRID error
I'm using postgres with postig extension. 我正在使用带postig扩展名的postgres。 I have coordinates which I put into following postgis function:
我将坐标放入以下postgis函数中:
select ST_SetSRID(ST_point(18.533935546875, 48.23199134320962),4674)
As a result, I get geometry type: 01010000204212000000000000B08832402D0570E4B11D4840 结果,我得到的几何类型为:01010000204212000000000000B08832402D0570E4B11D4840
When I want to do inverse action 当我想做逆向动作时
select st_x(st_transform(way,4326)), st_y(st_transform(way,4326)) from planet_osm_point where way ='01010000204212000000000000B08832402D0570E4B11D4840'
I get error: 我得到错误:
ERROR: Operation on mixed SRID geometries
********** Error **********
ERROR: Operation on mixed SRID geometries
SQL state: XX000
What can be the problem? 可能是什么问题?
The problem is somewhat described in the error message: you are trying to find equal geometries in planet_osm_point.way
, but they have a different SRID than 4674. It is effectively this: 错误消息中对该问题进行了某种描述:您试图在
planet_osm_point.way
找到相同的几何,但是它们的SRID与4674不同。实际上,这是这样的:
SELECT ST_SetSRID(ST_Point(0, 0), 4674) = ST_SetSRID(ST_Point(0, 0), 4326);
So you would need to pick a common SRID, and transform one to the other, ie 因此,您需要选择一个通用的SRID,然后将其中一个转换为另一个
SELECT ST_SetSRID(ST_Point(0, 0), 4674) =
ST_Transform(ST_SetSRID(ST_Point(0, 0), 4326), 4674);
except I don't recommend using the =(geometry, geometry)
operator since it requires identical geometries, which are not very common with floating point errors after transforming. 除非我不建议使用
=(geometry, geometry)
运算符,否则它需要相同的几何,这在转换后对于浮点错误不是很常见。
A better approach is to find all the way
geometries within a small margin of error distance using ST_DWithin : 更好的办法是找到所有的
way
使用误差距离的小幅度内的几何形状ST_DWithin :
select st_x(st_transform(way,4326)), st_y(st_transform(way,4326))
from planet_osm_point
where ST_DWithin(
way,
ST_Transform(
ST_SetSRID(ST_Point(18.533935546875, 48.23199134320962), 4674),
<way_SRID>),
1e-6);
Here, it transforms the point into the SRID of way
(you never specified, so update <way_SRID>
), then find anything within 1e-6 degrees distance away (about 10 cm). 在这里,它将点转换为
way
的SRID(您从未指定过,因此请更新<way_SRID>
),然后在1e-6度距离(约10厘米)内找到任何东西。 Increase it if you want to collect more nearby way
points. 如果您想收集更多附近的
way
点,请增加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.