Pyshp:PolyLineZ绘图在我的直线之间绘制直线

2024-05-07 00:37:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我的线条正在连接,即使我没有将它们设置为多边形。在

我的脚本基于pyshp包。在

我的脚本如下:

w=Shapefile.Writer()
#shapetype 11 is a polylineZ
w.poly(parts=[listOfCoordinates], shapeType = 11)
w.record(this,and,that)
w.save(file)

问题是,当我生成多个poly的Qgis时,我打开它们在它们之间画了一条线。 示例:

一条线从A到B

另一条线从C到D

由于某些原因,Qgis在B和C之间画了一条线。我认为这与shapefile的pyshp处理有关。更具体的是为每个形状设置边界的“bbox”字段。在

解决方案会使B和C之间的界限消失。在


Tags: 脚本isrecord多边形线条writerpartsshapefile
1条回答
网友
1楼 · 发布于 2024-05-07 00:37:20

您可能没有正确嵌套明细表。我假设您正在尝试创建一个多部分polylineZ shapefile,其中的行共享一个dbf记录。而且polylineZ类型实际上是13而不是11。在

下面的三行代码创建两个平行的文件。在这个例子中,我不关心Z坐标。第一个shapefile是一个多部分,就像我假设你正在创建的。第二个shapefile为每一行提供自己的记录。两者都使用相同的线几何图形。在

import shapefile

# Create a polylineZ shapefile writer
w = shapefile.Writer(shapeType = 13)
# Create a field called "Name"
w.field("NAME")
# Create 3 parallel, 2-point lines
line_A = [[5, 5], [10, 5]]
line_B = [[5, 15], [10, 15]]
line_C = [[5, 25], [10, 25]]
# Write all 3 as a multi-part shape
# sharing one record
w.poly(parts=[line_A, line_B, line_C])
# Give the shape a name attribute
w.record("Multi Example")
# save
w.save("multi_part")

# Create another polylineZ shapefile writer
w = shapefile.Writer(shapeType = 13)
# Create a field called "Name"
w.field("NAME")
# This time write each line separately
# with its own dbf record
w.poly(parts=[line_A])
w.record("Line A")
w.poly(parts=[line_B])
w.record("Line B")
w.poly(parts=[line_C])
w.record("Line C")
# Save
w.save("single_parts")

相关问题 更多 >