#31366 closed Bug (invalid)
GEOSGeometry fails on instance with GEOJson and srid not 4326.
Reported by: | Walter Lorenzetti | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Normal | Keywords: | Geodjango |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
On creating a GEOSGeometry intance by a GEOJson string with a srid not 4326, I obtain this error:
coord = '{"type": "Point", "coordinates": [10000, 10000]}'
g = GEOSGeometry(coord, srid=3857) Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/envs/g3w_suite_dj22/lib/python3.6/site-packages/django/contrib/gis/geos/geometry.py", line 732, in __init__ raise ValueError('Input geometry already has SRID: %d.' % input_srid) ValueError: Input geometry already has SRID: 4326.
So to fix it I use this not beautyfull solution:
g = GEOSGeometry(GEOSGeometry(coord).wkt, srid=3857)
Thanks in advance.
W
Change History (2)
comment:1 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Summary: | GEOSGeometry fails on instance with GEOJson and srid not 4326 → GEOSGeometry fails on instance with GEOJson and srid not 4326. |
Version: | 2.2 → master |
comment:2 by , 5 years ago
I would argue in favor of this bug that when a GeoJSON is created from PostGIS using the ST_AsGeoJSON function, there is 'crs' member (only 'type' and 'coordinates').
Also, in the same page of the doc, it is written "All these constructors take the keyword argument srid.", hence the confusion of Walter.
It's documented that "for the GeoJSON format, the SRID is set based on the crs member. If crs isn’t provided, the SRID defaults to 4326". So if you want to use GeoJSON with a different SRID you need to use
crs
, e.g.