从 SQL 创建 SHP
是否可以使用 pgsql2shp 不使用 shell 将 sql 转换为 shp 文件?通过一些 SQL(postgis、postgresql)语法?
Is it possible convert sql to shp file using pgsql2shp without shell? Through some SQL (postgis, postgresql) syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不调用 shell 是不可能的。但是,有两个可用的方法:
1)您可以在 postgresql 中使用不安全的语言(例如 python)创建一个函数,然后执行 pgsql2shp。这是一个丑陋的 hack,但具有通过 SQL 查询生成 shapefile 的优点。
2)您可以将sql结果转储到临时表中,其中几何列通过ST_AsText保存为文本。然后,您可以通过 sql COPY TO 命令将表转储到 csv,然后使用客户端脚本从 csv 重建 shapefile。
这些方法都不是完全令人满意的(特别是方法 2 可能会损失一些几何精度),但它们可能足以实现您的目标。
It is not possible without calling the shell. However, two kuldges are available:
1) You could create a function in an unsafe language (like python) within postgresql that then executes pgsql2shp. This is an ugly hack, but has the advantage of producing a shapefile by SQL query.
2) You could dump the sql results into a temporary table with the geometry column saved as text via ST_AsText. You can then dump the table to csv via the sql COPY TO command, and then reconstruct a shapefile from the csv later using a client side script.
Neither of these approaches is entirely satisfactory (approach 2 in particular may lose some of the precision of your geometry), but they may be enough to achieve your goal.