python postgis ST_ClosestPoint
我正在努力处理从我的 python 脚本发出的 SQL 命令。这是我到目前为止所尝试过的,第一个示例工作正常,但其余的则不然。
#working SQL = "SELECT ST_Distance(ST_Transform(ST_GeomFromText(%s, 4326),27700),ST_Transform(ST_GeomFromText(%s, 4326),27700));"
#newPointSQL = "SELECT ST_ClosestPoint(ST_GeomFromText(%s),ST_GeomFromText(%s));"
#newPointSQL = "SELECT ST_As_Text(ST_ClosestPoint(ST_GeomFromText(%s), ST_GeomFromText(%s)));"
#newPointSQL = "SELECT ST_AsText(ST_ClosestPoint(ST_GeomFromEWKT(%s), ST_GeomFromText(%s)));"
#newPointSQL = "SELECT ST_AsText(ST_Line_Interpolate_Point(ST_GeomFromText(%s),ST_Line_Locate_Point(ST_GeomFromText(%s),ST_GeomFromText(%s))));"
newPointData = (correctionPathLine,pointToCorrect) - ( MULTILINESTRING((-3.16427109855617 55.9273798550064,-3.16462372283029 55.9273883602162)), POINT(-3.164667 55.92739))
我的数据提取正常,因为第一个 sql 执行时成功。问题是当我使用 ST_ClosestPoint 函数时。 有人能注意到任何地方的滥用吗?我是否以错误的方式使用 ST_ClosetsPoint? 在最后一个示例中,我确实修改了我的数据(以防有人注意到)来运行它,但它仍然无法执行。
I am struggling with an SQL command issued from my python script. Here is what I have tried so far, the first example works fine but the rest do not.
#working SQL = "SELECT ST_Distance(ST_Transform(ST_GeomFromText(%s, 4326),27700),ST_Transform(ST_GeomFromText(%s, 4326),27700));"
#newPointSQL = "SELECT ST_ClosestPoint(ST_GeomFromText(%s),ST_GeomFromText(%s));"
#newPointSQL = "SELECT ST_As_Text(ST_ClosestPoint(ST_GeomFromText(%s), ST_GeomFromText(%s)));"
#newPointSQL = "SELECT ST_AsText(ST_ClosestPoint(ST_GeomFromEWKT(%s), ST_GeomFromText(%s)));"
#newPointSQL = "SELECT ST_AsText(ST_Line_Interpolate_Point(ST_GeomFromText(%s),ST_Line_Locate_Point(ST_GeomFromText(%s),ST_GeomFromText(%s))));"
newPointData = (correctionPathLine,pointToCorrect) - ( MULTILINESTRING((-3.16427109855617 55.9273798550064,-3.16462372283029 55.9273883602162)), POINT(-3.164667 55.92739))
My data is picked up ok because the first sql is successfull when executed. The problem is when I use the ST_ClosestPoint function.
Can anyone notice a misuse anywhere? Am I using the ST_ClosetsPoint in a wrong way?
In the last example, I did modify my data (in case someone notices) to run it but it still would not execute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你正在处理什么样的几何图形,但我之前在使用 MultiLineStrings 时也遇到过同样的麻烦,我意识到当 MultiLinestring 无法合并时,函数 ST_Line_Locate_Point 不起作用。(你可以知道如果无法使用 ST_LineMerge 合并 MultiLineString函数)我已经在旧的邮件列表中创建了一个 pl/pgSQL 函数,但我添加了一些性能调整,它仅适用于 MultiLineStrings 和 LineStrings(但可以轻松修改以使用 Polygons)。首先,它检查几何图形是否只有 1 维,如果有,则可以使用旧的 ST_Line_Interpolate_Point 和 ST_Line_Locate_Point 组合,如果没有,则必须对 MultiLineString 中的每个 LineString 执行相同的操作。另外,我还添加了 ST_LineMerge 以实现 1.5 之前的兼容性:
更新:
正如 @Nicklas Avén ST_Closest_Point() 所指出的, ST_Closest_Point() 应该可以工作, ST_Closest_Point 是在 1.5 中添加的。
I don't know with what kind of geometries you are dealing with, but I had the same trouble before with MultiLineStrings, I realized that when a MultiLinestring can't be merged, the function ST_Line_Locate_Point doesn't work.(you can know if a MultiLineString can't be merged using the ST_LineMerge function) I've made a pl/pgSQL function based in an old maillist but I added some performance tweaks, It only works with MultiLineStrings and LineStrings (but can be easily modified to work with Polygons). First it checks if the geometry only has 1 dimension, if it has, you can use the old ST_Line_Interpolate_Point and ST_Line_Locate_Point combination, if not, then you have to do the same for each LineString in the MultiLineString. Also I've added a ST_LineMerge for pre 1.5 compatibility :
UPDATE:
As noted by @Nicklas Avén ST_Closest_Point() should work, ST_Closest_Point was added in 1.5 .