Ticket #11948: 11948-3.diff
File 11948-3.diff, 7.9 KB (added by , 12 years ago) |
---|
-
django/contrib/gis/geos/geometry.py
diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py index f411d5a..ed70f90 100644
a b class GEOSGeometry(GEOSBase, ListMixin): 577 577 "Return the envelope for this geometry (a polygon)." 578 578 return self._topology(capi.geos_envelope(self.ptr)) 579 579 580 def interpolate(self, distance): 581 if not isinstance(self, (LineString, MultiLineString)): 582 raise TypeError('interpolate only works on LineString and MultiLineString geometries') 583 return self._topology(capi.geos_interpolate(self.ptr, distance)) 584 585 def interpolate_normalized(self, distance): 586 if not isinstance(self, (LineString, MultiLineString)): 587 raise TypeError('interpolate only works on LineString and MultiLineString geometries') 588 return self._topology(capi.geos_interpolate_normalized(self.ptr, distance)) 589 580 590 def intersection(self, other): 581 591 "Returns a Geometry representing the points shared by this Geometry and other." 582 592 return self._topology(capi.geos_intersection(self.ptr, other.ptr)) … … class GEOSGeometry(GEOSBase, ListMixin): 586 596 "Computes an interior point of this Geometry." 587 597 return self._topology(capi.geos_pointonsurface(self.ptr)) 588 598 599 def project(self, point): 600 if not isinstance(point, Point): 601 raise TypeError('locate_point argument must be a Point') 602 if not isinstance(self, (LineString, MultiLineString)): 603 raise TypeError('locate_point only works on LineString and MultiLineString geometries') 604 return capi.geos_project(self.ptr, point.ptr) 605 606 def project_normalized(self, point): 607 if not isinstance(point, Point): 608 raise TypeError('locate_point argument must be a Point') 609 if not isinstance(self, (LineString, MultiLineString)): 610 raise TypeError('locate_point only works on LineString and MultiLineString geometries') 611 return capi.geos_project_normalized(self.ptr, point.ptr) 612 589 613 def relate(self, other): 590 614 "Returns the DE-9IM intersection matrix for this Geometry and the other." 591 615 return capi.geos_relate(self.ptr, other.ptr) -
django/contrib/gis/geos/prototypes/topology.py
diff --git a/django/contrib/gis/geos/prototypes/topology.py b/django/contrib/gis/geos/prototypes/topology.py index cc5734b..dfea3e9 100644
a b __all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull', 8 8 'geos_simplify', 'geos_symdifference', 'geos_union', 'geos_relate'] 9 9 10 10 from ctypes import c_double, c_int 11 from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE12 from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_ string11 from django.contrib.gis.geos.libgeos import geos_version_info, GEOM_PTR, GEOS_PREPARE 12 from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_minus_one, check_string 13 13 from django.contrib.gis.geos.prototypes.geom import geos_char_p 14 14 from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc 15 15 16 def topology(func, *args ):16 def topology(func, *args, **kwargs): 17 17 "For GEOS unary topology functions." 18 18 argtypes = [GEOM_PTR] 19 19 if args: argtypes += args 20 20 func.argtypes = argtypes 21 func.restype = GEOM_PTR22 func.errcheck = check_geom21 func.restype = kwargs.get('restype', GEOM_PTR) 22 func.errcheck = kwargs.get('errcheck', check_geom) 23 23 return func 24 24 25 25 ### Topology Routines ### … … if GEOS_PREPARE: 49 49 geos_cascaded_union.argtypes = [GEOM_PTR] 50 50 geos_cascaded_union.restype = GEOM_PTR 51 51 __all__.append('geos_cascaded_union') 52 53 # Linear referencing routines 54 info = geos_version_info() 55 if info['version'] >= '3.2.0': 56 geos_project = topology(GEOSFunc('GEOSProject'), GEOM_PTR, 57 restype=c_double, errcheck=check_minus_one) 58 geos_interpolate = topology(GEOSFunc('GEOSInterpolate'), c_double) 59 60 geos_project_normalized = topology(GEOSFunc('GEOSProjectNormalized'), 61 GEOM_PTR, restype=c_double, errcheck=check_minus_one) 62 geos_interpolate_normalized = topology(GEOSFunc('GEOSInterpolateNormalized'), c_double) 63 __all__.extend(['geos_project', 'geos_interpolate', 64 'geos_project_normalized', 'geos_interpolate_normalized']) -
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 ed38283..97f2a86 100644
a b class GEOSTest(unittest.TestCase, TestDataMixin): 1017 1017 1018 1018 print("\nEND - expecting GEOS_NOTICE; safe to ignore.\n") 1019 1019 1020 @unittest.skipUnless(geos_version_info()['version'] >= '3.2.0', "geos >= 3.2.0 is required") 1021 def test_linearref(self): 1022 "Testing linear referencing" 1023 1024 ls = fromstr('LINESTRING(0 0, 0 10, 10 10, 10 0)') 1025 mls = fromstr('MULTILINESTRING((0 0, 0 10), (10 0, 10 10))') 1026 1027 self.assertEqual(ls.project(Point(0, 20)), 10.0) 1028 self.assertEqual(ls.project(Point(7, 6)), 24) 1029 self.assertEqual(ls.project_normalized(Point(0, 20)), 1.0/3) 1030 1031 self.assertEqual(ls.interpolate(10), Point(0, 10)) 1032 self.assertEqual(ls.interpolate(24), Point(10, 6)) 1033 self.assertEqual(ls.interpolate_normalized(1.0/3), Point(0, 10)) 1034 1035 self.assertEqual(mls.project(Point(0, 20)), 10) 1036 self.assertEqual(mls.project(Point(7, 6)), 16) 1037 1038 self.assertEqual(mls.interpolate(9), Point(0, 9)) 1039 self.assertEqual(mls.interpolate(17), Point(10, 7)) 1040 1020 1041 def test_geos_version(self): 1021 1042 "Testing the GEOS version regular expression." 1022 1043 from django.contrib.gis.geos.libgeos import version_regex -
docs/ref/contrib/gis/geos.txt
diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt index 1b32265..0487472 100644
a b quarter circle (defaults is 8). 402 402 Returns a :class:`GEOSGeometry` representing the points making up this 403 403 geometry that do not make up other. 404 404 405 .. method:: GEOSGeometry.interpolate(distance) 406 .. method:: GEOSGeometry.interpolate_normalized(distance) 407 408 .. versionadded:: 1.5 409 410 Given a distance (float), returns the point (or closest point) within the 411 geometry (:class:`LineString` or :class:`MultiLineString`) at that distance. 412 The normalized version takes the distance as a float between 0 (origin) and 1 413 (endpoint). 414 415 Reverse of :meth:`GEOSGeometry.project`. 416 405 417 .. method:: GEOSGeometry:intersection(other) 406 418 407 419 Returns a :class:`GEOSGeometry` representing the points shared by this 408 420 geometry and other. 409 421 422 .. method:: GEOSGeometry.project(point) 423 .. method:: GEOSGeometry.project_normalized(point) 424 425 .. versionadded:: 1.5 426 427 Returns the distance (float) from the origin of the geometry 428 (:class:`LineString` or :class:`MultiLineString`) to the point projected on the 429 geometry (that is to a point of the line the closest to the given point). 430 The normalized version returns the distance as a float between 0 (origin) and 1 431 (endpoint). 432 433 Reverse of :meth:`GEOSGeometry.interpolate`. 434 410 435 .. method:: GEOSGeometry.relate(other) 411 436 412 437 Returns the DE-9IM intersection matrix (a string) representing the -
docs/releases/1.5.txt
diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt index 3e274b5..b4618e7 100644
a b Django 1.5 also includes several smaller improvements worth noting: 102 102 * In the localflavor for Canada, "pq" was added to the acceptable codes for 103 103 Quebec. It's an old abbreviation. 104 104 105 * :class:`~django.contrib.gis.geos.LineString` and 106 :class:`~django.contrib.gis.geos.MultiLineString` GEOS objects now support the 107 :meth:`~django.contrib.gis.geos.GEOSGeometry.interpolate()` and 108 :meth:`~django.contrib.gis.geos.GEOSGeometry.project()` methods 109 (so-called linear referencing). 110 105 111 Backwards incompatible changes in 1.5 106 112 ===================================== 107 113