Added `merged` property to LineString & MultiLineString, which returns the output of the GEOS line merging operation. trunk
authorJustin Bronn <jbronn@geodjango.org>
Thu Mar 19 13:08:50 2009 -0500 (17 months ago)
branchtrunk
changeset 36287b34dce202d
parent 361 be2975906c89
child 363 a28d7990db62
Added `merged` property to LineString & MultiLineString, which returns the output of the GEOS line merging operation.
django/contrib/gis/geos/collections.py
django/contrib/gis/geos/linestring.py
django/contrib/gis/geos/prototypes/topology.py
django/contrib/gis/geos/tests/test_geos.py
     1.1 --- a/django/contrib/gis/geos/collections.py	Thu Mar 19 12:33:18 2009 -0500
     1.2 +++ b/django/contrib/gis/geos/collections.py	Thu Mar 19 13:08:50 2009 -0500
     1.3 @@ -103,6 +103,14 @@
     1.4      _allowed = (LineString, LinearRing)
     1.5      _typeid = 5
     1.6  
     1.7 +    @property
     1.8 +    def merged(self):
     1.9 +        """ 
    1.10 +        Returns a LineString representing the line merge of this 
    1.11 +        MultiLineString.
    1.12 +        """ 
    1.13 +        return self._topology(capi.geos_linemerge(self.ptr))         
    1.14 +
    1.15  class MultiPolygon(GeometryCollection):
    1.16      _allowed = Polygon
    1.17      _typeid = 6
     2.1 --- a/django/contrib/gis/geos/linestring.py	Thu Mar 19 12:33:18 2009 -0500
     2.2 +++ b/django/contrib/gis/geos/linestring.py	Thu Mar 19 13:08:50 2009 -0500
     2.3 @@ -126,6 +126,11 @@
     2.4          return self._listarr(self._cs.__getitem__)
     2.5  
     2.6      @property
     2.7 +    def merged(self):
     2.8 +        "Returns the line merge of this LineString."
     2.9 +        return self._topology(capi.geos_linemerge(self.ptr))   
    2.10 +
    2.11 +    @property
    2.12      def x(self):
    2.13          "Returns a list or numpy array of the X variable."
    2.14          return self._listarr(self._cs.getX)
     3.1 --- a/django/contrib/gis/geos/prototypes/topology.py	Thu Mar 19 12:33:18 2009 -0500
     3.2 +++ b/django/contrib/gis/geos/prototypes/topology.py	Thu Mar 19 13:08:50 2009 -0500
     3.3 @@ -3,9 +3,9 @@
     3.4   topological operations on geometries.
     3.5  """
     3.6  __all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull',
     3.7 -           'geos_difference', 'geos_envelope', 'geos_intersection',
     3.8 -           'geos_pointonsurface', 'geos_preservesimplify', 'geos_simplify',
     3.9 -           'geos_symdifference', 'geos_union', 'geos_relate']
    3.10 +           'geos_difference', 'geos_envelope', 'geos_intersection', 
    3.11 +           'geos_linemerge', 'geos_pointonsurface', 'geos_preservesimplify',
    3.12 +           'geos_simplify', 'geos_symdifference', 'geos_union', 'geos_relate']
    3.13  
    3.14  from ctypes import c_char_p, c_double, c_int
    3.15  from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE
    3.16 @@ -28,6 +28,7 @@
    3.17  geos_difference = topology(lgeos.GEOSDifference, GEOM_PTR)
    3.18  geos_envelope = topology(lgeos.GEOSEnvelope)
    3.19  geos_intersection = topology(lgeos.GEOSIntersection, GEOM_PTR)
    3.20 +geos_linemerge = topology(lgeos.GEOSLineMerge)
    3.21  geos_pointonsurface = topology(lgeos.GEOSPointOnSurface)
    3.22  geos_preservesimplify = topology(lgeos.GEOSTopologyPreserveSimplify, c_double)
    3.23  geos_simplify = topology(lgeos.GEOSSimplify, c_double)
     4.1 --- a/django/contrib/gis/geos/tests/test_geos.py	Thu Mar 19 12:33:18 2009 -0500
     4.2 +++ b/django/contrib/gis/geos/tests/test_geos.py	Thu Mar 19 13:08:50 2009 -0500
     4.3 @@ -824,6 +824,17 @@
     4.4              self.assertEqual(mpoly.intersects(pnt), prep.intersects(pnt))
     4.5              self.assertEqual(c, prep.covers(pnt))
     4.6  
     4.7 +    def test26_line_merge(self): 
     4.8 +        "Testing line merge support"
     4.9 +        ref_geoms = (fromstr('LINESTRING(1 1, 1 1, 3 3)'),
    4.10 +                     fromstr('MULTILINESTRING((1 1, 3 3), (3 3, 4 2))'),
    4.11 +                     )
    4.12 +        ref_merged = (fromstr('LINESTRING(1 1, 3 3)'),
    4.13 +                      fromstr('LINESTRING (1 1, 3 3, 4 2)'),
    4.14 +                      )
    4.15 +        for geom, merged in zip(ref_geoms, ref_merged):
    4.16 +            self.assertEqual(merged, geom.merged)
    4.17 +
    4.18  def suite():
    4.19      s = unittest.TestSuite()
    4.20      s.addTest(unittest.makeSuite(GEOSTest))