Skip to content

Commit

Permalink
#127 Infer in on authority cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Tisham Dhar authored and whatnick committed Jun 16, 2020
1 parent 498b090 commit 47a9d26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cubedash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def infer_crs(crs_str: str) -> Optional[str]:
if len(closest_wkt) == 0:
return
epsg = PJCRS.from_wkt(closest_wkt[0]).to_epsg()
return f"EPSG:{epsg}"
return f"epsg:{epsg}"


def render(template, **context):
Expand Down
27 changes: 16 additions & 11 deletions cubedash/summary/_extents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
from pathlib import Path
from typing import Dict, Iterable, Optional

import datacube.drivers.postgres._api as postgres_api
import fiona
import shapely.wkb
import structlog
from cubedash._utils import alchemy_engine
from cubedash.summary._schema import DATASET_SPATIAL, SPATIAL_REF_SYS
from datacube import Datacube
from datacube.drivers.postgres._fields import PgDocField, RangeDocField
from datacube.drivers.postgres._schema import DATASET
from datacube.index import Index
from datacube.model import DatasetType, MetadataType
from geoalchemy2 import Geometry, WKBElement
from geoalchemy2.shape import to_shape
from psycopg2._range import Range as PgRange
Expand All @@ -37,6 +29,15 @@
from sqlalchemy.engine import Engine
from sqlalchemy.sql import ColumnElement

import datacube.drivers.postgres._api as postgres_api
from cubedash._utils import alchemy_engine, infer_crs
from cubedash.summary._schema import DATASET_SPATIAL, SPATIAL_REF_SYS
from datacube import Datacube
from datacube.drivers.postgres._fields import PgDocField, RangeDocField
from datacube.drivers.postgres._schema import DATASET
from datacube.index import Index
from datacube.model import DatasetType, MetadataType

_LOG = structlog.get_logger()

_WRS_PATH_ROW = [
Expand Down Expand Up @@ -133,9 +134,13 @@ def get_dataset_srid_alchemy_expression(md: MetadataType, default_crs: str = Non
if not default_crs.lower().startswith(
"epsg:"
) and not default_crs.lower().startswith("esri:"):
raise NotImplementedError(
f"CRS expected in form of 'EPSG:1234'. Got: {default_crs!r}"
)
# HACK: Change default CRS with inference
inferred_crs = infer_crs(default_crs)
if inferred_crs is None:
raise NotImplementedError(
f"CRS expected in form of 'EPSG:1234'. Got: {default_crs!r}"
)
default_crs = inferred_crs

auth_name, auth_srid = default_crs.split(":")
default_crs_expression = (
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_arb_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def test_crs_infer_fail():


def test_crs_infer_pass():
assert infer_crs(TEST_CRS_RAW) == "EPSG:4283"
assert infer_crs(TEST_CRS_RAW) == "epsg:4283"

0 comments on commit 47a9d26

Please sign in to comment.