Skip to content

Commit

Permalink
Merge pull request #866 from koordinates/fix-no-crs
Browse files Browse the repository at this point in the history
Fix no crs
  • Loading branch information
olsen232 committed Jun 12, 2023
2 parents f67c252 + 12b307c commit bf5c4b0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where
- Fixes a bug where tab-completion wasn't working with helper mode, affects macOS and Linux. [#851](https://github.com/koordinates/kart/pull/851)
- Fixes a bug where git-lfs (and potentially other subprocesses) wasn't working reliably with helper mode, affects macOS and Linux. [#853](https://github.com/koordinates/kart/issues/853)
- `import` now informs the user to use `add-dataset` instead if they try to import a table that is already inside the working copy. [#249](https://github.com/koordinates/kart/issues/249)
- Fixes a bug where datasets with no CRS couldn't be checked out into a Geopackage working copy. [#855](https://github.com/koordinates/kart/issues/855)

## 0.12.3

Expand Down
3 changes: 3 additions & 0 deletions kart/create_workingcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def create_workingcopy(ctx, parts, delete_existing, discard_changes, tabular_loc
created with a default name based on the repository name.
"""
repo = ctx.obj.repo
if repo.is_bare:
raise InvalidOperation("Can't create a working copy for a bare repository")

if repo.head_is_unborn:
raise InvalidOperation(
"Can't create a working copy for an empty repository — first import some data with `kart import`"
Expand Down
2 changes: 1 addition & 1 deletion kart/sqlalchemy/adapter/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _ms_type_to_v2_geometry_type(cls, ms_col_info, ms_crs_info):
(r for r in ms_crs_info if r["column_name"] == ms_col_info["column_name"]),
None,
)
if crs_row:
if crs_row and crs_row["srid"]:
auth_name = crs_row["authority_name"]
auth_code = crs_row["authorized_spatial_reference_id"]
if not auth_name and not auth_code:
Expand Down
4 changes: 2 additions & 2 deletions kart/tabular/working_copy/gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path

import click
from osgeo import gdal

import sqlalchemy as sa
from kart import crs_util
Expand Down Expand Up @@ -193,7 +192,8 @@ def status(self, check_if_dirty=False, allow_unconnectable=False):
def create_and_initialise(self):
with self.session() as sess:
# Create standard GPKG tables:
GpkgTables().create_all(sess)
GpkgTables.create_all(sess)
GpkgTables.init_table_contents(sess)
# Create Kart-specific tables:
self.kart_tables.create_all(sess)

Expand Down
41 changes: 41 additions & 0 deletions kart/tabular/working_copy/table_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,47 @@ def __init__(self):
),
)

EPSG_4326_WKT = (
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],'
'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'
)

GPKG_SPATIAL_REF_SYS_INITIAL_CONTENTS = [
{
"srs_name": "Undefined cartesian SRS",
"srs_id": -1,
"organization": "NONE",
"organization_coordsys_id": -1,
"definition": "undefined",
"description": "undefined cartesian coordinate reference system",
},
{
"srs_name": "Undefined geographic SRS",
"srs_id": 0,
"organization": "NONE",
"organization_coordsys_id": 0,
"definition": "undefined",
"description": "undefined geographic coordinate reference system",
},
{
"srs_name": "WGS 84 geodetic",
"srs_id": 4326,
"organization": "EPSG",
"organization_coordsys_id": 4326,
"definition": EPSG_4326_WKT,
"description": "longitude/latitude coordinates in decimal degrees on the WGS 84 spheroid",
},
]

@classmethod
def init_table_contents(cls, sess):
from kart.sqlalchemy.upsert import Upsert as upsert

sess.execute(
upsert(cls.gpkg_spatial_ref_sys),
cls.GPKG_SPATIAL_REF_SYS_INITIAL_CONTENTS,
)


# Makes it so GPKG table definitions are also accessible at the GpkgTables class itself:
GpkgTables.copy_tables_to_class()
Binary file modified tests/data/points-no-crs.tgz
Binary file not shown.
1 change: 0 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ def test_init_import_with_no_crs(
r = cli_runner.invoke(
[
"init",
"--bare",
"--import",
f"gpkg:{data / 'nz-pa-points-topo-150k.gpkg'}",
str(repo_path),
Expand Down
13 changes: 2 additions & 11 deletions tests/test_working_copy_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,22 +1191,13 @@ def test_checkout_custom_crs(data_working_copy, cli_runner, dodgy_restore):
]


def test_checkout_and_status_with_no_crs(
def test_checkout_with_no_crs(
data_working_copy,
tmp_path,
cli_runner,
):
repo_path = tmp_path / "repo"
repo_path.mkdir()

with data_working_copy("points-no-crs") as (repo_dir, wc):
r = cli_runner.invoke(
[
"-C",
str(repo_dir),
"status",
]
)
r = cli_runner.invoke(["diff", "--exit-code"])
assert r.exit_code == 0, r.stderr


Expand Down
15 changes: 3 additions & 12 deletions tests/test_working_copy_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,23 +519,14 @@ def test_checkout_custom_crs(
]


def test_checkout_and_status_with_no_crs(
def test_checkout_with_no_crs(
new_mysql_db_schema,
data_archive,
tmp_path,
cli_runner,
):
repo_path = tmp_path / "repo"
repo_path.mkdir()

with data_archive("points-no-crs") as repo_path:
with new_mysql_db_schema() as (mysql_url, mysql_schema):
r = cli_runner.invoke(["create-workingcopy", mysql_url])
r = cli_runner.invoke(
[
"-C",
str(repo_path),
"status",
]
)
assert r.exit_code == 0, r.stderr
r = cli_runner.invoke(["diff", "--exit-code"])
assert r.exit_code == 0
15 changes: 3 additions & 12 deletions tests/test_working_copy_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,17 @@ def test_init_import(
assert table_wc.location == postgres_url


def test_checkout_and_status_with_no_crs(
def test_checkout_with_no_crs(
new_postgis_db_schema,
data_archive,
tmp_path,
cli_runner,
):
repo_path = tmp_path / "repo"
repo_path.mkdir()

with data_archive("points-no-crs") as repo_path:
with new_postgis_db_schema() as (postgres_url, postgres_schema):
r = cli_runner.invoke(["create-workingcopy", postgres_url])
r = cli_runner.invoke(
[
"-C",
str(repo_path),
"status",
]
)
assert r.exit_code == 0, r.stderr
r = cli_runner.invoke(["diff", "--exit-code"])
assert r.exit_code == 0


@pytest.mark.parametrize(
Expand Down
13 changes: 2 additions & 11 deletions tests/test_working_copy_sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,20 +638,11 @@ def test_checkout_and_status_with_no_crs(
tmp_path,
cli_runner,
):
repo_path = tmp_path / "repo"
repo_path.mkdir()

with data_archive("points-no-crs") as repo_path:
with new_sqlserver_db_schema() as (sqlserver_url, sqlserver_schema):
r = cli_runner.invoke(["create-workingcopy", sqlserver_url])
r = cli_runner.invoke(
[
"-C",
str(repo_path),
"status",
]
)
assert r.exit_code == 0, r.stderr
r = cli_runner.invoke(["diff", "--exit-code"])
assert r.exit_code == 0


def test_checkout_large_geometry(
Expand Down

0 comments on commit bf5c4b0

Please sign in to comment.