def addlabels(self, fieldname, **kwargs): ''' Add labels :param fieldname: (*string*) Field name :param fontname: (*string*) Font name. Default is ``Arial``. :param fontsize: (*string*) Font size. Default is ``14``. :param bold: (*boolean*) Font bold or not. Default is ``False``. :param color: (*color*) Label color. Default is ``None`` with black color. :param xoffset: (*int*) X coordinate offset. Default is ``0``. :param yoffset: (*int*) Y coordinate offset. Default is ``1``. :param avoidcoll: (*boolean*) Avoid labels collision or not. Default is ``True``. :param decimals: (*int*) Number of decimals of labels. ''' labelset = self.layer.getLabelSet() labelset.setFieldName(fieldname) fontname = kwargs.pop('fontname', 'Arial') fontsize = kwargs.pop('fontsize', 14) bold = kwargs.pop('bold', False) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) labelset.setLabelFont(font) color = kwargs.pop('color', None) if not color is None: color = miutil.getcolor(color) labelset.setLabelColor(color) xoffset = kwargs.pop('xoffset', 0) labelset.setXOffset(xoffset) yoffset = kwargs.pop('yoffset', 0) labelset.setYOffset(yoffset) avoidcoll = kwargs.pop('avoidcoll', True) labelset.setAvoidCollision(avoidcoll) decimals = kwargs.pop('decimals', None) if not decimals is None: labelset.setAutoDecimal(False) labelset.setDecimalDigits(decimals) self.layer.addLabels()
def addlabels(self, fieldname, **kwargs): ''' Add labels :param fieldname: (*string*) Field name :param fontname: (*string*) Font name. Default is ``Arial``. :param fontsize: (*string*) Font size. Default is ``14``. :param bold: (*boolean*) Font bold or not. Default is ``False``. :param color: (*color*) Label color. Default is ``None`` with black color. :param xoffset: (*int*) X coordinate offset. Default is ``0``. :param yoffset: (*int*) Y coordinate offset. Default is ``0``. :param avoidcoll: (*boolean*) Avoid labels collision or not. Default is ``True``. :param decimals: (*int*) Number of decimals of labels. ''' labelset = self.layer.getLabelSet() labelset.setFieldName(fieldname) fontname = kwargs.pop('fontname', 'Arial') fontsize = kwargs.pop('fontsize', 14) bold = kwargs.pop('bold', False) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) labelset.setLabelFont(font) color = kwargs.pop('color', None) if not color is None: color = miutil.getcolor(color) labelset.setLabelColor(color) xoffset = kwargs.pop('xoffset', 0) labelset.setXOffset(xoffset) yoffset = kwargs.pop('yoffset', 0) labelset.setYOffset(yoffset) avoidcoll = kwargs.pop('avoidcoll', True) labelset.setAvoidCollision(avoidcoll) decimals = kwargs.pop('decimals', None) if not decimals is None: labelset.setAutoDecimal(False) labelset.setDecimalDigits(decimals) self.layer.addLabels()
def add_charts(self, fieldnames, legend=None, **kwargs): ''' Add charts :param fieldnames: (*list of string*) Field name list. :param legend: (*LegendScheme*) Chart legend. :param charttype: (*string*) Chart type [bar | pie]. Default is ``bar``. :param minsize: (*int*) Minimum chart size. Default is ``0``. :param maxsize: (*int*) Maximum chart size. Default is ``50``. :param barwidth: (*int*) Bar width. Only valid for bar chart. Default is ``8``. :param xoffset: (*int*) X coordinate offset. Default is ``0``. :param yoffset: (*int*) Y coordinate offset. Default is ``0``. :param avoidcoll: (*boolean*) Avoid labels collision or not. Default is ``True``. :param align: (*string*) Chart align type [center | left | right | none], Default is ``center``. :param view3d: (*boolean*) Draw chart as 3D or not. Default is ``False``. :param thickness: (*int*) 3D chart thickness. Default is ``5``. :param drawlabel: (*boolean*) Draw label or not. Default is ``False``. :param fontname: (*string*) Label font name. :param fontsize: (*int*) Label font size. :param bold: (*boolean*) Font bold or not. Default is ``False``. :param labelcolor: (*color*) Label color. :param decimals: (*int*) Number of decimals of labels. ''' charttype = kwargs.pop('charttype', None) minsize = kwargs.pop('minsize', None) maxsize = kwargs.pop('maxsize', None) barwidth = kwargs.pop('barwidth', None) xoffset = kwargs.pop('xoffset', None) yoffset = kwargs.pop('yoffset', None) avoidcoll = kwargs.pop('avoidcoll', None) align = kwargs.pop('align', None) view3d = kwargs.pop('view3d', None) thickness = kwargs.pop('thickness', None) drawlabel = kwargs.pop('drawlabel', None) fontname = kwargs.pop('fontname', 'Arial') fontsize = kwargs.pop('fontsize', 12) bold = kwargs.pop('bold', False) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) labelcolor = kwargs.pop('labelcolor', None) decimals = kwargs.pop('decimals', None) chartset = self.layer.getChartSet() chartset.setFieldNames(fieldnames) chartset.setLegendScheme(legend) if not charttype is None: chartset.setChartType(charttype) if not minsize is None: chartset.setMinSize(minsize) if not maxsize is None: chartset.setMaxSize(maxsize) if not barwidth is None: chartset.setBarWidth(barwidth) if not xoffset is None: chartset.setXShift(xoffset) if not yoffset is None: chartset.setYShift(yoffset) if not avoidcoll is None: chartset.setAvoidCollision(avoidcoll) if not align is None: chartset.setAlignType(align) if not view3d is None: chartset.setView3D(view3d) if not thickness is None: chartset.setThickness(thickness) if not drawlabel is None: chartset.setDrawLabel(drawlabel) chartset.setLabelFont(font) if not labelcolor is None: chartset.setLabelColor(miutil.getcolor(labelcolor)) if not decimals is None: chartset.setDecimalDigits(decimals) self.layer.updateChartSet() self.layer.addCharts() return chartset
def geoshow(self, *args, **kwargs): ''' Display map layer or longitude latitude data. Syntax: -------- geoshow(shapefilename) - Displays the map data from a shape file. geoshow(layer) - Displays the map data from a map layer which may created by ``shaperead`` function. geoshow(S) - Displays the vector geographic features stored in S as points, multipoints, lines, or polygons. geoshow(lat, lon) - Displays the latitude and longitude vectors. ''' islayer = False if isinstance(args[0], basestring): fn = args[0] if not fn.endswith('.shp'): fn = fn + '.shp' if not os.path.exists(fn): fn = os.path.join(migl.mapfolder, fn) if os.path.exists(fn): layer = migeo.shaperead(fn) islayer = True else: raise IOError('File not exists: ' + fn) elif isinstance(args[0], MILayer): layer = args[0] islayer = True if islayer: layer = layer.layer visible = kwargs.pop('visible', True) layer.setVisible(visible) order = kwargs.pop('order', None) if layer.getLayerType() == LayerTypes.ImageLayer: if order is None: self.add_layer(layer) else: self.add_layer(layer, order) else: #LegendScheme ls = kwargs.pop('symbolspec', None) if ls is None: if len(kwargs) > 0 and layer.getLegendScheme().getBreakNum() == 1: lb = layer.getLegendScheme().getLegendBreaks().get(0) btype = lb.getBreakType() geometry = 'point' if btype == BreakTypes.PolylineBreak: geometry = 'line' elif btype == BreakTypes.PolygonBreak: geometry = 'polygon' lb, isunique = plotutil.getlegendbreak(geometry, **kwargs) layer.getLegendScheme().getLegendBreaks().set(0, lb) else: layer.setLegendScheme(ls) if order is None: self.add_layer(layer) else: self.add_layer(layer, order) #Labels labelfield = kwargs.pop('labelfield', None) if not labelfield is None: labelset = layer.getLabelSet() labelset.setFieldName(labelfield) fontname = kwargs.pop('fontname', 'Arial') fontsize = kwargs.pop('fontsize', 14) bold = kwargs.pop('bold', False) if bold: font = Font(fontname, Font.BOLD, fontsize) else: font = Font(fontname, Font.PLAIN, fontsize) labelset.setLabelFont(font) lcolor = kwargs.pop('labelcolor', None) if not lcolor is None: lcolor = miutil.getcolor(lcolor) labelset.setLabelColor(lcolor) xoffset = kwargs.pop('xoffset', 0) labelset.setXOffset(xoffset) yoffset = kwargs.pop('yoffset', 0) labelset.setYOffset(yoffset) avoidcoll = kwargs.pop('avoidcoll', True) decimals = kwargs.pop('decimals', None) if not decimals is None: labelset.setAutoDecimal(False) labelset.setDecimalDigits(decimals) labelset.setAvoidCollision(avoidcoll) layer.addLabels() self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer) else: if isinstance(args[0], Graphic): graphic = args[0] displaytype = 'point' stype = graphic.getShape().getShapeType() if stype == ShapeTypes.Polyline: displaytype = 'line' elif stype == ShapeTypes.Polygon: displaytype = 'polygon' lbreak, isunique = plotutil.getlegendbreak(displaytype, **kwargs) graphic.setLegend(lbreak) self.add_graphic(graphic) elif isinstance(args[0], Shape): shape = args[0] displaytype = 'point' stype = shape.getShapeType() if stype == ShapeTypes.Polyline: displaytype = 'line' elif stype == ShapeTypes.Polygon: displaytype = 'polygon' lbreak, isunique = plotutil.getlegendbreak(displaytype, **kwargs) graphic = Graphic(shape, lbreak) self.add_graphic(graphic) elif len(args) == 2: lat = args[0] lon = args[1] displaytype = kwargs.pop('displaytype', 'line') if isinstance(lat, (int, float)): displaytype = 'point' else: if len(lat) == 1: displaytype = 'point' else: if isinstance(lon, (MIArray, DimArray)): lon = lon.aslist() if isinstance(lat, (MIArray, DimArray)): lat = lat.aslist() lbreak, isunique = plotutil.getlegendbreak(displaytype, **kwargs) iscurve = kwargs.pop('iscurve', False) if displaytype == 'point': graphic = self.axes.addPoint(lat, lon, lbreak) elif displaytype == 'polyline' or displaytype == 'line': graphic = self.axes.addPolyline(lat, lon, lbreak, iscurve) elif displaytype == 'polygon': graphic = self.axes.addPolygon(lat, lon, lbreak) return graphic