Skip to content

Commit

Permalink
Improve error message for chaning CRSes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyh committed Oct 12, 2021
1 parent 5183e78 commit d1970cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cubedash/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ def convert(self, value, param, ctx):
"--epsg",
"epsg_code",
type=int,
default=DEFAULT_EPSG,
show_default=True,
help="The equal-area epsg code to use internally for grouping spatial data",
# We default to None as we want to know later if they explicitly specified one or not.
default=None,
help=f"The equal-area epsg code to use internally for grouping spatial data. "
f"(default: {DEFAULT_EPSG})",
)
@click.option(
"--verbose",
Expand Down
2 changes: 1 addition & 1 deletion cubedash/summary/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
)

# An SQLAlchemy expression to read the configured SRID.
FOOTPRINT_SRID_EXPRESSION = func.FindSRID(
FOOTPRINT_SRID_EXPRESSION = func.Find_SRID(
TIME_OVERVIEW.schema, TIME_OVERVIEW.name, "footprint_geometry"
)

Expand Down
33 changes: 31 additions & 2 deletions cubedash/summary/_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class ProductLocationSample:
example_uris: List[str]


_NOT_SET = object()


class SummaryStore:
def __init__(self, index: Index, summariser: Summariser, log=_LOG) -> None:
self.index = index
Expand Down Expand Up @@ -253,16 +256,42 @@ def is_schema_compatible(self, for_writing_operations_too=False) -> bool:
else:
return _schema.is_compatible_schema(self._engine)

def init(self, grouping_epsg_code: int = DEFAULT_EPSG):
def init(self, grouping_epsg_code: int = None):
"""
Initialise any schema elements that don't exist.
Takes an epsg_code, of the CRS used internally for summaries.
(Requires `create` permissions in the db)
"""

# Add any missing schema items or patches.
_schema.create_schema(self._engine, epsg_code=grouping_epsg_code)
_schema.create_schema(
self._engine, epsg_code=grouping_epsg_code or DEFAULT_EPSG
)

# If they specified an epsg code, make sure the existing schema uses it.
if grouping_epsg_code:
crs_used_by_schema = self.grouping_crs
if crs_used_by_schema != f"EPSG:{grouping_epsg_code}":
raise RuntimeError(
f"""
Tried to initialise with EPSG:{grouping_epsg_code!r},
but the schema is already using {crs_used_by_schema}.
To change the CRS, you need to drop Explorer's schema first.
Eg.
cubedash-gen --drop
And create with the new code:
cubedash-gen --init --epsg {grouping_epsg_code}
(Warning: this can take a long time!)
"""
)
refresh_also = _schema.update_schema(self._engine)

if refresh_also:
Expand Down

0 comments on commit d1970cc

Please sign in to comment.