Ticket #16594: 16594-2.diff

File 16594-2.diff, 7.5 KB (added by Claude Paroz, 12 years ago)

Updated now that geometries.json.gz test data is geometries.json

  • django/contrib/gis/geos/geometry.py

    commit 16002c9f10593b4d2e0f647bdfcfa67ff017b01b
    Author: Claude Paroz <claude@2xlibre.net>
    Date:   Fri Sep 21 20:22:54 2012 +0200
    
        Added wkt 3D support for GEOS geometries
        
        This requires GEOS >= 3.3.0 to function properly. On previous
        versions, the Z dimension will simply not appear in the wkt.
    
    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):  
    382382    @property
    383383    def wkt(self):
    384384        "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()
    386386
    387387    @property
    388388    def hex(self):
  • django/contrib/gis/geos/prototypes/io.py

    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]  
    4545wkt_writer_write.restype = geos_char_p
    4646wkt_writer_write.errcheck = check_string
    4747
     48try:
     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]
     54except 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
    4860### WKBReader routines ###
    4961wkb_reader_create = GEOSFunc('GEOSWKBReader_create')
    5062wkb_reader_create.restype = WKB_READ_PTR
    class WKTWriter(IOBase):  
    151163        "Returns the WKT representation of the given geometry."
    152164        return wkt_writer_write(self.ptr, geom.ptr)
    153165
     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
    154177class WKBWriter(IOBase):
    155178    _constructor = wkb_writer_create
    156179    _destructor = wkb_writer_destroy
    def wkt_r():  
    217240        thread_context.wkt_r = _WKTReader()
    218241    return thread_context.wkt_r
    219242
    220 def wkt_w():
     243def wkt_w(dim=2):
    221244    if not thread_context.wkt_w:
    222245        thread_context.wkt_w = WKTWriter()
     246    thread_context.wkt_w.outdim = dim
    223247    return thread_context.wkt_w
    224248
    225249def wkb_r():
  • django/contrib/gis/geos/tests/test_geos.py

    diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
    index 283daa4..5ae980d 100644
    a b class GEOSTest(unittest.TestCase, TestDataMixin):  
    8080        "Testing WKT output."
    8181        for g in self.geometries.wkt_out:
    8282            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)
    8485
    8586    def test_hex(self):
    8687        "Testing HEX output."
  • django/contrib/gis/tests/data/geometries.json

    diff --git a/django/contrib/gis/tests/data/geometries.json b/django/contrib/gis/tests/data/geometries.json
    index 46de4d6..fbca427 100644
    a b  
    2020  ],
    2121  "wkt_out": [
    2222    {"wkt": "POINT (110 130)", "ewkt": "POINT (110.0000000000000000 130.0000000000000000)", "kml": "<Point><coordinates>110.0,130.0,0</coordinates></Point>", "gml": "<gml:Point><gml:coordinates>110,130</gml:coordinates></gml:Point>"},
     23    {"wkt": "POINT (110 130 85)", "ewkt": "POINT (110.0000000000000000 130.0000000000000000 85.0000000000000000)", "kml": "<Point><coordinates>110.0,130.0,85.0</coordinates></Point>", "gml": "<gml:Point><gml:coordinates>110,130,85</gml:coordinates></gml:Point>"},
    2324    {"wkt": "LINESTRING (40 40,50 130,130 130)", "ewkt": "LINESTRING (40.0000000000000000 40.0000000000000000, 50.0000000000000000 130.0000000000000000, 130.0000000000000000 130.0000000000000000)", "kml": "<LineString><coordinates>40.0,40.0,0 50.0,130.0,0 130.0,130.0,0</coordinates></LineString>", "gml": "<gml:LineString><gml:coordinates>40,40 50,130 130,130</gml:coordinates></gml:LineString>"},
    2425    {"wkt": "POLYGON ((150 150,410 150,280 20,20 20,150 150),(170 120,330 120,260 50,100 50,170 120))", "ewkt": "POLYGON ((150.0000000000000000 150.0000000000000000, 410.0000000000000000 150.0000000000000000, 280.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 150.0000000000000000 150.0000000000000000), (170.0000000000000000 120.0000000000000000, 330.0000000000000000 120.0000000000000000, 260.0000000000000000 50.0000000000000000, 100.0000000000000000 50.0000000000000000, 170.0000000000000000 120.0000000000000000))", "kml": "<Polygon><outerBoundaryIs><LinearRing><coordinates>150.0,150.0,0 410.0,150.0,0 280.0,20.0,0 20.0,20.0,0 150.0,150.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>170.0,120.0,0 330.0,120.0,0 260.0,50.0,0 100.0,50.0,0 170.0,120.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon>", "gml": "<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>150,150 410,150 280,20 20,20 150,150</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>170,120 330,120 260,50 100,50 170,120</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>"},
    2526    {"wkt": "MULTIPOINT (10 80,110 170,110 120)", "ewkt": "MULTIPOINT (10.0000000000000000 80.0000000000000000, 110.0000000000000000 170.0000000000000000, 110.0000000000000000 120.0000000000000000)", "kml": "<MultiGeometry><Point><coordinates>10.0,80.0,0</coordinates></Point><Point><coordinates>110.0,170.0,0</coordinates></Point><Point><coordinates>110.0,120.0,0</coordinates></Point></MultiGeometry>", "gml": "<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates>10,80</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>110,170</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>110,120</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>"},
     
    2930  ],
    3031  "hex_wkt": [
    3132    {"wkt": "POINT(0 1)", "hex": "01010000000000000000000000000000000000F03F"},
     33    {"wkt": "POINT(0 1 5)", "hex": "01010000800000000000000000000000000000F03F0000000000001440"},
    3234    {"wkt": "LINESTRING(0 1, 2 3, 4 5)", "hex": "0102000000030000000000000000000000000000000000F03F0000000000000040000000000000084000000000000010400000000000001440"},
    3335    {"wkt": "POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", "hex": "010300000001000000050000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000000000000000000000"},
    3436    {"wkt": "MULTIPOINT(0 0, 10 0, 10 10, 0 10, 0 0)", "hex": "010400000005000000010100000000000000000000000000000000000000010100000000000000000024400000000000000000010100000000000000000024400000000000002440010100000000000000000000000000000000002440010100000000000000000000000000000000000000"},
     
    118120      {"wkt": "POLYGON ((-5 0,-5 10,5 10,5 5,10 5,10 -5,0 -5,0 0,-5 0))"},
    119121      {"wkt": "POLYGON ((2 0, 2 15, 18 15, 18 0, 2 0))"}
    120122  ]
    121 }
    122  No newline at end of file
     123}
Back to Top