本文介绍了numpy mgrid线形坐标匀称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在制作一些小地图,以使自己适应使用形状.

I've been making little maps to orient myself to using shapely.

例如:

from shapely.geometry import MultiLineString
from pprint import pprint
import pylab

coords = [((1,1),(1,13)),((3,1),(3,13)),((5,1),(5,13)),((7,1),(7,13)),((9,1),(9,13)), ((11,1),(11,13)),((13,1),(13,13)),((1,1),(13,1)),((1,3),(13,3)), ((1,5),(13,5)),((1,7),(13,7)),((1,9),(13,9)),((1,11),(13,11)),((1,13),(13,13)),((1,1),(13,13)),((3.5,1),(13,10.5)),((6.5,1),(13,7.5)),((9.5,1),(13,4.5)),((1,3.5),(10.5,13)),((1,6.5),(7.5,13)),((1,9.5),(4.5,13))]
lines_1 = MultiLineString(coords)
mow = lines_1.buffer(0.25)}

我发现自己是一个不好的打字员,很难写出很长的坐标列表.

I discover I am a bad typist and it is difficult to write long lists of coordinates.

我注意到numpy mgrid,想知道是否有一种方法可以使用它创建任意对象矩形xy网格,然后将mgrid转换为形状为LineString的列表.

I noticed numpy mgrid and wondered if there is a way to use it to create arbitraryrectangular xy grids and then convert the mgrid to a list for shapely LineString.

通常将网格设计为类似于棋盘格的东西.然后将网格中的一些水平线缓冲成多边形,然后缓冲垂直线,然后两个级联,我有我的检查板.然后我取不同的对角线,并合并用棋盘格将它们从线性环中提取出来.

The grid is generally designed to be something like a checker board. Some horizontal lines in the grid are then buffered to become polygons, then vertical lines buffered, then thetwo cascade unioned and I have my checker board. I then take different diagonals, unionthem with the checker board and extract the resultant polygons from the linear rings.

随着地图尺寸变大,而且不是最佳打字员,我希望在那里也许是使用mgrid更好地进行某些键入的一种方法.

As the map dimensions get larger, and being not the best typist, I was hoping that theremight be a way to use mgrid to do some of my typing much better.

即.x,y = np.mgrid [:55,:35]#矩形

ie. x, y = np.mgrid[:55, :35] # rectangular

这给出了预期的x和y值.我对如何服用这些药物感到困惑结果返回到Linestring(s)的Nx2数组作为shape的列表.

This gives the expected x and y values. I an confused as to how I might take theseresults back to an Nx2 array for Linestring(s) as list for shapely.

在此先感谢您的指导.克里斯

Thank you in advance for any guidance.Chris

推荐答案

您可以 vstack 结合转置:

>>> x, y = np.mgrid[:2, :3]
>>> np.vstack((x.ravel(),y.ravel())).T
array([[0, 0],
       [0, 1],
       [0, 2],
       [1, 0],
       [1, 1],
       [1, 2]])

如果需要元组列表:

>>> [(x,y) for x,y in zip(x.ravel(),y.ravel())]
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)]

这篇关于numpy mgrid线形坐标匀称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:41