Esempio n. 1
0
def split(a, b):
    ap = asshape(a)
    bp = asshape(b)
    cps = ap.split(bp)
    r = []
    for cp in cps:
        r.append(Graphic(cp, a.getLegend()))
    return r
Esempio n. 2
0
def convexhull(*args):
    if len(args) == 1:
        a = args[0]
        ap = asshape(a)
        cp = ap.convexHull()
        c = Graphic(cp, a.getLegend())
        return c
    else:
        x = args[0]
        y = args[1]
        r = ArrayUtil.convexHull(x.asarray(), y.asarray())
        return r
Esempio n. 3
0
 def text(self, x, y, z, s, zdir=None, **kwargs):
     '''
     Add text to the plot. kwargs will be passed on to text, except for the zdir 
     keyword, which sets the direction to be used as the z direction.
     
     :param x: (*float*) X coordinate.
     :param y: (*float*) Y coordinate.
     :param z: (*float*) Z coordinate.
     :param s: (*string*) Text string.
     :param zdir: Z direction.
     '''
     fontname = kwargs.pop('fontname', 'Arial')
     fontsize = kwargs.pop('fontsize', 14)
     bold = kwargs.pop('bold', False)
     color = kwargs.pop('color', 'black')
     if bold:
         font = Font(fontname, Font.BOLD, fontsize)
     else:
         font = Font(fontname, Font.PLAIN, fontsize)
     c = plotutil.getcolor(color)
     text = ChartText3D()
     text.setText(s)
     text.setFont(font)
     text.setColor(c)
     text.setPoint(x, y, z)
     ha = kwargs.pop('horizontalalignment', None)
     if ha is None:
         ha = kwargs.pop('ha', None)
     if not ha is None:
         text.setXAlign(ha)
     va = kwargs.pop('verticalalignment', None)
     if va is None:
         va = kwargs.pop('va', None)
     if not va is None:
         text.setYAlign(va)
     bbox = kwargs.pop('bbox', None)
     if not bbox is None:
         fill = bbox.pop('fill', None)
         if not fill is None:
             text.setFill(fill)
         facecolor = bbox.pop('facecolor', None)
         if not facecolor is None:
             facecolor = plotutil.getcolor(facecolor)
             text.setFill(True)
             text.setBackground(facecolor)
         edge = bbox.pop('edge', None)
         if not edge is None:
             text.setDrawNeatline(edge)
         edgecolor = bbox.pop('edgecolor', None)
         if not edgecolor is None:
             edgecolor = plotutil.getcolor(edgecolor)
             text.setNeatlineColor(edgecolor)
             text.setDrawNeatline(True)
         linewidth = bbox.pop('linewidth', None)
         if not linewidth is None:
             text.setNeatlineSize(linewidth)
             text.setDrawNeatline(True)
         gap = bbox.pop('gap', None)
         if not gap is None:
             text.setGap(gap)
     if not zdir is None:
         if isinstance(zdir, (list, tuple)):
             text.setZDir(zdir[0], zdir[1], zdir[2])
         else:
             text.setZDir(zdir)
     graphic = Graphic(text, None)
     visible = kwargs.pop('visible', True)
     if visible:
         self.add_graphic(graphic)
     return graphic
Esempio n. 4
0
    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
Esempio n. 5
0
def buffer(a, dis):
    ap = asshape(a)
    cp = ap.buffer(dis)
    c = Graphic(cp, a.getLegend())
    return c
Esempio n. 6
0
def symdifference(a, b):
    ap = asshape(a)
    bp = asshape(b)
    cp = ap.symDifference(bp)
    c = Graphic(cp, a.getLegend())
    return c
Esempio n. 7
0
def union(a, b):
    ap = asshape(a)
    bp = asshape(b)
    cp = ap.union(bp)
    c = Graphic(cp, a.getLegend())
    return c
Esempio n. 8
0
def intersect(a, b):
    ap = asshape(a)
    bp = asshape(b)
    cp = ap.intersection(bp)
    c = Graphic(cp, a.getLegend())
    return c