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

Update name length check to 57 characters. #117

Merged
merged 2 commits into from
May 28, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ The current checks are (see also the 'show-validations' command):
| RQ13 | It is required to give all GEOMETRY features the same default spatial reference system. |
| RQ14 | The geometry_type_name from the gpkg_geometry_columns table must be one of POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, or MULTIPOLYGON. |
| RQ15 | All table geometries must match the geometry_type_name from the gpkg_geometry_columns table. |
| RQ16 | All layer and column names shall not be longer than 53 characters. |
| RQ16 | _LEGACY:_ * All layer and column names shall not be longer than 53 characters. |
| RC17 | It is recommended to name all GEOMETRY type columns 'geom'. |
| RC18 | It is recommended to give all GEOMETRY type columns the same name. |
| RC19 | It is recommended to only use multidimensional geometry coordinates (elevation and measurement) when necessary. |
| RC20 | It is recommended that all (MULTI)POLYGON geometries have a counter-clockwise orientation for their exterior ring, and a clockwise direction for all interior rings. |
| RQ21 | All layer and column names shall not be longer than 57 characters. |
| UNKNOWN_WARNINGS | It is recommended that the unexpected (GDAL) warnings are looked into. |

\* Legacy requirements are only executed with the validate command when explicitly requested in the validation set.
Expand Down
4 changes: 3 additions & 1 deletion geopackage_validator/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
RQ0 = "RQ0"
RQ3 = "RQ3"
RQ8 = "RQ8"
RQ16 = "RQ16"


# Drop legacy requirements
DROP_LEGACY_RQ_FROM_ALL = [RQ0, RQ3]
DROP_LEGACY_RQ_FROM_ALL = [RQ0, RQ3, RQ16]


def validators_to_use(
Expand Down
6 changes: 5 additions & 1 deletion geopackage_validator/validations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
from geopackage_validator.validations.geometry_dimension_check import (
GeometryDimensionValidator,
)
from geopackage_validator.validations.name_length_check import NameLengthValidator
from geopackage_validator.validations.name_length_check import (
NameLengthValidator,
NameLengthValidatorV0,
)

__all__ = [
# Requirements
Expand All @@ -55,4 +58,5 @@
"GeomColumnNameEqualValidator",
"GeometryDimensionValidator",
"NameLengthValidator",
"NameLengthValidatorV0",
]
30 changes: 27 additions & 3 deletions geopackage_validator/validations/name_length_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from geopackage_validator.validations import validator
from geopackage_validator import utils

LEGACY_MAX_LENGTH = 53
MAX_LENGTH = 57


def query_names(dataset) -> Iterable[Tuple[str, str, int]]:
tables = utils.dataset_geometry_tables(dataset)
Expand All @@ -17,8 +20,8 @@ def query_names(dataset) -> Iterable[Tuple[str, str, int]]:
dataset.ReleaseResultSet(columns)


class NameLengthValidator(validator.Validator):
"""All names must be maximally 53 characters long."""
class NameLengthValidatorV0(validator.Validator):
f"""All names must be maximally {LEGACY_MAX_LENGTH} characters long."""

code = 16
level = validator.ValidationLevel.ERROR
Expand All @@ -34,5 +37,26 @@ def check_columns(cls, names: Iterable[Tuple[str, str, int]]) -> List[str]:
return [
cls.message.format(name=name, name_type=name_type, length=length)
for name_type, name, length in names
if length > 53
if length > MAX_LENGTH
]


class NameLengthValidator(validator.Validator):
f"""All names must be maximally {MAX_LENGTH} characters long."""

code = 21
level = validator.ValidationLevel.ERROR
message = "Error {name_type} too long: {name}, with length: {length}"

def check(self) -> Iterable[str]:
column_names = query_names(self.dataset)
return self.check_columns(column_names)

@classmethod
def check_columns(cls, names: Iterable[Tuple[str, str, int]]) -> List[str]:
assert names is not None
return [
cls.message.format(name=name, name_type=name_type, length=length)
for name_type, name, length in names
if length > MAX_LENGTH
]
2 changes: 1 addition & 1 deletion tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_determine_validations_to_use_none():
"RQ13",
"RQ14",
"RQ15",
"RQ16",
"RQ21",
"RC17",
"RC18",
"RC19",
Expand Down
Loading