如何将形状文件类型从折线转换为多边形?

发布于 2024-12-20 02:52:06 字数 66 浏览 6 评论 0原文

我有一个文件类型为折线的形状文件。但我想将其转换为多边形。有可能使用免费资源吗?如何将形状文件类型从折线转换为多边形?

I have a shape file whose file type is polyline. But I want convert it to polygon. Is it possible with free sources? How can I convert shape file type from polyline to polygon?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜灵血窟げ 2024-12-27 02:52:06

借助 PySAL 库,这可以在 python 中轻松完成。

例如,给定一个名为“tst.shp”的形状文件,其中包含两条折线,
QGIS 中的两条折线

我们可以打开 shapefile 将折线转换为多边形并写出一个新的 shapefile。

>>> import pysal
>>> shps = pysal.open('tst.shp','r')
>>> o = pysal.open('tst_polygons.shp','w')
>>> for polyline in shps:
...     verts = polyline.vertices
...     if verts[0] != verts[-1]: #make sure the polylines are closed rings
...         verts = verts+verts[0:1]
...     o.write(pysal.cg.Polygon(verts))
...
>>> o.close()

现在我们有了多边形,
QGIS 中的两个多边形

如果您需要一种无需编程即可完成此任务的方法,请尝试在 http://gis.stackexchange.com

This can be done pretty easily in python with the help of the PySAL library.

For example given a shapefile named "tst.shp" with two polylines,
Two Polylines in QGIS

We can open the shapefile convert the polylines to polygons and write out a new shapefile.

>>> import pysal
>>> shps = pysal.open('tst.shp','r')
>>> o = pysal.open('tst_polygons.shp','w')
>>> for polyline in shps:
...     verts = polyline.vertices
...     if verts[0] != verts[-1]: #make sure the polylines are closed rings
...         verts = verts+verts[0:1]
...     o.write(pysal.cg.Polygon(verts))
...
>>> o.close()

Now we have polygons,
Two Polygons in QGIS

If you need a way to accomplish this without programming, try asking your questions at http://gis.stackexchange.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文