首页 文章

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

提问于
浏览
1

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

我的脚本基于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之间划了一条线 . 我认为这与pyshp处理shapefile有关 . 更具体的'bbox'字段设置每个形状的bounderies .

解决方案将使B和C之间的界线消失 .

1 回答

  • 2

    您可能没有正确嵌套零件清单 . 我假设你正在尝试创建一个多部分polylineZ shapefile,其中的行共享一个dbf记录 . 折线Z型实际上是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")
    

相关问题