def arrayinpolygon(a, polygon, x=None, y=None): ''' Set array element value as 1 if inside a polygon or set value as -1. :param a: (*array_like*) The array. :param polygon: (*PolygonShape*) The polygon. :param x: (*float*) X coordinate of the point. Default is ``None``, for DimArray :param y: (*float*) Y coordinate of the point. Default is ``None``, for DimArray :returns: (*array_like*) Result array. ''' if isinstance(a, DimArray): if x is None or y is None: x = self.dimvalue(1) y = self.dimvalue(0) if not x is None and not y is None: if isinstance(polygon, tuple): x_p = polygon[0] y_p = polygon[1] if isinstance(x_p, MIArray): x_p = x_p.aslist() if isinstance(y_p, MIArray): y_p = y_p.aslist() return MIArray(ArrayMath.inPolygon(a.asarray(), x.aslist(), y.aslist(), x_p, y_p)) else: if isinstance(polygon, MILayer): polygon = polygon.layer return MIArray(ArrayMath.inPolygon(a.asarray(), x.aslist(), y.aslist(), polygon)) else: return None
def inpolygon(x, y, polygon): ''' Check if x/y points are inside a polygon or not. :param x: (*array_like*) X coordinate of the points. :param y: (*array_like*) Y coordinate of the points. :param polygon: (*PolygonShape list*) The polygon list. :returns: (*boolean array*) Inside or not. ''' if isinstance(x, numbers.Number): return GeoComputation.pointInPolygon(polygon, x, y) if isinstance(x, (list, tuple)): x = minum.array(x) if isinstance(y, (list, tuple)): y = minum.array(y) if isinstance(polygon, tuple): x_p = polygon[0] y_p = polygon[1] if isinstance(x_p, (list, tuple)): x_p = minum.array(x_p) if isinstance(y_p, (list, tuple)): y_p = minum.array(y_p) return MIArray(ArrayMath.inPolygon(x.array, y.array, x_p.array, y_p.array)) else: if isinstance(polygon, MILayer): polygon = polygon.shapes() elif isinstance(polygon, PolygonShape): polygon = [polygon] return MIArray(ArrayMath.inPolygon(x.array, y.array, polygon))
def inpolygon(self, x, y, polygon): if isinstance(polygon, tuple): x_p = polygon[0] y_p = polygon[1] if isinstance(x_p, MIArray): x_p = x_p.aslist() if isinstance(y_p, MIArray): y_p = y_p.aslist() return MIArray(ArrayMath.inPolygon(self.array, x.aslist(), y.aslist(), x_p, y_p)) else: if isinstance(polygon, MILayer): polygon = polygon.layer return MIArray(ArrayMath.inPolygon(self.array, x.aslist(), y.aslist(), polygon))