def makeshapes(x, y, type=None, z=None, m=None): """ Make shapes by x and y coordinates. :param x: (*array_like*) X coordinates. :param y: (*array_like*) Y coordinates. :param type: (*string*) Shape type [point | line | polygon]. :param z: (*array_like*) Z coordinates. :param m: (*array_like*) M coordinates. :returns: Shapes """ shapes = [] if isinstance(x, (int, float)): shape = PointShape() shape.setPoint(PointD(x, y)) shapes.append(shape) else: x = minum.asarray(x).array y = minum.asarray(y).array if not z is None: if m is None: m = minum.zeros(len(z)).array else: m = minum.asarray(m) z = minum.asarray(z) if type == 'point': if z is None: shapes = ShapeUtil.createPointShapes(x, y) else: shapes = ShapeUtil.createPointShapes(x, y, z, m) elif type == 'line': if z is None: shapes = ShapeUtil.createPolylineShapes(x, y) else: shapes = ShapeUtil.createPolylineShapes(x, y, z, m) elif type == 'polygon': if z is None: shapes = ShapeUtil.createPolygonShapes(x, y) else: shapes = ShapeUtil.createPolygonShape(x, y, z, m) return shapes
def makeshapes(x, y, type=None, z=None, m=None): """ Make shapes by x and y coordinates. :param x: (*array_like*) X coordinates. :param y: (*array_like*) Y coordinates. :param type: (*string*) Shape type [point | line | polygon]. :param z: (*array_like*) Z coordinates. :param m: (*array_like*) M coordinates. :returns: Shapes """ shapes = [] if isinstance(x, (int, float)): shape = PointShape() shape.setPoint(PointD(x, y)) shapes.append(shape) else: x = minum.asarray(x).array y = minum.asarray(y).array if not z is None: if m is None: m = minum.zeros(len(z)).array else: m = minum.asarray(m).array z = minum.asarray(z).array if type == 'point': if z is None: shapes = ShapeUtil.createPointShapes(x, y) else: shapes = ShapeUtil.createPointShapes(x, y, z, m) elif type == 'line': if z is None: shapes = ShapeUtil.createPolylineShapes(x, y) else: shapes = ShapeUtil.createPolylineShapes(x, y, z, m) elif type == 'polygon': if z is None: shapes = ShapeUtil.createPolygonShapes(x, y) else: shapes = ShapeUtil.createPolygonShape(x, y, z, m) return shapes
def barbs(self, *args, **kwargs): """ Plot a 2-D field of barbs in a map. :param x: (*array_like*) Optional. X coordinate array. :param y: (*array_like*) Optional. Y coordinate array. :param u: (*array_like*) U component of the arrow vectors (wind field) or wind direction. :param v: (*array_like*) V component of the arrow vectors (wind field) or wind speed. :param z: (*array_like*) Optional, 2-D z value array. :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level barbs to draw, in increasing order. :param cmap: (*string*) Color map string. :param fill_value: (*float*) Fill_value. Default is ``-9999.0``. :param isuv: (*boolean*) Is U/V or direction/speed data array pairs. Default is True. :param size: (*float*) Base size of the arrows. :param proj: (*ProjectionInfo*) Map projection of the data. Default is None. :param zorder: (*int*) Z-order of created layer for display. :param select: (*boolean*) Set the return layer as selected layer or not. :returns: (*VectoryLayer*) Created barbs VectoryLayer. """ cmap = plotutil.getcolormap(**kwargs) fill_value = kwargs.pop('fill_value', -9999.0) proj = kwargs.pop('proj', None) order = kwargs.pop('order', None) isuv = kwargs.pop('isuv', True) n = len(args) iscolor = False cdata = None onlyuv = True if n >= 4 and isinstance(args[3], (DimArray, MIArray)): onlyuv = False if onlyuv: u = minum.asarray(args[0]) v = minum.asarray(args[1]) xx = args[0].dimvalue(1) yy = args[0].dimvalue(0) x, y = minum.meshgrid(xx, yy) args = args[2:] if len(args) > 0: cdata = minum.asarray(args[0]) iscolor = True args = args[1:] else: x = minum.asarray(args[0]) y = minum.asarray(args[1]) u = minum.asarray(args[2]) v = minum.asarray(args[3]) args = args[4:] if len(args) > 0: cdata = minum.asarray(args[0]) iscolor = True args = args[1:] if iscolor: if len(args) > 0: cn = args[0] ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cn, cmap) else: levs = kwargs.pop('levs', None) if levs is None: ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cmap) else: if isinstance(levs, MIArray): levs = levs.tolist() ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), levs, cmap) else: if cmap.getColorCount() == 1: c = cmap.getColor(0) else: c = Color.black ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, c, 10) ls = plotutil.setlegendscheme_point(ls, **kwargs) if not cdata is None: cdata = cdata.array layer = DrawMeteoData.createBarbLayer(x.array, y.array, u.array, v.array, cdata, ls, 'layer', isuv) if not proj is None: layer.setProjInfo(proj) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
def plot(self, *args, **kwargs): """ Plot lines and/or markers to the map. :param x: (*array_like*) Input x data. :param y: (*array_like*) Input y data. :param style: (*string*) Line style for plot. :param linewidth: (*float*) Line width. :param color: (*Color*) Line color. :returns: (*VectoryLayer*) Line VectoryLayer. """ fill_value = kwargs.pop('fill_value', -9999.0) proj = kwargs.pop('proj', None) order = kwargs.pop('order', None) n = len(args) xdatalist = [] ydatalist = [] styles = [] if n == 1: ydata = plotutil.getplotdata(args[0]) if isinstance(args[0], DimArray): xdata = args[0].dimvalue(0) else: xdata = [] for i in range(0, len(args[0])): xdata.append(i) xdatalist.append(minum.asarray(xdata).array) ydatalist.append(minum.asarray(ydata).array) elif n == 2: if isinstance(args[1], basestring): ydata = plotutil.getplotdata(args[0]) if isinstance(args[0], DimArray): xdata = args[0].dimvalue(0) else: xdata = [] for i in range(0, len(args[0])): xdata.append(i) styles.append(args[1]) else: xdata = plotutil.getplotdata(args[0]) ydata = plotutil.getplotdata(args[1]) xdatalist.append(minum.asarray(xdata).array) ydatalist.append(minum.asarray(ydata).array) else: c = 'x' for arg in args: if c == 'x': xdatalist.append(minum.asarray(arg).array) c = 'y' elif c == 'y': ydatalist.append(minum.asarray(arg).array) c = 's' elif c == 's': if isinstance(arg, basestring): styles.append(arg) c = 'x' else: styles.append('-') xdatalist.append(minum.asarray(arg).array) c = 'y' snum = len(xdatalist) if len(styles) == 0: styles = None else: while len(styles) < snum: styles.append('-') #Get plot data styles - Legend lines = [] ls = kwargs.pop('legend', None) if ls is None: if styles != None: for i in range(0, len(styles)): line = plotutil.getplotstyle(styles[i], str(i), **kwargs) lines.append(line) else: for i in range(0, snum): label = kwargs.pop('label', 'S_' + str(i + 1)) line = plotutil.getlegendbreak('line', **kwargs)[0] line.setCaption(label) lines.append(line) ls = LegendScheme(lines) layer = DrawMeteoData.createPolylineLayer(xdatalist, ydatalist, ls, \ 'Plot_lines', 'ID', -180, 180) if (proj != None): layer.setProjInfo(proj) # Add layer isadd = kwargs.pop('isadd', True) if isadd: zorder = kwargs.pop('zorder', None) select = kwargs.pop('select', True) self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)