GeoAlchemy2 0.15.2__py3-none-any.whl → 0.16.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {GeoAlchemy2-0.15.2.dist-info → GeoAlchemy2-0.16.0.dist-info}/METADATA +3 -3
- {GeoAlchemy2-0.15.2.dist-info → GeoAlchemy2-0.16.0.dist-info}/RECORD +9 -8
- {GeoAlchemy2-0.15.2.dist-info → GeoAlchemy2-0.16.0.dist-info}/WHEEL +1 -1
- geoalchemy2/admin/dialects/mysql.py +74 -6
- geoalchemy2/types/__init__.py +4 -4
- geoalchemy2/types/dialects/__init__.py +1 -0
- geoalchemy2/types/dialects/mariadb.py +47 -0
- {GeoAlchemy2-0.15.2.dist-info → GeoAlchemy2-0.16.0.dist-info}/COPYING.rst +0 -0
- {GeoAlchemy2-0.15.2.dist-info → GeoAlchemy2-0.16.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: GeoAlchemy2
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.16.0
|
4
4
|
Summary: Using SQLAlchemy with Spatial Databases
|
5
5
|
Home-page: https://geoalchemy-2.readthedocs.io/en/stable/
|
6
6
|
Author: Eric Lemoine
|
@@ -24,10 +24,10 @@ Classifier: License :: OSI Approved :: MIT License
|
|
24
24
|
Classifier: Topic :: Scientific/Engineering :: GIS
|
25
25
|
Requires-Python: >=3.7
|
26
26
|
License-File: COPYING.rst
|
27
|
-
Requires-Dist: SQLAlchemy
|
27
|
+
Requires-Dist: SQLAlchemy>=1.4
|
28
28
|
Requires-Dist: packaging
|
29
29
|
Provides-Extra: shapely
|
30
|
-
Requires-Dist: Shapely
|
30
|
+
Requires-Dist: Shapely>=1.7; extra == "shapely"
|
31
31
|
|
32
32
|
============
|
33
33
|
GeoAlchemy 2
|
@@ -14,18 +14,19 @@ geoalchemy2/admin/__init__.py,sha256=s8L5C9pYC5dTxhIp9j-JzWeg9kEJevXUW8Pq4_L4aZ8
|
|
14
14
|
geoalchemy2/admin/dialects/__init__.py,sha256=XodzuBbWKkkSQzM5EL3I33azuE-y_go0nVOlmIyJ13g,367
|
15
15
|
geoalchemy2/admin/dialects/common.py,sha256=8OkGa7T2Gxz2vDVnC9nva8Ma0YqBwGxHWfBJoZF1cNQ,2936
|
16
16
|
geoalchemy2/admin/dialects/geopackage.py,sha256=UaJignKtlo13oHxq92yescVJtXFEXkm4fy5WzR6sLT8,13469
|
17
|
-
geoalchemy2/admin/dialects/mysql.py,sha256=
|
17
|
+
geoalchemy2/admin/dialects/mysql.py,sha256=b_34MDv2I615YdZI3h_KoH4cyoMG2cTKQm1Slh5p2qQ,9043
|
18
18
|
geoalchemy2/admin/dialects/postgresql.py,sha256=VwB_h3TC8M5aQ6aKE3UYgxHfbEKav3eIHJeLx534Zzg,6191
|
19
19
|
geoalchemy2/admin/dialects/sqlite.py,sha256=UYQuNDDy-1-lsvYlqyKy01UtHgLF4iEN42fE5D-9QQk,13597
|
20
|
-
geoalchemy2/types/__init__.py,sha256=
|
21
|
-
geoalchemy2/types/dialects/__init__.py,sha256=
|
20
|
+
geoalchemy2/types/__init__.py,sha256=r2gscVpcxebsEgZnSA6V9pSvO6V9DSzGkDRfSxrmXdk,14243
|
21
|
+
geoalchemy2/types/dialects/__init__.py,sha256=GYqO6nDtzElvsV22VN1SSUet2elaZG4ZuRrM-asbstM,414
|
22
22
|
geoalchemy2/types/dialects/common.py,sha256=gxKaRQhIODJhu_yBurlvFNAqGh3LfPNu_DcObEG1wlU,138
|
23
23
|
geoalchemy2/types/dialects/geopackage.py,sha256=nRmN_PnF-CWMEHkWhKVdsybnw3SvXZIBXAHIHXJLTqw,147
|
24
|
+
geoalchemy2/types/dialects/mariadb.py,sha256=tPZpfj95XlVSOm8zC52iFbqVrIOdj-EDH5KVJP1Gd9c,1723
|
24
25
|
geoalchemy2/types/dialects/mysql.py,sha256=zMNi1920v0XlVaCJWSwtq0b0P5YQRn8y3X_rBxC5KEw,1790
|
25
26
|
geoalchemy2/types/dialects/postgresql.py,sha256=7NBKEbDJXMwX8Sgs6o_N2bAUHgjUcjbrdmYOA7sDiRw,1117
|
26
27
|
geoalchemy2/types/dialects/sqlite.py,sha256=B-yLzaQcqL_4dXoOPX9D9IXw2ZQlq-Tibv_kqUIBeb4,2104
|
27
|
-
GeoAlchemy2-0.
|
28
|
-
GeoAlchemy2-0.
|
29
|
-
GeoAlchemy2-0.
|
30
|
-
GeoAlchemy2-0.
|
31
|
-
GeoAlchemy2-0.
|
28
|
+
GeoAlchemy2-0.16.0.dist-info/COPYING.rst,sha256=-bQKftq9uMOROzF7oN65kYBBIJKxTmBuDoftp27IC3I,1056
|
29
|
+
GeoAlchemy2-0.16.0.dist-info/METADATA,sha256=oM7Fr3V8L1xyD7SXdFjwcYSHVMEHIUb-yhM-D2V-b70,2084
|
30
|
+
GeoAlchemy2-0.16.0.dist-info/WHEEL,sha256=a7TGlA-5DaHMRrarXjVbQagU3Man_dCnGIWMJr5kRWo,91
|
31
|
+
GeoAlchemy2-0.16.0.dist-info/top_level.txt,sha256=3kGUTcfBeXd61zFpof6-qiuw1peNF_HuZabgHQgrdis,12
|
32
|
+
GeoAlchemy2-0.16.0.dist-info/RECORD,,
|
@@ -8,6 +8,9 @@ from geoalchemy2 import functions
|
|
8
8
|
from geoalchemy2.admin.dialects.common import _check_spatial_type
|
9
9
|
from geoalchemy2.admin.dialects.common import _spatial_idx_name
|
10
10
|
from geoalchemy2.admin.dialects.common import setup_create_drop
|
11
|
+
from geoalchemy2.elements import WKBElement
|
12
|
+
from geoalchemy2.elements import WKTElement
|
13
|
+
from geoalchemy2.shape import to_shape
|
11
14
|
from geoalchemy2.types import Geography
|
12
15
|
from geoalchemy2.types import Geometry
|
13
16
|
|
@@ -31,11 +34,16 @@ def reflect_geometry_column(inspector, table, column_info):
|
|
31
34
|
column_name = column_info.get("name")
|
32
35
|
schema = table.schema or inspector.default_schema_name
|
33
36
|
|
37
|
+
if inspector.dialect.name == "mariadb":
|
38
|
+
select_srid = "-1, "
|
39
|
+
else:
|
40
|
+
select_srid = "SRS_ID, "
|
41
|
+
|
34
42
|
# Check geometry type, SRID and if the column is nullable
|
35
|
-
geometry_type_query = """SELECT DATA_TYPE,
|
43
|
+
geometry_type_query = """SELECT DATA_TYPE, {}IS_NULLABLE
|
36
44
|
FROM INFORMATION_SCHEMA.COLUMNS
|
37
45
|
WHERE TABLE_NAME = '{}' and COLUMN_NAME = '{}'""".format(
|
38
|
-
table.name, column_name
|
46
|
+
select_srid, table.name, column_name
|
39
47
|
)
|
40
48
|
if schema is not None:
|
41
49
|
geometry_type_query += """ and table_schema = '{}'""".format(schema)
|
@@ -176,25 +184,85 @@ def _compile_GeomFromWKB_MySql(element, compiler, **kw):
|
|
176
184
|
return "{}({})".format(element.identifier, compiled)
|
177
185
|
|
178
186
|
|
187
|
+
def _compile_GeomFromText_MariaDB(element, compiler, **kw):
|
188
|
+
element.identifier = "ST_GeomFromText"
|
189
|
+
compiled = compiler.process(element.clauses, **kw)
|
190
|
+
try:
|
191
|
+
clauses = list(element.clauses)
|
192
|
+
data_element = WKTElement(clauses[0].value)
|
193
|
+
srid = max(0, data_element.srid)
|
194
|
+
if srid <= 0:
|
195
|
+
srid = max(0, element.type.srid)
|
196
|
+
if len(clauses) > 1 and srid > 0:
|
197
|
+
clauses[1].value = srid
|
198
|
+
except Exception:
|
199
|
+
srid = max(0, element.type.srid)
|
200
|
+
|
201
|
+
if srid > 0:
|
202
|
+
res = "{}({}, {})".format(element.identifier, compiled, srid)
|
203
|
+
else:
|
204
|
+
res = "{}({})".format(element.identifier, compiled)
|
205
|
+
return res
|
206
|
+
|
207
|
+
|
208
|
+
def _compile_GeomFromWKB_MariaDB(element, compiler, **kw):
|
209
|
+
element.identifier = "ST_GeomFromText"
|
210
|
+
|
211
|
+
try:
|
212
|
+
clauses = list(element.clauses)
|
213
|
+
data_element = WKBElement(clauses[0].value)
|
214
|
+
srid = max(0, data_element.srid)
|
215
|
+
if srid <= 0:
|
216
|
+
srid = max(0, element.type.srid)
|
217
|
+
clauses[0].value = to_shape(data_element).wkt.encode("utf-8")
|
218
|
+
if len(clauses) > 1 and srid > 0:
|
219
|
+
clauses[1].value = srid
|
220
|
+
except Exception:
|
221
|
+
srid = max(0, element.type.srid)
|
222
|
+
compiled = compiler.process(element.clauses, **kw)
|
223
|
+
|
224
|
+
if srid > 0:
|
225
|
+
res = "{}({}, {})".format(element.identifier, compiled, srid)
|
226
|
+
else:
|
227
|
+
res = "{}({})".format(element.identifier, compiled)
|
228
|
+
return res
|
229
|
+
|
230
|
+
|
179
231
|
@compiles(functions.ST_GeomFromText, "mysql") # type: ignore
|
180
|
-
@compiles(functions.ST_GeomFromText, "mariadb") # type: ignore
|
181
232
|
def _MySQL_ST_GeomFromText(element, compiler, **kw):
|
182
233
|
return _compile_GeomFromText_MySql(element, compiler, **kw)
|
183
234
|
|
184
235
|
|
185
236
|
@compiles(functions.ST_GeomFromEWKT, "mysql") # type: ignore
|
186
|
-
@compiles(functions.ST_GeomFromEWKT, "mariadb") # type: ignore
|
187
237
|
def _MySQL_ST_GeomFromEWKT(element, compiler, **kw):
|
188
238
|
return _compile_GeomFromText_MySql(element, compiler, **kw)
|
189
239
|
|
190
240
|
|
241
|
+
@compiles(functions.ST_GeomFromText, "mariadb") # type: ignore
|
242
|
+
def _MariaDB_ST_GeomFromText(element, compiler, **kw):
|
243
|
+
return _compile_GeomFromText_MariaDB(element, compiler, **kw)
|
244
|
+
|
245
|
+
|
246
|
+
@compiles(functions.ST_GeomFromEWKT, "mariadb") # type: ignore
|
247
|
+
def _MariaDB_ST_GeomFromEWKT(element, compiler, **kw):
|
248
|
+
return _compile_GeomFromText_MariaDB(element, compiler, **kw)
|
249
|
+
|
250
|
+
|
191
251
|
@compiles(functions.ST_GeomFromWKB, "mysql") # type: ignore
|
192
|
-
@compiles(functions.ST_GeomFromWKB, "mariadb") # type: ignore
|
193
252
|
def _MySQL_ST_GeomFromWKB(element, compiler, **kw):
|
194
253
|
return _compile_GeomFromWKB_MySql(element, compiler, **kw)
|
195
254
|
|
196
255
|
|
197
256
|
@compiles(functions.ST_GeomFromEWKB, "mysql") # type: ignore
|
198
|
-
@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore
|
199
257
|
def _MySQL_ST_GeomFromEWKB(element, compiler, **kw):
|
200
258
|
return _compile_GeomFromWKB_MySql(element, compiler, **kw)
|
259
|
+
|
260
|
+
|
261
|
+
@compiles(functions.ST_GeomFromWKB, "mariadb") # type: ignore
|
262
|
+
def _MariaDB_ST_GeomFromWKB(element, compiler, **kw):
|
263
|
+
return _compile_GeomFromWKB_MariaDB(element, compiler, **kw)
|
264
|
+
|
265
|
+
|
266
|
+
@compiles(functions.ST_GeomFromEWKB, "mariadb") # type: ignore
|
267
|
+
def _MariaDB_ST_GeomFromEWKB(element, compiler, **kw):
|
268
|
+
return _compile_GeomFromWKB_MariaDB(element, compiler, **kw)
|
geoalchemy2/types/__init__.py
CHANGED
@@ -40,7 +40,7 @@ def select_dialect(dialect_name):
|
|
40
40
|
known_dialects = {
|
41
41
|
"geopackage": dialects.geopackage,
|
42
42
|
"mysql": dialects.mysql,
|
43
|
-
"mariadb": dialects.
|
43
|
+
"mariadb": dialects.mariadb,
|
44
44
|
"postgresql": dialects.postgresql,
|
45
45
|
"sqlite": dialects.sqlite,
|
46
46
|
}
|
@@ -198,9 +198,9 @@ class _GISType(UserDefinedType):
|
|
198
198
|
return geometry_type, srid
|
199
199
|
|
200
200
|
|
201
|
-
@compiles(_GISType, "mariadb")
|
202
201
|
@compiles(_GISType, "mysql")
|
203
|
-
|
202
|
+
@compiles(_GISType, "mariadb")
|
203
|
+
def get_col_spec_mysql(self, compiler, *args, **kwargs):
|
204
204
|
if self.geometry_type is not None:
|
205
205
|
spec = "%s" % self.geometry_type
|
206
206
|
else:
|
@@ -208,7 +208,7 @@ def get_col_spec(self, *args, **kwargs):
|
|
208
208
|
|
209
209
|
if not self.nullable or self.spatial_index:
|
210
210
|
spec += " NOT NULL"
|
211
|
-
if self.srid > 0:
|
211
|
+
if self.srid > 0 and compiler.dialect.name != "mariadb":
|
212
212
|
spec += " SRID %d" % self.srid
|
213
213
|
return spec
|
214
214
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
from geoalchemy2.types.dialects import common # noqa
|
4
4
|
from geoalchemy2.types.dialects import geopackage # noqa
|
5
|
+
from geoalchemy2.types.dialects import mariadb # noqa
|
5
6
|
from geoalchemy2.types.dialects import mysql # noqa
|
6
7
|
from geoalchemy2.types.dialects import postgresql # noqa
|
7
8
|
from geoalchemy2.types.dialects import sqlite # noqa
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"""This module defines specific functions for MySQL dialect."""
|
2
|
+
|
3
|
+
from geoalchemy2.elements import WKBElement
|
4
|
+
from geoalchemy2.elements import WKTElement
|
5
|
+
from geoalchemy2.elements import _SpatialElement
|
6
|
+
from geoalchemy2.exc import ArgumentError
|
7
|
+
from geoalchemy2.shape import to_shape
|
8
|
+
|
9
|
+
|
10
|
+
def bind_processor_process(spatial_type, bindvalue):
|
11
|
+
if isinstance(bindvalue, str):
|
12
|
+
wkt_match = WKTElement._REMOVE_SRID.match(bindvalue)
|
13
|
+
srid = wkt_match.group(2)
|
14
|
+
try:
|
15
|
+
if srid is not None:
|
16
|
+
srid = int(srid)
|
17
|
+
except (ValueError, TypeError): # pragma: no cover
|
18
|
+
raise ArgumentError(
|
19
|
+
f"The SRID ({srid}) of the supplied value can not be casted to integer"
|
20
|
+
)
|
21
|
+
|
22
|
+
if srid is not None and srid != spatial_type.srid:
|
23
|
+
raise ArgumentError(
|
24
|
+
f"The SRID ({srid}) of the supplied value is different "
|
25
|
+
f"from the one of the column ({spatial_type.srid})"
|
26
|
+
)
|
27
|
+
return wkt_match.group(3)
|
28
|
+
|
29
|
+
if (
|
30
|
+
isinstance(bindvalue, _SpatialElement)
|
31
|
+
and bindvalue.srid != -1
|
32
|
+
and bindvalue.srid != spatial_type.srid
|
33
|
+
):
|
34
|
+
raise ArgumentError(
|
35
|
+
f"The SRID ({bindvalue.srid}) of the supplied value is different "
|
36
|
+
f"from the one of the column ({spatial_type.srid})"
|
37
|
+
)
|
38
|
+
|
39
|
+
if isinstance(bindvalue, WKTElement):
|
40
|
+
bindvalue = bindvalue.as_wkt()
|
41
|
+
if bindvalue.srid <= 0:
|
42
|
+
bindvalue.srid = spatial_type.srid
|
43
|
+
return bindvalue
|
44
|
+
elif isinstance(bindvalue, WKBElement):
|
45
|
+
# With MariaDB we use Shapely to convert the WKBElement to an EWKT string
|
46
|
+
return to_shape(bindvalue).wkt
|
47
|
+
return bindvalue
|
File without changes
|
File without changes
|