Skip to content

Commit

Permalink
Update name length check to 57 characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoelvandenBerg authored and Shalucik committed May 28, 2024
1 parent dd9894e commit 69f372e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
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
3 changes: 2 additions & 1 deletion geopackage_validator/validations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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 +55,5 @@
"GeomColumnNameEqualValidator",
"GeometryDimensionValidator",
"NameLengthValidator",
"NameLengthValidatorV0",
]
29 changes: 26 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,8 @@
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 +19,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 +36,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

0 comments on commit 69f372e

Please sign in to comment.