mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #26789 -- Fixed output of WKBWriter for empty points and polygons.
This commit is contained in:
committed by
Tim Graham
parent
181f492ad0
commit
b90d72facf
@@ -4,7 +4,8 @@ import binascii
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.contrib.gis.geos import (
|
||||
HAS_GEOS, GEOSGeometry, Point, WKBReader, WKBWriter, WKTReader, WKTWriter,
|
||||
HAS_GEOS, GEOSGeometry, Point, Polygon, WKBReader, WKBWriter, WKTReader,
|
||||
WKTWriter,
|
||||
)
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.six import memoryview
|
||||
@@ -155,3 +156,41 @@ class GEOSIOTest(SimpleTestCase):
|
||||
|
||||
with self.assertRaisesMessage(AttributeError, 'WKT output rounding precision must be '):
|
||||
wkt_w.precision = 'potato'
|
||||
|
||||
def test_empty_point_wkb(self):
|
||||
p = Point(srid=4326)
|
||||
wkb_w = WKBWriter()
|
||||
|
||||
wkb_w.srid = False
|
||||
with self.assertRaisesMessage(ValueError, 'Empty point is not representable in WKB.'):
|
||||
wkb_w.write(p)
|
||||
with self.assertRaisesMessage(ValueError, 'Empty point is not representable in WKB.'):
|
||||
wkb_w.write_hex(p)
|
||||
|
||||
wkb_w.srid = True
|
||||
for byteorder, hex in enumerate([
|
||||
b'0020000001000010E67FF80000000000007FF8000000000000',
|
||||
b'0101000020E6100000000000000000F87F000000000000F87F',
|
||||
]):
|
||||
wkb_w.byteorder = byteorder
|
||||
self.assertEqual(wkb_w.write_hex(p), hex)
|
||||
self.assertEqual(GEOSGeometry(wkb_w.write_hex(p)), p)
|
||||
self.assertEqual(wkb_w.write(p), memoryview(binascii.a2b_hex(hex)))
|
||||
self.assertEqual(GEOSGeometry(wkb_w.write(p)), p)
|
||||
|
||||
def test_empty_polygon_wkb(self):
|
||||
p = Polygon(srid=4326)
|
||||
p_no_srid = Polygon()
|
||||
wkb_w = WKBWriter()
|
||||
wkb_w.srid = True
|
||||
for byteorder, hexes in enumerate([
|
||||
(b'000000000300000000', b'0020000003000010E600000000'),
|
||||
(b'010300000000000000', b'0103000020E610000000000000'),
|
||||
]):
|
||||
wkb_w.byteorder = byteorder
|
||||
for srid, hex in enumerate(hexes):
|
||||
wkb_w.srid = srid
|
||||
self.assertEqual(wkb_w.write_hex(p), hex)
|
||||
self.assertEqual(GEOSGeometry(wkb_w.write_hex(p)), p if srid else p_no_srid)
|
||||
self.assertEqual(wkb_w.write(p), memoryview(binascii.a2b_hex(hex)))
|
||||
self.assertEqual(GEOSGeometry(wkb_w.write(p)), p if srid else p_no_srid)
|
||||
|
||||
Reference in New Issue
Block a user