Ticket #10222: linemerge.patch

File linemerge.patch, 4.1 KB (added by psmith, 6 years ago)

Patch to add line_merge to geos geometries, with test case

  • django/contrib/gis/geos/base.py

     
    551551        "Returns a Geometry representing all the points in this Geometry and other."
    552552        return self._topology(geos_union(self.ptr, other.ptr))
    553553
     554    def line_merge(self):
     555        """
     556        Returns a Geometry representing the line merge of a geometry collection
     557        or multi-linestring geometry.
     558        """
     559        return self._topology(geos_linemerge(self.ptr))
     560
    554561    #### Other Routines ####
    555562    @property
    556563    def area(self):
  • django/contrib/gis/geos/prototypes/topology.py

     
    2828geos_simplify = topology(lgeos.GEOSSimplify, c_double)
    2929geos_symdifference = topology(lgeos.GEOSSymDifference, GEOM_PTR)
    3030geos_union = topology(lgeos.GEOSUnion, GEOM_PTR)
     31geos_linemerge = topology(lgeos.GEOSLineMerge)
    3132
    3233# GEOSRelate returns a string, not a geometry.
    3334geos_relate = lgeos.GEOSRelate
  • django/contrib/gis/geos/prototypes/__init__.py

     
    3030from django.contrib.gis.geos.prototypes.topology import \
    3131    geos_boundary, geos_buffer, geos_centroid, geos_convexhull, geos_difference, \
    3232    geos_envelope, geos_intersection, geos_pointonsurface, geos_preservesimplify, \
    33     geos_simplify, geos_symdifference, geos_union, geos_relate
     33    geos_simplify, geos_symdifference, geos_union, geos_relate, geos_linemerge
  • django/contrib/gis/tests/test_geos.py

     
    767767                self.assertEqual(geom, tmpg)
    768768                if not no_srid: self.assertEqual(geom.srid, tmpg.srid)
    769769
     770    def test26_line_merge(self):
     771        "Testing line merge support"
     772        pre_merge = fromstr(line_merge_geoms[0].wkt)
     773        post_merge = fromstr(line_merge_geoms[1].wkt)
     774        self.assertEqual(pre_merge.line_merge().wkt, post_merge.wkt)
     775
    770776def suite():
    771777    s = unittest.TestSuite()
    772778    s.addTest(unittest.makeSuite(GEOSTest))
  • django/contrib/gis/tests/geometries.py

     
    151151                  2.0, 8),
    152152                 )
    153153
     154line_merge_geoms = (TestGeom('MULTILINESTRING((1 1, 3 3), (3 3, 4 2))'),
     155                    TestGeom('LINESTRING (1.0000000000000000 1.0000000000000000, 3.0000000000000000 3.0000000000000000, 4.0000000000000000 2.0000000000000000)'))
     156
    154157json_geoms = (TestGeom('POINT(100 0)', json='{ "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }'),
    155158              TestGeom('POLYGON((0 0, -10 0, -10 -10, 0 -10, 0 0))', json='{ "type": "Polygon", "coordinates": [ [ [ 0.000000, 0.000000 ], [ -10.000000, 0.000000 ], [ -10.000000, -10.000000 ], [ 0.000000, -10.000000 ], [ 0.000000, 0.000000 ] ] ] }'),
    156159              TestGeom('MULTIPOLYGON(((102 2, 103 2, 103 3, 102 3, 102 2)), ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0), (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2)))', json='{ "type": "MultiPolygon", "coordinates": [ [ [ [ 102.000000, 2.000000 ], [ 103.000000, 2.000000 ], [ 103.000000, 3.000000 ], [ 102.000000, 3.000000 ], [ 102.000000, 2.000000 ] ] ], [ [ [ 100.000000, 0.000000 ], [ 101.000000, 0.000000 ], [ 101.000000, 1.000000 ], [ 100.000000, 1.000000 ], [ 100.000000, 0.000000 ] ], [ [ 100.200000, 0.200000 ], [ 100.800000, 0.200000 ], [ 100.800000, 0.800000 ], [ 100.200000, 0.800000 ], [ 100.200000, 0.200000 ] ] ] ] }'),
Back to Top