Ticket #11948: 08_contrib-gis-linearref.patch
File 08_contrib-gis-linearref.patch, 5.7 KB (added by , 13 years ago) |
---|
-
django/contrib/gis/geos/geometry.py
diff -Nru ./django/contrib/gis/geos/geometry.py /tmp/t/Django-1.3//django/contrib/gis/geos/geometry.py
a b 667 667 "Clones this Geometry." 668 668 return GEOSGeometry(capi.geom_clone(self.ptr), srid=self.srid) 669 669 670 def project(self, point): 671 if not isinstance(point, Point): 672 raise TypeError('locate_point argument must be a Point') 673 if not isinstance(self, (LineString, MultiLineString)): 674 raise TypeError('locate_point only works on LineString and MultiLineString geometries') 675 return capi.geos_project(self.ptr, point.ptr) 676 677 678 def interpolate(self, distance): 679 if not isinstance(self, (LineString, MultiLineString)): 680 raise TypeError('interpolate only works on LineString and MultiLineString geometries') 681 return self._topology(capi.geos_interpolate(self.ptr, distance)) 682 683 def project_normalized(self, point): 684 if not isinstance(point, Point): 685 raise TypeError('locate_point argument must be a Point') 686 if not isinstance(self, (LineString, MultiLineString)): 687 raise TypeError('locate_point only works on LineString and MultiLineString geometries') 688 return capi.geos_project_normalized(self.ptr, point.ptr) 689 690 691 def interpolate_normalized(self, distance): 692 if not isinstance(self, (LineString, MultiLineString)): 693 raise TypeError('interpolate only works on LineString and MultiLineString geometries') 694 return self._topology(capi.geos_interpolate_normalized(self.ptr, distance)) 695 696 670 697 # Class mapping dictionary. Has to be at the end to avoid import 671 698 # conflicts with GEOSGeometry. 672 699 from django.contrib.gis.geos.linestring import LineString, LinearRing -
django/contrib/gis/geos/prototypes/geom.py
diff -Nru ./django/contrib/gis/geos/prototypes/geom.py /tmp/t/Django-1.3//django/contrib/gis/geos/prototypes/geom.py
a b 1 from ctypes import c_char_p, c_int, c_ size_t, c_ubyte, c_uint, POINTER2 from django.contrib.gis.geos.libgeos import CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE1 from ctypes import c_char_p, c_int, c_double, c_size_t, c_ubyte, c_uint, POINTER 2 from django.contrib.gis.geos.libgeos import geos_version_info, CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE 3 3 from django.contrib.gis.geos.prototypes.errcheck import \ 4 4 check_geom, check_minus_one, check_sized_string, check_string, check_zero 5 5 from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc … … 117 117 geos_set_srid = GEOSFunc('GEOSSetSRID') 118 118 geos_set_srid.argtypes = [GEOM_PTR, c_int] 119 119 geos_set_srid.restype = None 120 121 # Linear referencing routines 122 123 info = geos_version_info() 124 if info['version'] >= '3.2.0': 125 geos_project = GEOSFunc('GEOSProject') 126 geos_project.argtypes = [GEOM_PTR, GEOM_PTR] 127 geos_project.restype = c_double 128 geos_interpolate = geom_output(GEOSFunc('GEOSInterpolate'), [GEOM_PTR, c_double]) 129 130 geos_project_normalized = GEOSFunc('GEOSProjectNormalized') 131 geos_project_normalized.argtypes = [GEOM_PTR, GEOM_PTR] 132 geos_project_normalized.restype = c_double 133 geos_interpolate_normalized = geom_output(GEOSFunc('GEOSInterpolateNormalized'), [GEOM_PTR, c_double]) -
django/contrib/gis/geos/prototypes/__init__.py
diff -Nru ./django/contrib/gis/geos/prototypes/__init__.py /tmp/t/Django-1.3//django/contrib/gis/geos/prototypes/__init__.py
a b 13 13 from django.contrib.gis.geos.prototypes.geom import from_hex, from_wkb, from_wkt, \ 14 14 create_point, create_linestring, create_linearring, create_polygon, create_collection, \ 15 15 destroy_geom, get_extring, get_intring, get_nrings, get_geomn, geom_clone, \ 16 geos_normalize, geos_ type, geos_typeid, geos_get_srid, geos_set_srid, \17 ge t_dims, get_num_coords, get_num_geoms, \18 to_hex, to_wkb, to_wkt16 geos_normalize, geos_interpolate, geos_interpolate_normalized, geos_project, \ 17 geos_project_normalized, geos_type, geos_typeid, geos_get_srid, geos_set_srid, \ 18 get_dims, get_num_coords, get_num_geoms, to_hex, to_wkb, to_wkt 19 19 20 20 # Miscellaneous routines. 21 21 from django.contrib.gis.geos.prototypes.misc import * -
django/contrib/gis/geos/tests/test_geos.py
diff -Nru ./django/contrib/gis/geos/tests/test_geos.py /tmp/t/Django-1.3//django/contrib/gis/geos/tests/test_geos.py
a b 1046 1046 1047 1047 print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n" 1048 1048 1049 def test28_linearref(self): 1050 "Testing linear referencing" 1051 1052 info = geos_version_info() 1053 if info['version'] < '3.2.0': 1054 return #no linear referencing yet 1055 1056 ls = fromstr('LINESTRING(0 0, 0 10, 10 10, 10 0)') 1057 mls = fromstr('MULTILINESTRING((0 0, 0 10), (10 0, 10 10))') 1058 1059 self.assertEqual(ls.project(Point(0, 20)), 10.0) 1060 self.assertEqual(ls.project(Point(7, 6)), 24) 1061 1062 self.assertEqual(ls.interpolate(10), Point(0, 10)) 1063 self.assertEqual(ls.interpolate(24), Point(10, 6)) 1064 1065 self.assertEqual(mls.project(Point(0, 20)), 10) 1066 self.assertEqual(mls.project(Point(7, 6)), 16) 1067 1068 self.assertEqual(mls.interpolate(9), Point(0, 9)) 1069 self.assertEqual(mls.interpolate(17), Point(10, 7)) 1070 1049 1071 def suite(): 1050 1072 s = unittest.TestSuite() 1051 1073 s.addTest(unittest.makeSuite(GEOSTest))