使用 OpenLayers 将数据保存到 Shapefile
我正在使用 OpenLayers 创建一个 Web 应用程序。我已经实现了这样的功能:用户可以向使用 JavaScript 显示的地图添加点或多边形。我现在需要将此数据保存到形状文件中。有什么想法吗?
I am creating a web application using OpenLayers. I have implemented functionality such that a user can add a point or polygon to the map that is displayed using JavaScript. I now need to save this data to a shapefile. Any ideas on how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一个旧线程,但在我自己进行了一些谷歌搜索以查看是否有任何内容之后,我带着同样的问题来到这里。我的结论是不存在,但可能存在,所以我写了它:
https://code。 google.com/p/js2shapefile/
这是我第一次在 Javascript 中完成这些工作,所以我相信您会发现我的代码有各种奇怪的地方...但是,它有效,无论如何,对于 ESRI Javascript API 图形和 Google 地图标记。它也可以很容易地扩展为将 OpenLayers 向量作为输入,但我还没有时间这样做。
I know it's an old thread but I came here with the same question after doing a bit of googling myself to see if there was anything out there. I concluded that there wasn't but that there could be, so I wrote it:
https://code.google.com/p/js2shapefile/
It's the first time I've done anything along these lines in Javascript so I'm sure you'll find all kinds of oddities with my code...but, it works, for ESRI Javascript API graphics and Google Maps markers, at any rate. It could be easily extended to take OpenLayers vectors as input too, but I haven't got round to doing that.
您可能必须在服务器上执行此操作,除非有 shapelib 的 javascript 实现。
实际上,您希望网络用户获取要保存的 shapefile 还是将其保存在服务器上?
在服务器上执行此操作的方法有很多种,具体取决于您选择的服务器语言。在 python 中,您只需导入 ogr 库并编写它...您需要使用其中的数据从客户端构造一个 Web 请求...
也许 geoscript 可以提供帮助:
http://geoscriptblog.blogspot.com/2010/06/merging-shapefiles-with-javascript.html< /a>
You'll probably have to do it on the server, unless there's a javascript implementation of shapelib.
Actually, do you want the web user to get a shapefile to save or do you want to save it on the server?
There's lots of ways of doing it on a server, depending on your server language of choice. In python, you just import the ogr library and write it... You'll need to construct a web request from the client with the data in it though...
Maybe geoscript can help:
http://geoscriptblog.blogspot.com/2010/06/merging-shapefiles-with-javascript.html
此处对此问题有很好的概述。要仅使用客户端 javascipt 转换为形状,您可以基于 JavaScript Shapefile 到 GeoJSON 进行工作库。
There's a good overview on this issue here. For converting to shape using client side javascipt only, you could base you work on the JavaScript Shapefile to GeoJSON library.