Ticket #168 (defect)

Opened 3 months ago

Last modified 3 months ago

Polygon dimensionality inconsistency

Status: closed (fixed)

Reported by: seang Assigned to: seang
Priority: major Milestone:
Component: Shapely Version:
Keywords: poygon dimensions Cc:

Hello!

I've been using Shapely for a few weeks, and I'm wondering if there is a simpler way to access z values from Shapes (other than Points).

For instance, I use a lot of Polygons and right now, although they are created with 3 dimensions, their rings seem to automatically get a _ndim of 2 although they _do_ store the z (see example below). It gets a bit contrived to get the value back (must force the _ndim to 3), but since Shapely isn't meant to deal with 3d geometries I'm not sure if this qualifies as a bug.

An example:

  >>> from shapely.geometry import Point, Polygon
  >>> p = Point(1., 1., 5.)
  >>> print p.__geo_interface__
  {'type': 'Point', 'coordinates': (1.0, 1.0, 5.0)} # Great!
  >>> poly = Polygon(((1., 11., 20.),
  ...             (11., 1., 20.),
  ...             (1., -9., 20.),
  ...             (-9., 1., 20.)))
  >>> print poly.__geo_interface__
  {'type': 'Polygon', 'coordinates': (((1.0, 11.0), (11.0, 1.0), (1.0, -9.0), (-9.0, 1.0), (1.0, 11.0)),)}
  >>> print poly._ndim
  3
  >>> print poly.has_z
  True
  >>> e = poly.exterior
  >>> print e._ndim
  2 # Hm...
  >>> list(e.coords)
  [(1.0, 11.0), (11.0, 1.0), (1.0, -9.0), (-9.0, 1.0), (1.0, 11.0)]
  >>> e._ndim = 3
  >>> list(e.coords)
  [(1.0, 11.0, 20.0), (11.0, 1.0, 20.0), (1.0, -9.0, 20.0), (-9.0, 1.0, 20.0), (1.0, 11.0, 20.0)] # Haha!

Ideally I'd love to be able to get z back from <shape>.geo_interface, but that might be asking for too much :) Still, I expected the rings to be returned with the correct number of dimensions. Is there a simpler way to get z back?

Change History

08/11/08 09:57:42: Modified by seang

  • keywords set to poygon dimensions.
  • status changed from new to assigned.

Agreed that there is a dimensionality bug. Looks like it's associated with the rings.

08/22/08 21:10:44: Modified by seang

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in r1137.