예제 #1
0
 def test_issue157(self):
     """Verify that we get the error class name back - issue #157
        .. seealso:: https://github.com/AIFDR/inasafe/issues/121
     """
     try:
         bbox_intersection('aoeu', 'oaeu', [])
     except Exception, e:
         myMessage = getExceptionWithStacktrace(e, html=False)
         assert 'VerificationError : Western' in myMessage, myMessage
예제 #2
0
    def test_stacktrace_html(self):
        """Stack traces can be caught and rendered as html
        """

        try:
            bbox_intersection('aoeu', 'oaeu', [])
        except Exception, e:
            # Display message and traceback

            myMessage = getExceptionWithStacktrace(e, html=False)
            #print myMessage
            assert str(e) in myMessage
            assert 'line' in myMessage
            assert 'File' in myMessage

            myMessage = getExceptionWithStacktrace(e, html=True)
            assert str(e) in myMessage
            assert '<pre id="traceback"' in myMessage
            assert 'line' in myMessage
            assert 'File' in myMessage
예제 #3
0
                'be a sequence of the '
               'form [west, south, east, north]' % (str(x),
                                                    str(type(x))[1:-1]))
        try:
            list(x)
        except:
            raise InvalidBoundingBoxException(myMessage)
        try:
            verify(len(x) == 4, myMessage)
        except VerificationError, e:
            raise InvalidBoundingBoxException(str(e))

    # .. note:: The bbox_intersection function below assumes that
    #           all inputs are in EPSG:4326
    myOptimalExtent = bbox_intersection(theHazardGeoExtent,
                                        theExposureGeoExtent,
                                        theViewportGeoExtent)
    if myOptimalExtent is None:
        # Bounding boxes did not overlap
        myMessage = tr('Bounding boxes of hazard data, exposure data '
               'and viewport did not overlap, so no computation was '
               'done. Please make sure you pan to where the data is and '
               'that hazard and exposure data overlaps.')
        raise InsufficientOverlapException(myMessage)

    return myOptimalExtent


def getBufferedExtent(theGeoExtent, theCellSize):
    """Grow bounding box with one unit of resolution in each direction.
예제 #4
0
def getOptimalExtent(theHazardGeoExtent,
                     theExposureGeoExtent,
                     theViewportGeoExtent):
    """ A helper function to determine what the optimal extent is.
    Optimal extent should be considered as the intersection between
    the three inputs. The inasafe library will perform various checks
    to ensure that the extent is tenable, includes data from both
    etc.

    This is just a thin wrapper around safe_api.bbox_intersection.

    Typically the result of this function will be used to clip
    input layers to a commone extent before processing.

    Args:

        * theHazardGeoExtent - an array representing the hazard layer
           extents in the form [xmin, ymin, xmax, ymax]. It is assumed
           that the coordinates are in EPSG:4326 although currently
           no checks are made to enforce this.
        * theExposureGeoExtent - an array representing the exposure layer
           extents in the form [xmin, ymin, xmax, ymax]. It is assumed
           that the coordinates are in EPSG:4326 although currently
           no checks are made to enforce this.
        * theViewPortGeoExtent - an array representing the viewport
           extents in the form [xmin, ymin, xmax, ymax]. It is assumed
           that the coordinates are in EPSG:4326 although currently
           no checks are made to enforce this.

       ..note:: We do minimal checking as the inasafe library takes
         care of it for us.

    Returns:
       An array containing an extent in the form [xmin, ymin, xmax, ymax]
       e.g.::

          [100.03, -1.14, 100.81, -0.73]

    Raises:
        Any exceptions raised by the InaSAFE library will be propogated.
    """

    # Check that inputs are valid
    for x in [theHazardGeoExtent,
              theExposureGeoExtent,
              theViewportGeoExtent]:

        # Err message
        myMessage = tr('Invalid bounding box %s (%s). It must '
                'be a sequence of the '
               'form [west, south, east, north]' % (str(x),
                                                    str(type(x))[1:-1]))
        try:
            list(x)
        except:
            raise Exception(myMessage)
        verify(len(x) == 4, myMessage)

    # .. note:: The bbox_intersection function below assumes that
    #           all inputs are in EPSG:4326
    myOptimalExtent = bbox_intersection(theHazardGeoExtent,
                                        theExposureGeoExtent,
                                        theViewportGeoExtent)
    if myOptimalExtent is None:
        # Bounding boxes did not overlap
        myMessage = tr('Bounding boxes of hazard data, exposure data '
               'and viewport did not overlap, so no computation was '
               'done. Please make sure you pan to where the data is and '
               'that hazard and exposure data overlaps.')
        raise Exception(myMessage)

    return myOptimalExtent