{"record":{"id":"6c151de41649ffdb","repo":"django/django","slug":"envelope-minimum-x-maximum-x","errorCode":null,"errorMessage":"Envelope minimum X > maximum X.","messagePattern":"Envelope minimum X > maximum X\\.","errorType":"exception","errorClass":"GDALException","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/gdal/envelope.py","lineNumber":69,"sourceCode":"                # A tuple was passed in.\n                if len(args[0]) != 4:\n                    raise GDALException(\n                        \"Incorrect number of tuple elements (%d).\" % len(args[0])\n                    )\n                else:\n                    self._from_sequence(args[0])\n            else:\n                raise TypeError(\"Incorrect type of argument: %s\" % type(args[0]))\n        elif len(args) == 4:\n            # Individual parameters passed in.\n            #  Thanks to ww for the help\n            self._from_sequence([float(a) for a in args])\n        else:\n            raise GDALException(\"Incorrect number (%d) of arguments.\" % len(args))\n\n        # Checking the x,y coordinates\n        if self.min_x > self.max_x:\n            raise GDALException(\"Envelope minimum X > maximum X.\")\n        if self.min_y > self.max_y:\n            raise GDALException(\"Envelope minimum Y > maximum Y.\")\n\n    def __eq__(self, other):\n        \"\"\"\n        Return True if the envelopes are equivalent; can compare against\n        other Envelopes and 4-tuples.\n        \"\"\"\n        if isinstance(other, Envelope):\n            return (\n                (self.min_x == other.min_x)\n                and (self.min_y == other.min_y)\n                and (self.max_x == other.max_x)\n                and (self.max_y == other.max_y)\n            )\n        elif isinstance(other, tuple) and len(other) == 4:\n            return (\n                (self.min_x == other[0])","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/gdal/envelope.py#L51-L87","documentation":"Raised by Envelope.__init__ (django/contrib/gis/gdal/envelope.py:69) as a GDALException after the envelope fields are populated, when min_x > max_x. A bounding box is meaningless if its left edge is to the right of its right edge, so the constructor refuses to produce an invalid envelope.","triggerScenarios":"Envelope((10.0, 0.0, 5.0, 5.0)) where minx=10 > maxx=5. Swapped coordinate order from a source that emits (maxx, miny, minx, maxy). Off-by-one or sign error in computed extents. Negative-longitude crossing handled incorrectly.","commonSituations":"Datasets that report extent as (xmax, ymin, xmin, ymax) rather than (xmin, ymin, xmax, ymax). UI bounding boxes where the user drags right-to-left. Antimeridian-crossing geometries whose raw bbox wraps.","solutions":["Reorder coordinates so min_x <= max_x: Envelope((min(a,c), b, max(a,c), d)).","Normalize the source extent with min/max before construction.","For antimeridian geometries, split or shift longitudes before computing the envelope.","Check the source documentation for its extent axis order."],"exampleFix":"// before\nenv = Envelope((xmax, ymin, xmin, ymax))   # minx > maxx -> error\n// after\nenv = Envelope((xmin, ymin, xmax, ymax))   # canonical (min_x, min_y, max_x, max_y)","handlingStrategy":"validation","validationCode":"minx, miny, maxx, maxy = extent\nif minx > maxx:\n    minx, maxx = min(minx, maxx), max(minx, maxx)\nenv = Envelope((minx, miny, maxx, maxy))","typeGuard":"def x_axis_valid(extent) -> bool:\n    return extent[0] <= extent[2]","tryCatchPattern":"from django.contrib.gis.gdal.error import GDALException\ntry:\n    env = Envelope(extent)\nexcept GDALException:\n    a, b, c, d = extent\n    env = Envelope((min(a, c), b, max(a, c), d))  # normalize X","preventionTips":["Normalize extents with min/max on both axes before construction.","Confirm the source's axis order (xmin,ymin,xmax,ymax vs. xmax,ymin,xmin,ymax).","Watch for antimeridian-crossing geometries that need splitting."],"tags":["gis","gdal","ogr","envelope","coordinate-order","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}