2011-09-22 111 views
1

我一直在研究这个问题一段时间,并没有发现ESRI论坛页面或我写的一些FORTRAN三角测试脚本没有喜悦。Python,GIS和Fortran:试图从xy点数据创建多个多边形

我有两个.csv文件,其中包含数百个xy点数据。这些点表示潮间带的高端和低端。高点和低点相互平行,我想创建多边形条,将这些点中的四个连接到每个单独的多边形中。多边形的高度取决于高点和低点之间的距离。下面的链接显示,说明我的意思两个图像:

http://forums.arcgis.com/threads/39757-Feature-to-Line..?p=135880&posted=1#post135880

的主要问题已脚本的多边形正确地在角落形成。我知道在弯道上移动时,不能在底部直径为1英尺,顶部直径为1英尺的多边形。但是,这仅仅是我在试图解决此遇到了很多的问题之一......

任何帮助将不胜感激,谢谢

回答

0

这应该插值工作(说潮线为x ,y距岸上某个控制点的距离):

import math 

example_triangle = [[0,0], [5,5], [0,5], [0,0]] 
high_tide_line = [[0, 0], [5., 1.5], [10., 3.2], [20., 1.], [30., 4.5], [80.,2.], [80,0]] 
low_tide_line = [[0, 10.], [5., 11.5], [10., 13.2], [20., 11.], [30., 14.5], [80., 12.], [80, 10]] 

def points_from_geom(geom): 
    idx = 0 
    line_lengths = [] 
    unit_vectors = [] 
    interpolated_points = [] 
    while idx < (len(geom) - 1): 
     dy, dx = ((geom[idx+1][1] - geom[idx][1]), (geom[idx+1][0] - geom[idx][0])) 
     line_lengths.append(math.sqrt(dy**2 + dx**2)) 
     try: 
      angle = math.atan(dy/dx) 
      unit_vectors.append([math.cos(angle)*cmp(dx, 0), 
       math.sin(angle)*cmp(dy, 0)]) 
     except ZeroDivisionError: 
      if geom[idx+1][1] < geom[idx][1]: 
       direction = [0, -1] 
      else: 
       direction = [0, 1] 
      unit_vectors.append(direction) 
     idx += 1 

    for i, length in enumerate(line_lengths): 
     inter = 0 
     while inter <= length: 
      interpolated_points.append([geom[i][0] + unit_vectors[i][0]*inter,\ 
       geom[i][1] + unit_vectors[i][1]*inter]) 
      inter += .3048 # a ft in proper units ;) 

    return interpolated_points 

ln1 = points_from_geom(example_triangle) 
ln2 = points_from_geom(high_tide_line) 
ln3 = points_from_geom(low_tide_line) 

print ln1, ln2, ln3 

有很多不同的方法来做多边形。我可能会尝试的是确定一个参考海岸线,然后以固定间隔或在每个线段中间取垂直线,然后在相邻海岸线上的相交处制作一个多边形或边界框。顺便说一句,在真实应用程序中,您需要确保cmp未在(0,0)上运行。