Skip to content

Commit

Permalink
Merge pull request #142 from developmentseed/patch/crs-wkt-is-projjso…
Browse files Browse the repository at this point in the history
…n-object

OGC says Well Known Text is a PROJJSON object
  • Loading branch information
vincentsarago authored Jan 18, 2024
2 parents d0aa3ad + 1b3eee0 commit ef793c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
20 changes: 20 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@

## 5.2.1 (2024-01-18)

* fix `CRS` WKT type from `string` to `Object` (PROJJSON) (ref: https://github.com/opengeospatial/2D-Tile-Matrix-Set/issues/89).

```python
# Before
wkt = pyproj.CRS.from_epsg(3857).to_wkt()
TileMatrixSet(
...
crs={"wkt": wkt}
)

# Now
wkt = pyproj.CRS.from_epsg(3857).to_json_dict()
TileMatrixSet(
...
crs={"wkt": wkt}
)
```

## 5.2.0 (2024-01-18)

* fix `CRS` parsing to allow `wkt ({"wkt": ...})` and `uri ({"uri": ...})` defined CRS
Expand Down
15 changes: 6 additions & 9 deletions morecantile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ class CRSUri(BaseModel):


class CRSWKT(BaseModel):
"""Coordinate Reference System (CRS) from WKT."""
"""Coordinate Reference System (CRS) from WKT encoded as PROJJSON Object."""

wkt: Annotated[
str,
Dict,
Field(
description="Reference to one coordinate reference system (CRS) as WKT string",
examples=[
'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]',
],
description="An object defining the CRS using the JSON encoding for Well-known text representation of coordinate reference systems 2.0",
),
]

Expand Down Expand Up @@ -109,7 +106,7 @@ def model_post_init(self, __context: Any) -> None:
self._pyproj_crs = pyproj.CRS.from_user_input(str(self.root.uri))

elif isinstance(self.root, CRSWKT):
self._pyproj_crs = pyproj.CRS.from_wkt(self.root.wkt)
self._pyproj_crs = pyproj.CRS.from_json_dict(self.root.wkt)

elif isinstance(self.root, CRSRef):
raise NotImplementedError(
Expand Down Expand Up @@ -660,10 +657,10 @@ def custom(
try:
pyproj.CRS.from_user_input(crs_data)
except CRSError:
crs_data = {"wkt": crs.to_wkt()}
crs_data = {"wkt": crs.to_json_dict()}

else:
crs_data = {"wkt": crs.to_wkt()}
crs_data = {"wkt": crs.to_json_dict()}

return cls(
crs=crs_data,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def test_crs_type():
assert crs._pyproj_crs == pyproj.CRS.from_epsg(3857)

# CRSWKT
wkt = pyproj.CRS.from_epsg(3857).to_wkt()
wkt = pyproj.CRS.from_epsg(3857).to_json_dict()
crs = CRS({"wkt": wkt})
assert crs.root == CRSWKT(wkt=wkt)
assert crs.model_dump()["wkt"] == wkt
Expand Down

0 comments on commit ef793c7

Please sign in to comment.