[Tutor] classes for setting 2D envelopes
Matt Gregory
matt.gregory at oregonstate.edu
Thu Dec 23 02:31:09 CET 2010
Hi all,
I've been working on creating 2D bounding box (envelope) classes to
describe spatial data. Variations of these are available in other
spatial libraries (e.g. Shapely), although I haven't found envelopes
specific to raster data that also specifies cell size. Could be I just
haven't found them yet.
I have two classes (Envelope and RasterEnvelope). Envelope specifies a
bounding box and does error checking (through __setattr__) when a
coordinate is changed. RasterEnvelope additionally specifies a cell
size (along with n_rows and n_cols), does the bounds checking on a
coordinate change and adjusts the spatial envelope accordingly (again
through __setattr__). I've posted the code (and some unit tests) here:
http://pastebin.com/Twf3RjWa
So far things work, but I have a nagging feeling that there's too much
work devoted to changing coordinates. In another thread I posted a
while back
(http://mail.python.org/pipermail/tutor/2010-August/077940.html), Steven
D'Aprano recommended using immutable types for point coordinate data and
I'm guessing the advice might be applicable here as well? If so, I'm a
slow learner ;) There are also (at least) a couple of design flaws
right now that could be remedied if I put more work into it:
- A RasterEnvelope is 'pinned' by its upper-left coordinate and only
changes to x_min or y_max will cause changes in this coordinate (by
design but probably a limitation)
- Changing cell size currently doesn't change the corresponding window
because there is no specification as to whether n_cols/n_rows should
change or x_max/y_min should change.
Both these probably suggest creating new RasterEnvelope instances any
time a coordinate changes? Any feedback would be welcome, so that I
don't devote too much more time down a bad route.
thanks, matt
More information about the Tutor
mailing list