Ticket #11948: 08_contrib-gis-linearref.patch

File 08_contrib-gis-linearref.patch, 5.7 KB (added by anonymous, 13 years ago)

refresh patch for 1.3

  • 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  
    667667        "Clones this Geometry."
    668668        return GEOSGeometry(capi.geom_clone(self.ptr), srid=self.srid)
    669669
     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
    670697# Class mapping dictionary.  Has to be at the end to avoid import
    671698# conflicts with GEOSGeometry.
    672699from 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, POINTER
    2 from django.contrib.gis.geos.libgeos import CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE
     1from ctypes import c_char_p, c_int, c_double, c_size_t, c_ubyte, c_uint, POINTER
     2from django.contrib.gis.geos.libgeos import geos_version_info, CS_PTR, GEOM_PTR, PREPGEOM_PTR, GEOS_PREPARE
    33from django.contrib.gis.geos.prototypes.errcheck import \
    44    check_geom, check_minus_one, check_sized_string, check_string, check_zero
    55from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
     
    117117geos_set_srid = GEOSFunc('GEOSSetSRID')
    118118geos_set_srid.argtypes = [GEOM_PTR, c_int]
    119119geos_set_srid.restype = None
     120
     121# Linear referencing routines
     122
     123info = geos_version_info()
     124if 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  
    1313from django.contrib.gis.geos.prototypes.geom import from_hex, from_wkb, from_wkt, \
    1414    create_point, create_linestring, create_linearring, create_polygon, create_collection, \
    1515    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     get_dims, get_num_coords, get_num_geoms, \
    18     to_hex, to_wkb, to_wkt
     16    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
    1919
    2020# Miscellaneous routines.
    2121from 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  
    10461046
    10471047        print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n"
    10481048
     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
    10491071def suite():
    10501072    s = unittest.TestSuite()
    10511073    s.addTest(unittest.makeSuite(GEOSTest))
Back to Top