pxx = numpy.array(pxx) pyy = numpy.array(pyy) 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 nhlib.geo import _utils_speedups except ImportError: # speedups extension is not available import warnings warnings.warn("geoutils speedups are not available", RuntimeWarning) else: from nhlib 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
except ImportError: # speedups extension is not available import warnings warnings.warn("geodetic speedups are not available", RuntimeWarning) else: from nhlib 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)
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 nhlib.geo import _utils_speedups except ImportError: # speedups extension is not available import warnings warnings.warn("geoutils speedups are not available", RuntimeWarning) else: from nhlib 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 nhlib 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