Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get projection definition from pyproj #2648

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/spell-ignore-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Mapnik
Redis
CloudFront
OpenLayers
pyproj
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ waitress = "3.0.2"
certifi = "2024.8.30"
Paste = "3.10.1"
psutil = "6.1.0"
pyproj = "3.7.0"

[tool.poetry.group.dev.dependencies]
prospector = { extras = ["with_mypy", "with_bandit", "with_pyroma", "with_ruff"], version = "1.13.3" }
Expand Down
2 changes: 1 addition & 1 deletion tilecloud_chain/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- **`postgresql`**: Refer to _[#/definitions/postgresql](#definitions/postgresql)_.
- **`openlayers`** _(object)_: Configuration used to generate the OpenLayers example page. Cannot contain additional properties.
- **`srs`** _(string)_: The projection code. Default: `"EPSG:2056"`.
- **`proj4js_def`** _(string)_: The `proj4js` definition, get it from https://epsg.io/. Default: `"+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs"`.
- **`proj4js_def`** _(string)_: The `proj4js` definition, by default it will be build with pyproj.
- **`center_x`** _(number)_: The center easting. Default: `2600000`.
- **`center_y`** _(number)_: The center northing. Default: `1200000`.
- **`zoom`** _(number)_: The initial zoom. Default: `3`.
Expand Down
8 changes: 1 addition & 7 deletions tilecloud_chain/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,9 +1979,7 @@ class Openlayers(TypedDict, total=False):
"""
Proj4js definition.

The `proj4js` definition, get it from https://epsg.io/

default: +proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs
The `proj4js` definition, by default it will be build with pyproj
"""

center_x: int | float
Expand Down Expand Up @@ -2050,10 +2048,6 @@ class Openlayers(TypedDict, total=False):
""" Default value of the field path 'Redis prefix' """


PROJ4JS_DEFINITION_DEFAULT = "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs"
""" Default value of the field path 'OpenLayers proj4js_def' """


class Phone(TypedDict, total=False):
"""
Phone.
Expand Down
5 changes: 2 additions & 3 deletions tilecloud_chain/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,8 @@
},
"proj4js_def": {
"title": "Proj4js definition",
"description": "The `proj4js` definition, get it from https://epsg.io/",
"type": "string",
"default": "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs"
"description": "The `proj4js` definition, by default it will be build with pyproj",
"type": "string"
},
"center_x": {
"title": "Center x",
Expand Down
16 changes: 7 additions & 9 deletions tilecloud_chain/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
import logging
import multiprocessing
import os
import re
import shlex
import subprocess # nosec
from collections.abc import Callable
from typing import IO, Any
from urllib.parse import urljoin

import pyproj
import pyramid.httpexceptions
import pyramid.request
import pyramid.response
Expand Down Expand Up @@ -307,15 +307,13 @@ def admin_test(self) -> dict[str, Any]:
assert self.gene
config = self.gene.get_host_config(self.request.host)
main_config = self.gene.get_main_config()
srs = config.config["openlayers"].get("srs", configuration.SRS_DEFAULT)
proj4js_def = config.config["openlayers"].get("proj4js_def")
if proj4js_def is None:
proj4js_def = pyproj.CRS.from_string(srs).to_proj4()
return {
"proj4js_def": re.sub(
r"\s+",
" ",
config.config["openlayers"]
.get("proj4js_def", configuration.PROJ4JS_DEFINITION_DEFAULT)
.strip(),
),
"srs": config.config["openlayers"].get("srs", configuration.SRS_DEFAULT),
"proj4js_def": proj4js_def,
"srs": srs,
"center_x": config.config["openlayers"].get("center_x", configuration.CENTER_X_DEFAULT),
"center_y": config.config["openlayers"].get("center_y", configuration.CENTER_Y_DEFAULT),
"zoom": config.config["openlayers"].get("zoom", configuration.MAP_INITIAL_ZOOM_DEFAULT),
Expand Down
Loading