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
1 file
+ 12
12
Compare changes
  • Side-by-side
  • Inline
+ 12
12
@@ -18,7 +18,6 @@
import abc
from typing import Union, Optional
import shapely
@@ -38,8 +37,8 @@ class AbstractRule(abc.ABC):
def __init__(
self,
rule_source_ids: Optional[list | None] = None,
geographic_filter_boundary: Optional[str | None] = None,
rule_source_ids: list | None = None,
geographic_filter_boundary: str | None = None,
):
self.geographic_filter_boundary_geometry = None
@@ -56,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
@@ -79,16 +78,16 @@ class AbstractRule(abc.ABC):
def filter(
self,
longitude: Optional[float | None] = None,
latitude: Optional[float | None] = None,
source_id: Optional[int | None] = None,
longitude: float | None = None,
latitude: float | None = None,
source_id: int | None = None,
*args,
**kwargs
):
"""
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):
@@ -96,14 +95,15 @@ class AbstractRule(abc.ABC):
latitude (float):
Latitude of the building being processed.
source_id (int):
Integer representing the input-source ID.
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(
@@ -112,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