-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specific process for geometries with Z or M coordinate with SpatiaLit…
…e dialect (#506) * Temporary fix for geometries with Z in SpatiaLite. Though most of the dialects support geom_type ending with Z in SQL queries, it seems not working with SpatiaLite. Hence replacing Z with a blank. Added a test to cover this behaviour. * Add a more complete test and propose an extended fix * Handle M coordinate * Change postgis image in test_and_publish.yml to postgis/postgis:16-3.4 Add some formatting for postgresql dialect, MULTIPOINT geom_type. * Enable postgis_raster extension for postgresql gis db. * Fix docs, tests and docker helpers * Fix postgis_raster extension in CI * Update .github/workflows/test_and_publish.yml Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com> * Update .github/workflows/test_and_publish.yml Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com> * Update .github/workflows/test_and_publish.yml Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com>
- Loading branch information
1 parent
de380dc
commit da53834
Showing
8 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
"""This module defines specific functions for SQLite dialect.""" | ||
|
||
import re | ||
|
||
from geoalchemy2.elements import RasterElement | ||
from geoalchemy2.elements import WKBElement | ||
from geoalchemy2.elements import WKTElement | ||
from geoalchemy2.shape import to_shape | ||
|
||
|
||
def format_geom_type(wkt, default_srid=None): | ||
"""Format the Geometry type for SQLite.""" | ||
match = re.match(WKTElement.SPLIT_WKT_PATTERN, wkt) | ||
if match is None: | ||
return wkt | ||
_, srid, geom_type, coords = match.groups() | ||
geom_type = geom_type.replace(" ", "") | ||
if geom_type.endswith("ZM"): | ||
geom_type = geom_type[:-2] | ||
elif geom_type.endswith("Z"): | ||
geom_type = geom_type[:-1] | ||
if srid is None and default_srid is not None: | ||
srid = f"SRID={default_srid}" | ||
if srid is not None: | ||
return "%s;%s%s" % (srid, geom_type, coords) | ||
else: | ||
return "%s%s" % (geom_type, coords) | ||
|
||
|
||
def bind_processor_process(spatial_type, bindvalue): | ||
if isinstance(bindvalue, WKTElement): | ||
if bindvalue.extended: | ||
return "%s" % (bindvalue.data) | ||
else: | ||
return "SRID=%d;%s" % (bindvalue.srid, bindvalue.data) | ||
return format_geom_type( | ||
bindvalue.data, | ||
default_srid=bindvalue.srid if bindvalue.srid >= 0 else spatial_type.srid, | ||
) | ||
elif isinstance(bindvalue, WKBElement): | ||
# With SpatiaLite we use Shapely to convert the WKBElement to an EWKT string | ||
shape = to_shape(bindvalue) | ||
return "SRID=%d;%s" % (bindvalue.srid, shape.wkt) | ||
# shapely.wkb.loads returns geom_type with a 'Z', for example, 'LINESTRING Z' | ||
# which is a limitation with SpatiaLite. Hence, a temporary fix. | ||
res = format_geom_type( | ||
shape.wkt, default_srid=bindvalue.srid if bindvalue.srid >= 0 else spatial_type.srid | ||
) | ||
return res | ||
elif isinstance(bindvalue, RasterElement): | ||
return "%s" % (bindvalue.data) | ||
elif isinstance(bindvalue, str): | ||
return format_geom_type(bindvalue, default_srid=spatial_type.srid) | ||
else: | ||
return bindvalue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters