Ejemplo n.º 1
0
    def _test_get_independent_polygons2(self):
        # This fails. The only way to fix it is to play with geos.

        # The error occurs because a linestring (a degenerate poly)
        # is used somewhere.
        # It should work if union works ;)
        from eqrm_code.generation_polygon import polygons_from_xml
        polygons,mag_type = polygons_from_xml(join('..','test_resources',
                                                   'sample_event.xml'))
        independent_polygons=get_independent_polygons_obsolete(polygons)

        super_poly = independent_polygons[0]
        area = 0
        for poly in independent_polygons:
            area+=poly.area
            super_poly = super_poly.union(poly)
        assert allclose(super_poly.area,area)
Ejemplo n.º 2
0
    def _test_get_independent_polygons(self):
        from eqrm_code.generation_polygon import polygons_from_xml
        eqrm_dir = determine_eqrm_path()
        #print "eqrm_dir", eqrm_dir
        file_location = join(eqrm_dir, 'test_resources','sample_event.xml')
        #print "file_location", file_location
        polygons,mag_type = polygons_from_xml(file_location,
                      azi=[180,180],
                      dazi=[10,10],
                      fault_dip=[30,30],
                      fault_width=15,
                      override_xml=True)
        independent_polygons=get_independent_polygons_obsolete(polygons)
        assert len(independent_polygons)==3
        
        #conformance tests, could change if I change the way area works
        assert allclose(independent_polygons[0].area,80.685560816)
        assert allclose(independent_polygons[1].area,16.314439184)
        assert allclose(independent_polygons[2].area, 27.919220365)

        #no more conformance tests (these are real ones):
        for i in range(len(independent_polygons)):
            for j in range(len(independent_polygons)):
                if not i == j:
                    polygoni = independent_polygons[i]
                    polygonj = independent_polygons[j]
                    int = polygoni.intersection(polygonj)
                    assert int.area == 0

        area1=0
        area2=0

        for poly in polygons:
            area1+=poly.area
        for poly in independent_polygons:
            area2+=poly.area
        assert not allclose(area1,area2)
        assert allclose(area2,area1-polygons[0].intersection(polygons[1]).area)