【问题标题】:Vertical lines in a polygon shapefile多边形 shapefile 中的垂直线
【发布时间】:2014-09-09 10:58:13
【问题描述】:

我正在使用多边形 shapefile 的单个输入来解决 GIS 问题。

考虑一个不规则的多边形。我想以相等的间距在多边形的范围内绘制垂直线。

我打算如何继续:

  1. 识别边界框(使用 PyShp 完成)

  2. 以等间距绘制平行于边界框左边缘的垂直线(如何?)

  3. 将线条剪裁到多边形的范围(如何,不使用 ArcPy?)

注意:它们只能是垂直的,并且不是刻度线。另外,我不打算使用 ArcPy,而是打算在 Python (2.7) 中完成编码,因为这部分代码需要进入从 PyQt 生成的工具中。

【问题讨论】:

  • @jonrsharpe - 感谢您的编辑..
  • 您可能想提出您的问题并将您的代码发布到gis.stackexchange.com
  • 是的.. 绝对的.. 谢谢:)
  • 非常欢迎任何有关剪辑片段的帮助..

标签: python python-2.7 shapefile bounding-box


【解决方案1】:
  • 在左边缘找到描述直线的点/顶点 - (x1, y1), (x2, y2)
  • 为 x 值添加一个常数 - (x1+k, y1), (x2+k, y2)
  • 在新的 x 值 - (x1+k, y3), (x2+k, y4) 处找到多边形上的 y 值
  • 在这两点之间画线。

【讨论】:

  • 非常感谢您的意见。如果解决了(或考虑错误),我会尽快发布代码
【解决方案2】:

终于找到了我的问题的代码.. !!因此回答它...谢谢您的投入..

Ipath = raw_input("Enter the input file :- ")
Opath = raw_input("Enter the output directory :- ")
Ipath = Ipath.replace("\\", "/") # Python requirement for paths
Opath = Opath.replace("\\", "/")
copyfile(str(Ipath) + ".prj", str(Opath) + "/" + "Out_Lines" + ".prj") # Copying projection file


sf = shapefile.Reader(str('Input Path'))
shapes = sf.shapes()
Box = shapes[0].bbox
Spc = input("Enter the grid spacing :- ") # Grid Spacing read

x_min = Box[0] # Save the coordinates of the right-bottom, left-top bounding box
y_min = Box[1]
x_max = Box[2]
y_max = Box[3]

A_bbox = [x_min, y_min] # First assignment of coordinates
B_bbox = [x_max, y_max]
C_bbox = [x_min, y_max]
D_bbox = [x_max, y_min]

w = shapefile.Writer(shapefile.POLYLINE) # Shapefile writer
w.line(parts = [[A_bbox, C_bbox]])
w.field('Path number', 'C', '50') 
w.record(str(1)) # Writes the first line, that is the left 'side' of the bounding box

# Increasing the X coordinate to generate a line at a specified spacing 
i = 2
while (A_bbox[0] <= x_max):
    A_bbox = [A_bbox[0] + Spc, A_bbox[1]]
    C_bbox = [C_bbox[0] + Spc, C_bbox[1]]
    w.line(parts = [[A_bbox, C_bbox]])
    w.record(str(i))
    i = i+1

w.save(str(Opath) + "/" + "Out_Lines")

这会将结果保存在 shapefile 中。

作为上述问题的延续,问题的解决方案可在Clipping Line shapefiles within extent of Polygon shape 获得。我认为这组问题现在可以被视为已回答和结束。

感谢大家的帮助。

【讨论】:

  • 您希望将其裁剪到边界框还是原始形状?一种是蛮力,方法是将线上的点与 shape 进行比较,并找出这些点在 outside 形状的位置。
  • 解出涉及Clipping段的余数解,更新答案。谢谢您的帮助。希望尽快在这个论坛上提出很多问题.. :)
猜你喜欢
  • 2013-04-19
  • 2016-03-21
  • 2014-01-30
  • 2014-11-01
  • 2011-08-30
  • 1970-01-01
  • 2021-09-21
  • 2015-08-29
  • 1970-01-01
相关资源
最近更新 更多