Ticket #14318: geos_validreason.1.diff
File geos_validreason.1.diff, 4.3 KB (added by , 14 years ago) |
---|
-
django/contrib/gis/geos/geometry.py
275 275 "This property tests the validity of this Geometry." 276 276 return capi.geos_isvalid(self.ptr) 277 277 278 @property 279 def valid_reason(self): 280 """ 281 Returns a string containing the reason for any invalidity. 282 """ 283 if not GEOS_PREPARE: 284 raise GEOSException('Upgrade GEOS to 3.1 to get validity reason.') 285 return capi.geos_isvalidreason(self.ptr) 286 278 287 #### Binary predicates. #### 279 288 def contains(self, other): 280 289 "Returns true if other.within(this) returns true." -
django/contrib/gis/geos/prototypes/misc.py
4 4 """ 5 5 from ctypes import c_int, c_double, POINTER 6 6 from django.contrib.gis.geos.libgeos import GEOM_PTR 7 from django.contrib.gis.geos.prototypes.errcheck import check_dbl 7 from django.contrib.gis.geos.prototypes.errcheck import check_dbl, check_string 8 from django.contrib.gis.geos.prototypes.geom import geos_char_p 8 9 from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc 9 10 10 11 ### ctypes generator function ### … … 26 27 geos_area = dbl_from_geom(GEOSFunc('GEOSArea')) 27 28 geos_distance = dbl_from_geom(GEOSFunc('GEOSDistance'), num_geom=2) 28 29 geos_length = dbl_from_geom(GEOSFunc('GEOSLength')) 30 31 # Validity reason 32 geos_isvalidreason = GEOSFunc('GEOSisValidReason') 33 geos_isvalidreason.argtypes = [GEOM_PTR] 34 geos_isvalidreason.restype = geos_char_p 35 geos_isvalidreason.errcheck = check_string -
django/contrib/gis/geos/prototypes/__init__.py
18 18 to_hex, to_wkb, to_wkt 19 19 20 20 # Miscellaneous routines. 21 from django.contrib.gis.geos.prototypes.misc import geos_area, geos_distance, geos_length 21 from django.contrib.gis.geos.prototypes.misc import geos_area, geos_distance, geos_length, geos_isvalidreason 22 22 23 23 # Predicates 24 24 from django.contrib.gis.geos.prototypes.predicates import geos_hasz, geos_isempty, \ -
django/contrib/gis/geos/tests/test_geos.py
2 2 from django.contrib.gis.geos import * 3 3 from django.contrib.gis.geos.base import gdal, numpy, GEOSBase 4 4 from django.contrib.gis.tests.geometries import * 5 from django.contrib.gis.geos.libgeos import GEOS_PREPARE 5 6 6 7 class GEOSTest(unittest.TestCase): 7 8 … … 919 920 for geom, merged in zip(ref_geoms, ref_merged): 920 921 self.assertEqual(merged, geom.merged) 921 922 923 def test27_valid_reason(self): 924 "Testing IsValidReason support" 925 if not GEOS_PREPARE: 926 print >>sys.stderr, "Skipping tests (GEOS < v3.1)" 927 return 928 929 g = GEOSGeometry("POINT(0 0)") 930 self.assert_(g.valid) 931 self.assert_(isinstance(g.valid_reason, basestring)) 932 self.assertEqual(g.valid_reason, "Valid Geometry") 933 934 g = GEOSGeometry("LINESTRING(0 0, 0 0)") 935 self.assert_(not g.valid) 936 self.assert_(isinstance(g.valid_reason, basestring)) 937 self.assertEqual(g.valid_reason, "Too few points in geometry component[0 0]") 938 922 939 def suite(): 923 940 s = unittest.TestSuite() 924 941 s.addTest(unittest.makeSuite(GEOSTest)) -
docs/ref/contrib/gis/geos.txt
219 219 220 220 Returns a boolean indicating whether the geometry is valid. 221 221 222 .. attribute:: GEOSGeometry.valid_reason 223 224 .. versionadded:: 1.3 225 226 Returns a string describing the reason why a geometry is invalid. 227 222 228 .. attribute:: GEOSGeometry.srid 223 229 224 230 Property that may be used to retrieve or set the SRID associated with the