{"record":{"id":"f8980eea64aeef45","repo":"django/django","slug":"calling-transform-with-no-srid-set-is-not-suppor","errorCode":null,"errorMessage":"Calling transform() with no SRID set is not supported.","messagePattern":"Calling transform\\(\\) with no SRID set is not supported\\.","errorType":"exception","errorClass":"GEOSException","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/geos/geometry.py","lineNumber":518,"sourceCode":"        PROJ string. By default, transform the geometry in-place and return\n        nothing. However if the `clone` keyword is set, don't modify the\n        geometry and return a transformed clone instead.\n        \"\"\"\n        srid = self.srid\n\n        if ct == srid:\n            # short-circuit where source & dest SRIDs match\n            if clone:\n                return self.clone()\n            else:\n                return\n\n        if isinstance(ct, gdal.CoordTransform):\n            # We don't care about SRID because CoordTransform presupposes\n            # source SRS.\n            srid = None\n        elif srid is None or srid < 0:\n            raise GEOSException(\n                \"Calling transform() with no SRID set is not supported.\"\n            )\n\n        # Creating an OGR Geometry, which is then transformed.\n        g = gdal.OGRGeometry(self._ogr_ptr(), srid)\n        g.transform(ct)\n        # Getting a new GEOS pointer\n        ptr = g._geos_ptr()\n        if clone:\n            # User wants a cloned transformed geometry returned.\n            return GEOSGeometry(ptr, srid=g.srid)\n        if ptr:\n            # Reassigning pointer, and performing post-initialization setup\n            # again due to the reassignment.\n            capi.destroy_geom(self.ptr)\n            self.ptr = ptr\n            self._post_init()\n            self.srid = g.srid","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/geos/geometry.py#L500-L536","documentation":"Raised by GEOSGeometry.transform (geometry.py:496-520) as a GEOSException when the geometry has no SRID (srid is None) or a negative SRID and the caller passed a target SRID/transform that is not already a gdal.CoordTransform. Reprojection requires a known source SRS, so Django refuses to guess.","triggerScenarios":"Calling geom.transform(3857) (or any int/WKT/PROJ-string target) on a geometry whose geom.srid is None or < 0 and where the target is not a CoordTransform (a CoordTransform bundles its own source SRS and bypasses this check).","commonSituations":"Loading geometries from WKT without specifying an SRID, geometries deserialized from formats that drop SRID, or input pipelines that forget to call geom.srid = 4326. Also from negative SRIDs used as 'unknown' sentinels.","solutions":["Set an explicit SRID before transforming: geom.srid = 4326; geom.transform(3857).","Construct the geometry with the SRID up front: GEOSGeometry('POINT(0 0)', srid=4326).","If only the target SRS is known, build a gdal.CoordTransform(source_srs, dest_srs) and pass that instead of a bare SRID."],"exampleFix":"// before\ngeom.transform(3857)  # geom.srid is None\n// after\ngeom.srid = 4326\ngeom.transform(3857)","handlingStrategy":"validation","validationCode":"def safe_transform(geom, target):\n    if geom.srid is None or geom.srid < 0:\n        geom.srid = 4326  # or raise, depending on policy\n    return geom.transform(target)","typeGuard":"def geometry_has_srid(geom):\n    return geom.srid is not None and geom.srid >= 0","tryCatchPattern":"from django.contrib.gis.geos.error import GEOSException\ntry:\n    geom.transform(3857)\nexcept GEOSException:\n    geom.srid = 4326  # assume WGS84\n    geom.transform(3857)","preventionTips":["Always set an SRID when constructing geometries from WKT.","Validate geom.srid is set before any transform pipeline.","Prefer CoordTransform when source SRS varies per record."],"tags":["geos","transform","srid","projection","validation"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}