17

我正在将Shapely集成到我的代码中,并且我必须处理几种不同类型的几何对象。线、多边形和线串满足了我的大部分需求,但我需要使用椭圆。有没有办法通过边界框或半轴在 Shapely 中创建椭圆,而不必将椭圆离散成线?

4

2 回答 2

22

没有任何方法可以在不离散化的情况下在 Shapely 中表示多边形。

在基础级别,Shapely 处理点数。从 LineString 到 Polygon 的所有内容都只是一个点列表。一个很好的例子是当你把 aPoint缓冲出来时会发生什么:

>>> import shapely
>>> from shapely.geometry.point import Point
>>> p = Point(0, 0)
>>> circle = p.buffer(1.0)
>>> list(circle.exterior.coords)
[(1.0, 0.0), (0.99518472667219693, -0.098017140329560506), (0.98078528040323054, -0.19509032201612808), (0.95694033573220894, -0.29028467725446211), (0.92387953251128696, -0.38268343236508939), (0.88192126434835527, -0.4713967368259972), (0.83146961230254557, -0.55557023301960173), (0.77301045336273744, -0.63439328416364493), (0.70710678118654813, -0.70710678118654691), (0.63439328416364626, -0.77301045336273633), (0.55557023301960307, -0.83146961230254468), (0.47139673682599859, -0.88192126434835449), (0.38268343236509084, -0.92387953251128629), (0.29028467725446361, -0.95694033573220849), (0.19509032201612964, -0.98078528040323021), (0.098017140329562089, -0.99518472667219671), (1.615542552166338e-15, -1.0), (-0.098017140329558883, -0.99518472667219704), (-0.19509032201612647, -0.98078528040323076), (-0.2902846772544605, -0.95694033573220938), (-0.38268343236508784, -0.92387953251128752), (-0.4713967368259957, -0.88192126434835605), (-0.55557023301960051, -0.83146961230254635), (-0.63439328416364393, -0.77301045336273821), (-0.70710678118654624, -0.70710678118654879), (-0.77301045336273588, -0.63439328416364682), (-0.83146961230254435, -0.55557023301960362), (-0.88192126434835427, -0.47139673682599903), (-0.92387953251128618, -0.38268343236509111), (-0.95694033573220849, -0.29028467725446366), (-0.98078528040323021, -0.19509032201612947), (-0.99518472667219682, -0.098017140329561714), (-1.0, -1.010639055082363e-15), (-0.99518472667219693, 0.098017140329559702), (-0.98078528040323065, 0.1950903220161275), (-0.95694033573220905, 0.29028467725446172), (-0.92387953251128696, 0.38268343236508923), (-0.88192126434835527, 0.47139673682599725), (-0.83146961230254546, 0.55557023301960196), (-0.7730104533627371, 0.63439328416364527), (-0.70710678118654768, 0.70710678118654746), (-0.63439328416364593, 0.77301045336273666), (-0.55557023301960295, 0.83146961230254479), (-0.4713967368259987, 0.88192126434835449), (-0.38268343236509117, 0.92387953251128618), (-0.29028467725446411, 0.95694033573220838), (-0.19509032201613041, 0.98078528040322999), (-0.098017140329563102, 0.9951847266721966), (-2.8482262121737323e-15, 1.0), (0.098017140329557426, 0.99518472667219715), (0.19509032201612481, 0.9807852804032311), (0.29028467725445867, 0.95694033573220993), (0.3826834323650859, 0.9238795325112884), (0.47139673682599365, 0.88192126434835716), (0.55557023301959818, 0.8314696123025479), (0.63439328416364149, 0.77301045336274021), (0.70710678118654358, 0.70710678118655146), (0.77301045336273322, 0.63439328416365004), (0.83146961230254179, 0.5555702330196074), (0.88192126434835194, 0.47139673682600342), (0.92387953251128407, 0.38268343236509617), (0.95694033573220671, 0.29028467725446927), (0.98078528040322899, 0.19509032201613569), (0.99518472667219615, 0.098017140329568472), (1.0, 8.2385270480656025e-15), (1.0, 0.0)]

如您所见,圆由 65 个点组成,这些点彼此间隔开0.0966

于 2012-10-30T06:01:19.577 回答
11

对于那些感兴趣的人,这里是一个创建轴长为 15 和 20 的椭圆的示例。

import shapely.affinity
from shapely.geometry import Point

circle = Point(0, 0).buffer(1)  # type(circle)=polygon
ellipse = shapely.affinity.scale(circle, 15, 20)  # type(ellipse)=polygon
于 2016-12-22T08:01:03.027 回答