Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10380 closed (fixed)

gdal Envelope should allow min_x == max_x and/or min_y == max_y

Reported by: psmith Owned by: jbronn
Component: GIS Version: 1.0
Severity: Keywords: envelope extent gdal
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When initializing a new django.contrib.gis.gdal.Envelope object, an OGRException is raised if the min_x value is less than or equal to max_x, and if the min_y value is less than or equal to max_y. It would be better if the exception was raised on in the case that min_x was greater than max_x and/or if min_y greater than max_y.

The reason that it is often useful to create an Envelope from a point initially, say from the extent of a django.contrib.gis.geos.Point object, where the min_x and min_y will equal the max_x and max_y, respectively. For example, to find the extent of a set or list of points, it is convenient to iterate over the collection, creating the Envelope initially with the first point from the iteration, then expanding it with each successive point. (Perhaps using the expand_to_include method proposed in #10368.)

Example:

>>> from django.contrib.gis.geos import Point
>>> from django.contrib.gis.gdal import Envelope
>>> env = None
>>> for pt in [Point(5, 10), Point(-1, 3), Point(9, -2)]:
...     if env is None:
...         env = Envelope(pt.extent)
...     else:
...         env.expand_to_include(pt.extent)
>>> env.tuple
(-1, -2, 9, 10)

Making this change should have no impact on the semantics of the Envelope class: indeed, the OGREnvelope class in ogr_core.h from which it is derived does not enforce or check for the ordering of the min and max values.

Attachments (1)

gis_envelope_min_max.diff (1.6 KB) - added by psmith 5 years ago.
Patch to envelope.py with unit test

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by psmith

Patch to envelope.py with unit test

comment:1 Changed 5 years ago by jbronn

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jbronn
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9985]) Maintenance refactor of the GDAL (OGR) ctypes interface. Changes include:

  • All C API method explictly called from their prototype module, no longer imported via *.
  • Applied DRY to C pointer management, classes that do so subclass from GDALBase.
  • OGRGeometry: Added from_bbox class method (patch from Christopher Schmidt) and kml property.
  • SpatialReference: Now initialize with SetFromUserInput (initialization is now more simple and flexible); removed duplicate methods.
  • Envelope: Added expand_to_include method and now allow same coordinates for lower left and upper right points. Thanks to Paul Smith for tickets and patches.
  • OGRGeomType: Now treat OGC 'Geometry' type as 'Unknown'.

Fixed #9855, #10368, #10380. Refs #9806.

comment:3 Changed 5 years ago by jbronn

  • milestone set to 1.1

comment:4 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.