-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Iterable, Tuple | ||
from geopackage_validator.validations import validator | ||
from geopackage_validator import utils | ||
|
||
|
||
SQL_TEMPLATE = """SELECT | ||
count(rowid) AS count, | ||
cast(rowid AS INTEGER) AS row_id | ||
FROM "{table_name}" WHERE ST_IsSimple("{column_name}") = 0""" | ||
|
||
|
||
def query_geometry_simple(dataset) -> Iterable[Tuple[str, str, int]]: | ||
columns = utils.dataset_geometry_tables(dataset) | ||
|
||
for table_name, column_name, _ in columns: | ||
|
||
validations = dataset.ExecuteSQL( | ||
SQL_TEMPLATE.format(table_name=table_name, column_name=column_name) | ||
) | ||
for count, row_id in validations: | ||
if count > 0: | ||
yield table_name, column_name, count, row_id | ||
dataset.ReleaseResultSet(validations) | ||
|
||
|
||
class SimpleGeometryValidator(validator.Validator): | ||
"""Geometries should be simple.""" | ||
|
||
code = 23 | ||
level = validator.ValidationLevel.ERROR | ||
message = "Found not simple geometry in table: {table_name}, column {column_name}, {count} {count_label}, example id {row_id}" | ||
|
||
def check(self) -> Iterable[str]: | ||
result = query_geometry_simple(self.dataset) | ||
|
||
return [ | ||
self.message.format( | ||
table_name=table_name, | ||
column_name=column_name, | ||
count=count, | ||
count_label=("time" if count == 1 else "times"), | ||
row_id=row_id, | ||
) | ||
for table_name, column_name, count, row_id in result | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from geopackage_validator.utils import open_dataset | ||
from geopackage_validator.validations.geometry_simple_check import query_geometry_simple | ||
|
||
|
||
def test_with_gpkg(): | ||
dataset = open_dataset("tests/data/test_geometry_simple.gpkg") | ||
checks = list(query_geometry_simple(dataset)) | ||
assert len(checks) == 1 | ||
assert checks[0][0] == "test_geometry_simple" | ||
assert checks[0][1] == "geometry" | ||
assert checks[0][2] == 1 | ||
assert checks[0][3] == 1 | ||
|
||
|
||
def test_with_gpkg_allcorrect(): | ||
dataset = open_dataset("tests/data/test_allcorrect.gpkg") | ||
checks = list(query_geometry_simple(dataset)) | ||
assert len(checks) == 0 |