Fastest way to get all the points between two (X,Y) coordinates in python

后端 未结 3 860
星月不相逢
星月不相逢 2020-12-16 07:58

So I have a shapely LineString:

print np.round(shapely_intersecting_lines.coords).astype(np.int) 
>>> array([[ 1520, -1140         


        
3条回答
  •  无人及你
    2020-12-16 08:35

    Using generators so that way you will save memory

    import numpy as np
    import math
    
    d = np.array(
        [
            [1520,-1140],
            [1412,-973]
        ],dtype=float);
    rise = d[0,1]-d[1,1];
    run = d[0,0]-d[1,0];
    slope = rise/run;
    print slope
    
    fromPt = d[0];
    sign = 1
    if (slope<0):
        sign = -1;
    points = ([d[0,0]+sign*i,math.floor(d[0,1]+(sign*i*slope))] for i in xrange(1+int(math.ceil(abs(d[0,0]-d[1,0])))))
    for pt in points:
        print pt
    

提交回复
热议问题