assert pxx.shape == pyy.shape if pxx.ndim == 0: pxx = pxx.reshape((1, )) pyy = pyy.reshape((1, )) result = numpy.array([ polygon.distance(shapely.geometry.Point(pxx.item(i), pyy.item(i))) for i in xrange(pxx.size) ]) return result.reshape(pxx.shape) try: from openquake.hazardlib.geo import _utils_speedups except ImportError: # speedups extension is not available import warnings warnings.warn("geoutils speedups are not available", RuntimeWarning) else: from openquake.hazardlib import speedups def _c_point_to_polygon_distance(polygon, pxx, pyy): pxx = numpy.array(pxx, float) pyy = numpy.array(pyy, float) cxx, cyy = numpy.array(polygon.exterior).transpose() return _utils_speedups.point_to_polygon_distance( cxx, cyy, pxx, pyy ) speedups.register(point_to_polygon_distance, _c_point_to_polygon_distance) del _c_point_to_polygon_distance
else: from openquake.hazardlib import speedups def _c_min_geodetic_distance(mlons, mlats, slons, slats): mlons, mlats, slons, slats = _prepare_coords(mlons, mlats, slons, slats) mdepths = sdepths = numpy.array(0.0) return _geodetic_speedups.min_distance(mlons, mlats, mdepths, slons, slats, sdepths, indices=False) speedups.register(min_geodetic_distance, _c_min_geodetic_distance) del _c_min_geodetic_distance def _c_min_distance(mlons, mlats, mdepths, slons, slats, sdepths, indices=False): assert not indices or mlons.ndim > 0 mlons, mlats, slons, slats = _prepare_coords(mlons, mlats, slons, slats) mdepths = numpy.array(mdepths, float) sdepths = numpy.array(sdepths, float) assert mlons.shape == mdepths.shape
except ImportError: # speedups extension is not available import warnings warnings.warn("geodetic speedups are not available", RuntimeWarning) else: from openquake.hazardlib import speedups def _c_min_geodetic_distance(mlons, mlats, slons, slats): mlons, mlats, slons, slats = _prepare_coords(mlons, mlats, slons, slats) mdepths = sdepths = numpy.array(0.0) return _geodetic_speedups.min_distance(mlons, mlats, mdepths, slons, slats, sdepths, indices=False) speedups.register(min_geodetic_distance, _c_min_geodetic_distance) del _c_min_geodetic_distance def _c_min_distance(mlons, mlats, mdepths, slons, slats, sdepths, indices=False): assert not indices or mlons.ndim > 0 mlons, mlats, slons, slats = _prepare_coords(mlons, mlats, slons, slats) mdepths = numpy.array(mdepths, float) sdepths = numpy.array(sdepths, float) assert mlons.shape == mdepths.shape assert slons.shape == sdepths.shape return _geodetic_speedups.min_distance(mlons, mlats, mdepths, slons, slats, sdepths, indices) speedups.register(min_distance, _c_min_distance)
except ImportError: # speedups extension is not available import warnings warnings.warn("geoutils speedups are not available", RuntimeWarning) else: from openquake.hazardlib import speedups def _c_point_to_polygon_distance(polygon, pxx, pyy): pxx = numpy.array(pxx, float) pyy = numpy.array(pyy, float) cxx, cyy = numpy.array(polygon.exterior).transpose() return _utils_speedups.point_to_polygon_distance( cxx, cyy, pxx, pyy ) speedups.register(point_to_polygon_distance, _c_point_to_polygon_distance) del _c_point_to_polygon_distance def cross_idl(lon1, lon2): """ Return True if two longitude values define line crossing international date line. >>> cross_idl(-45, 45) False >>> cross_idl(-180, -179) False >>> cross_idl(180, 179) False >>> cross_idl(45, -45)