Skip to content
Snippets Groups Projects

Resolve "Introduce a new filter for when rules should be run based on the source ID of a building."

Compare and Show latest version
2 files
+ 18
16
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 13
11
@@ -18,7 +18,6 @@
import abc
from typing import Union, Optional
import shapely
@@ -30,14 +29,17 @@ class AbstractRule(abc.ABC):
Args:
rule_source_ids (list):
A list of all valid source IDs for the rule. This is provided by the rule's XML
A list of all valid source IDs for the rule. This is provided by the rule's XML file
if relevant.
geographic_filter_boundary (str):
Boundary polygon in WKT format defining the geographic boundary of the rule.
"""
def __init__(self, rule_source_ids: Optional[list | None] = None,
geographic_filter_boundary: Optional[str | None] = None):
def __init__(
self,
rule_source_ids: list | None = None,
geographic_filter_boundary: str | None = None,
):
self.geographic_filter_boundary_geometry = None
if geographic_filter_boundary is not None:
@@ -45,7 +47,6 @@ class AbstractRule(abc.ABC):
geographic_filter_boundary
)
self.rule_source_ids = rule_source_ids
@abc.abstractmethod
@@ -54,7 +55,7 @@ class AbstractRule(abc.ABC):
The `__call__` method implements the core process of the rule.
"""
def parse_data(self, data: Union[str, bytes], source_file: str):
def parse_data(self, data: str | bytes, source_file: str):
"""
The `parse_data` method can be used to parse files that are attached to the
rule. As file types can widely vary, this method needs to be implemented for each
@@ -86,7 +87,7 @@ class AbstractRule(abc.ABC):
"""
Applies a spatial filter to ensure that only buildings within the provided geographic
polygon are processed and a source filter to ensure source-specific rules only run
for inputs with a matching source ID.
for buildings with a matching source ID.
Args:
longitude (float):
@@ -94,14 +95,15 @@ class AbstractRule(abc.ABC):
latitude (float):
Latitude of the building being processed.
source_id (int):
Integer representing the input-source ID, and determines the rule's relevance.
Integer representing the building-source ID.
Returns:
bool:
`True` if all tests pass and `False` if at least one doesn't pass.
True if all tests pass and False if at least one does not pass.
"""
# Geographic filter, passes if the inputs coordinates lie within the boundary geometry.
# Geographic filter, passes if the building's coordinates lie within the boundary
# geometry.
if (
self.geographic_filter_boundary_geometry is not None
and self.geographic_filter_boundary_geometry.disjoint(
@@ -110,7 +112,7 @@ class AbstractRule(abc.ABC):
):
return False
# Source ID filter, passes if the rule's and the source ID match.
# Source ID filter, passes if the rule's source ID and the building-source ID match.
if self.rule_source_ids is not None and source_id not in self.rule_source_ids:
return False
return True
Loading