【问题标题】:Pyshp: PolyLineZ drawing draws lines between my linesPyshp:PolyLineZ 绘图在我的线条之间绘制线条
【发布时间】:2016-02-04 14:50:43
【问题描述】:

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

我的脚本基于 pyshp 包。

我的脚本如下所示:

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

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

一条线从 A 到 B。

另一条线从 C 到 D

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

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

【问题讨论】:

    标签: python gis shape shapefile


    【解决方案1】:

    您可能没有正确嵌套零件列表。我假设您正在尝试创建一个多部分 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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-19
      • 2019-08-15
      • 1970-01-01
      • 2018-10-02
      • 2019-10-27
      • 2015-04-19
      • 2010-12-25
      • 1970-01-01
      相关资源
      最近更新 更多