Changeset 6314
- Timestamp:
- 09/15/07 13:56:35 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (4 diffs)
- django/branches/gis/django/contrib/gis/geos/libgeos.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/geometries.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/test_geos.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/geos/base.py
r6024 r6314 7 7 byref, string_at, create_string_buffer, pointer, \ 8 8 c_char_p, c_double, c_int, c_size_t 9 from types import StringType, UnicodeType, IntType, FloatType 9 from types import StringType, UnicodeType, IntType, FloatType, BufferType 10 10 11 11 # Python and GEOS-related dependencies. … … 31 31 def __init__(self, geo_input, srid=None): 32 32 """ 33 The base constructor for GEOS geometry objects, and may take the following 34 string inputs: WKT and HEXEWKB (a PostGIS-specific canonical form). 35 33 The base constructor for GEOS geometry objects, and may take the 34 following inputs: 35 36 * string: WKT 37 * string: HEXEWKB (a PostGIS-specific canonical form) 38 * buffer: WKB 39 36 40 The `srid` keyword is used to specify the Source Reference Identifier 37 41 (SRID) number for this Geometry. If not set, the SRID will be None. … … 56 60 # GEOSPointer object. 57 61 g = geo_input 62 elif isinstance(geo_input, BufferType): 63 # When the input is a buffer (WKB). 64 wkb_input = str(geo_input) 65 sz = c_size_t(len(wkb_input)) 66 g = lgeos.GEOSGeomFromWKB_buf(c_char_p(wkb_input), sz) 58 67 else: 59 68 # Invalid geometry type. … … 413 422 h = lgeos.GEOSGeomToHEX_buf(self._ptr(), byref(sz)) 414 423 return string_at(h, sz.value) 424 425 @property 426 def wkb(self): 427 "Returns the WKB of the Geometry as a buffer." 428 sz = c_size_t() 429 h = lgeos.GEOSGeomToWKB_buf(self._ptr(), byref(sz)) 430 return buffer(string_at(h, sz.value)) 415 431 416 432 @property django/branches/gis/django/contrib/gis/geos/libgeos.py
r6024 r6314 53 53 # "typedef void (*GEOSMessageHandler)(const char *fmt, ...);" 54 54 NOTICEFUNC = CFUNCTYPE(None, c_char_p, c_char_p) 55 def notice_h(fmt, list, output_h=sys.stdout): 56 output_h.write('GEOS_NOTICE: %s\n' % (fmt % list)) 55 def notice_h(fmt, lst, output_h=sys.stdout): 56 try: 57 warn_msg = fmt % lst 58 except: 59 warn_msg = fmt 60 output_h.write('GEOS_NOTICE: %s\n' % warn_msg) 57 61 notice_h = NOTICEFUNC(notice_h) 58 62 django/branches/gis/django/contrib/gis/tests/geometries.py
r5805 r6314 50 50 TestGeom('AAABBBDDDAAD##@#1113511111-098111111111111111533333333333333', bad=True, hex=True), 51 51 TestGeom('FFFFFFFFFFFFFFFFF1355555555555555555565111', bad=True, hex=True), 52 TestGeom('', bad=True, hex=False), 52 53 ) 53 54 django/branches/gis/django/contrib/gis/tests/test_geos.py
r6024 r6314 32 32 def test01d_errors(self): 33 33 "Testing the Error handlers." 34 # string-based 34 35 print "\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n" 35 36 for err in errors: 36 if err.hex: 37 self.assertRaises(GEOSException, fromstr, err.wkt) 38 else: 39 self.assertRaises(GEOSException, fromstr, err.wkt) 37 self.assertRaises(GEOSException, fromstr, err.wkt) 40 38 print "\nEND - expecting GEOS_ERROR; safe to ignore.\n" 39 40 class NotAGeometry(object): 41 pass 42 43 # Some other object 44 self.assertRaises(TypeError, GEOSGeometry, NotAGeometry()) 45 # None 46 self.assertRaises(TypeError, GEOSGeometry, None) 47 # Bad WKB 48 self.assertRaises(GEOSException, GEOSGeometry, buffer('0')) 41 49 50 def test01e_wkb(self): 51 "Testing WKB output." 52 from binascii import b2a_hex 53 for g in hex_wkt: 54 geom = fromstr(g.wkt) 55 wkb = geom.wkb 56 self.assertEqual(b2a_hex(wkb).upper(), g.hex) 57 58 def test01f_create_hex(self): 59 "Testing creation from HEX." 60 for g in hex_wkt: 61 geom_h = GEOSGeometry(g.hex) 62 # we need to do this so decimal places get normalised 63 geom_t = fromstr(g.wkt) 64 self.assertEqual(geom_t.wkt, geom_h.wkt) 65 66 def test01g_create_wkb(self): 67 "Testing creation from WKB." 68 from binascii import a2b_hex 69 for g in hex_wkt: 70 wkb = buffer(a2b_hex(g.hex)) 71 geom_h = GEOSGeometry(wkb) 72 # we need to do this so decimal places get normalised 73 geom_t = fromstr(g.wkt) 74 self.assertEqual(geom_t.wkt, geom_h.wkt) 75 42 76 def test02a_points(self): 43 77 "Testing Point objects."
