Skip to content

Commit

Permalink
only consider geometry in source uri if the table is handled multiple…
Browse files Browse the repository at this point in the history
… times in the same project - because of multiple geometries
  • Loading branch information
signedav committed Oct 21, 2024
1 parent 9f8d62e commit ee2fdb9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modelbaker/db_factory/gpkg_layer_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def __init__(self, uri: str) -> None:
LayerUri.__init__(self, uri)
self.provider = "ogr"

def get_data_source_uri(self, record: dict) -> str:
def get_data_source_uri(self, record: dict, multigeom: bool) -> str:
data_source_uri = "{uri}|layername={table}".format(
uri=self.uri, table=record["tablename"]
)
if record["geometry_column"]:
if multigeom:
data_source_uri = "{} ({})".format(
data_source_uri, record["geometry_column"]
)
Expand Down
2 changes: 1 addition & 1 deletion modelbaker/db_factory/layer_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, uri: str) -> None:
self.provider = None

@abstractmethod
def get_data_source_uri(self, record: dict) -> str:
def get_data_source_uri(self, record: dict, multigeom: bool) -> str:
"""Provides layer uri based on database uri and specific information of the data source.
:param str record: Dictionary containing specific information of the data source.
Expand Down
2 changes: 1 addition & 1 deletion modelbaker/db_factory/mssql_layer_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, uri: str) -> None:
LayerUri.__init__(self, uri)
self.provider = "mssql"

def get_data_source_uri(self, record: dict) -> str:
def get_data_source_uri(self, record: dict, multigeom: bool) -> str:
if record["geometry_column"]:
data_source_uri = '{uri} key={primary_key} estimatedmetadata=true srid={srid} type={type} table="{schema}"."{table}" ({geometry_column}) sql='.format(
uri=self._get_layer_uri_common(),
Expand Down
2 changes: 1 addition & 1 deletion modelbaker/db_factory/pg_layer_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, uri: str) -> None:
self.pg_estimated_metadata = False
self.provider = "postgres"

def get_data_source_uri(self, record: dict) -> str:
def get_data_source_uri(self, record: dict, multigeom: bool) -> str:
if record["geometry_column"]:
str_pg_estimated_metadata = (
"true" if self.pg_estimated_metadata else "false"
Expand Down
8 changes: 7 additions & 1 deletion modelbaker/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ def layers(self, filter_layer_list: list = []) -> list[Layer]:

layer = Layer(
layer_uri.provider,
layer_uri.get_data_source_uri(record),
layer_uri.get_data_source_uri(
record,
bool(
table_appearance_count[record["tablename"]] > 1
and "geometry_column" in record
),
),
record.get("tablename"),
record.get("srid"),
record.get("extent"),
Expand Down

0 comments on commit ee2fdb9

Please sign in to comment.