Clean up FromWKB, FromWKT code

Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
This commit is contained in:
Ondřej Böhm 2022-09-26 10:02:01 +02:00
parent abc5a54c78
commit f26698f8e6
3 changed files with 7 additions and 12 deletions

View File

@ -63,8 +63,8 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
)
function_names = {
'FromWKB': 'ST_GeomFromWKB',
'FromWKT': 'ST_GeomFromText',
"FromWKB": "ST_GeomFromWKB",
"FromWKT": "ST_GeomFromText",
}
@cached_property

View File

@ -328,7 +328,7 @@ are returned unchanged.
.. class:: FromWKB(expression, **extra)
.. versionadded:: 3.1
.. versionadded:: 4.2
*Availability*: MariaDB, `MySQL
<https://dev.mysql.com/doc/refman/en/gis-wkb-functions.html#function_st-geomfromwkb>`__,
@ -341,7 +341,7 @@ Creates geometry from `Well-known binary (WKB)`_ representation.
.. class:: FromWKT(expression, **extra)
.. versionadded:: 3.1
.. versionadded:: 4.2
*Availability*: MariaDB, `MySQL
<https://dev.mysql.com/doc/refman/en/gis-wkt-functions.html#function_st-geomfromtext>`__,

View File

@ -6,7 +6,7 @@ from decimal import Decimal
from django.contrib.gis.db.models import GeometryField, PolygonField, functions
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon, fromstr
from django.contrib.gis.measure import Area
from django.db import NotSupportedError, connection, models
from django.db import NotSupportedError, connection
from django.db.models import IntegerField, Sum, Value
from django.test import TestCase, skipUnlessDBFeature
@ -330,12 +330,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
def test_fromwkb(self):
g = Point(56.811078, 60.608647)
g2 = City.objects.values_list(
functions.FromWKB(
models.Value(
bytes(g.wkb),
output_field=models.BinaryField(),
)
),
functions.FromWKB(Value(g.wkb.tobytes())),
flat=True,
)[0]
self.assertEqual(g, g2)
@ -344,7 +339,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
def test_fromwkt(self):
g = Point(56.811078, 60.608647)
g2 = City.objects.values_list(
functions.FromWKT(models.Value(g.wkt)),
functions.FromWKT(Value(g.wkt)),
flat=True,
)[0]
self.assertEqual(g, g2)