diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
index df396bd..7ae5788 100644
a
|
b
|
class GEOSGeometry(GEOSBase, ListMixin):
|
382 | 382 | @property |
383 | 383 | def wkt(self): |
384 | 384 | "Returns the WKT (Well-Known Text) representation of this Geometry." |
385 | | return wkt_w().write(self).decode() |
| 385 | return wkt_w(self.hasz and 3 or 2).write(self).decode() |
386 | 386 | |
387 | 387 | @property |
388 | 388 | def hex(self): |
diff --git a/django/contrib/gis/geos/prototypes/io.py b/django/contrib/gis/geos/prototypes/io.py
index 1be7da8..1e80351 100644
a
|
b
|
wkt_writer_write.argtypes = [WKT_WRITE_PTR, GEOM_PTR]
|
45 | 45 | wkt_writer_write.restype = geos_char_p |
46 | 46 | wkt_writer_write.errcheck = check_string |
47 | 47 | |
| 48 | try: |
| 49 | wkt_writer_get_outdim = GEOSFunc('GEOSWKTWriter_getOutputDimension') |
| 50 | wkt_writer_get_outdim.argtypes = [WKT_WRITE_PTR] |
| 51 | wkt_writer_get_outdim.restype = c_int |
| 52 | wkt_writer_set_outdim = GEOSFunc('GEOSWKTWriter_setOutputDimension') |
| 53 | wkt_writer_set_outdim.argtypes = [WKT_WRITE_PTR, c_int] |
| 54 | except AttributeError: |
| 55 | # GEOSWKTWriter_get/setOutputDimension has been introduced in GEOS 3.3.0 |
| 56 | # Always return 2 if not available |
| 57 | wkt_writer_get_outdim = lambda ptr: 2 |
| 58 | wkt_writer_set_outdim = lambda ptr, dim: None |
| 59 | |
48 | 60 | ### WKBReader routines ### |
49 | 61 | wkb_reader_create = GEOSFunc('GEOSWKBReader_create') |
50 | 62 | wkb_reader_create.restype = WKB_READ_PTR |
… |
… |
class WKTWriter(IOBase):
|
151 | 163 | "Returns the WKT representation of the given geometry." |
152 | 164 | return wkt_writer_write(self.ptr, geom.ptr) |
153 | 165 | |
| 166 | @property |
| 167 | def outdim(self): |
| 168 | return wkt_writer_get_outdim(self.ptr) |
| 169 | |
| 170 | @outdim.setter |
| 171 | def outdim(self, new_dim): |
| 172 | if not new_dim in (2, 3): |
| 173 | raise ValueError('WKT output dimension must be 2 or 3') |
| 174 | wkt_writer_set_outdim(self.ptr, new_dim) |
| 175 | |
| 176 | |
154 | 177 | class WKBWriter(IOBase): |
155 | 178 | _constructor = wkb_writer_create |
156 | 179 | _destructor = wkb_writer_destroy |
… |
… |
def wkt_r():
|
217 | 240 | thread_context.wkt_r = _WKTReader() |
218 | 241 | return thread_context.wkt_r |
219 | 242 | |
220 | | def wkt_w(): |
| 243 | def wkt_w(dim=2): |
221 | 244 | if not thread_context.wkt_w: |
222 | 245 | thread_context.wkt_w = WKTWriter() |
| 246 | thread_context.wkt_w.outdim = dim |
223 | 247 | return thread_context.wkt_w |
224 | 248 | |
225 | 249 | def wkb_r(): |
diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
index cbe5136..e18f809 100644
a
|
b
|
class GEOSTest(unittest.TestCase, TestDataMixin):
|
80 | 80 | "Testing WKT output." |
81 | 81 | for g in self.geometries.wkt_out: |
82 | 82 | geom = fromstr(g.wkt) |
83 | | self.assertEqual(g.ewkt, geom.wkt) |
| 83 | if geom.hasz and geos_version_info()['version'] >= '3.3.0': |
| 84 | self.assertEqual(g.ewkt, geom.wkt) |
84 | 85 | |
85 | 86 | def test_hex(self): |
86 | 87 | "Testing HEX output." |