示例#1
0
 def setLegendItems(self):
     items = LegendItemCollection()
     items.add(
         LegendItem("PostUpRegulated", None, None, None,
                    Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0), Color.green))
     items.add(
         LegendItem("PostDownRegulated", None, None, None,
                    Rectangle2D.Double(-6.0, -3.0, 12.0, 6.0), Color.red))
     return items
示例#2
0
 def save(self, parent, format):
     chooser = JFileChooser()
     # filter = FileNameExtensionFilter(
     #     format + " files",
     #     array([format, format.lower()], String))
     # chooser.setFileFilter(filter);
     returnVal = chooser.showSaveDialog(parent)
     if returnVal == JFileChooser.APPROVE_OPTION:
         fileName = chooser.getSelectedFile().getPath()
         if not fileName.upper().endswith('.' + format):
             fileName += '.' + format.lower()
         file = File(fileName)
     else:
         return
     if format == 'PNG':
         ChartUtils.saveChartAsPNG(file, self.chart, self.exportX,
                                   self.exportY)
     elif format == 'SVG':
         domImpl = GenericDOMImplementation.getDOMImplementation()
         doc = domImpl.createDocument(None, "svg", None)
         svgGen = SVGGraphics2D(doc)
         svgGen.getGeneratorContext().setPrecision(6)
         self.chart.draw(
             svgGen, Rectangle2D.Double(0, 0, self.exportX, self.exportY),
             None)
         out = OutputStreamWriter(FileOutputStream(file), "UTF-8")
         svgGen.stream(out, True)  #True is for useCSS
         out.close()
     elif format == 'PDF':
         mapper = DefaultFontMapper()
         pageSize = Rectangle(self.exportX, self.exportY)
         doc = TextDocument(pageSize, 50, 50, 50, 50)
         out = BufferedOutputStream(FileOutputStream(file))
         writer = PdfWriter.getInstance(doc, out)
         doc.open()
         cb = writer.getDirectContent()
         tp = cb.createTemplate(self.exportX, self.exportY)
         g2 = tp.createGraphics(self.exportX, self.exportY, mapper)
         r2D = Rectangle2D.Double(0, 0, self.exportX, self.exportY)
         self.chart.draw(g2, r2D)
         g2.dispose()
         cb.addTemplate(tp, 0, 0)
         doc.close()
	def draw(self, graphics):
		sz = self.__element.getActualSize()
		prevPaint = graphics.getPaint()
		prevStroke = graphics.getStroke()
		current = self.__element.pushLocalToRootGraphicsTransform(graphics)
		graphics.setPaint(Color(0.0, 0.3, 0.6, 0.5))
		graphics.setStroke(BasicStroke(2.0))
		graphics.draw(Rectangle2D.Double(1.0, 1.0, sz.x - 2.0, sz.y - 2.0))
		graphics.setPaint(prevPaint)
		graphics.setStroke(prevStroke)
		self.__element.popGraphicsTransform(graphics, current)
示例#4
0
    def __defineExtent(self, algorithm, kwparams):
        """ Define Analysis Extent """
        if 'EXTENT' in kwparams.keys():
            print("|" + str(kwparams.keys()))
            frame = kwparams['EXTENT']
            print("|" + str(frame))
            print "TIPO DE FRAME", type(frame)
            if isinstance(frame, str) and frame == 'VIEW' or isinstance(
                    frame, gvsig.View):
                AExtent = AnalysisExtent()
                print "EXTENT ************ VIEW"
                if isinstance(frame, gvsig.View): view = frame
                else: view = gvsig.currentView()
                envelope = view.getMap().getFullEnvelope()
                xlow = envelope.getLowerCorner().getX()
                ylow = envelope.getLowerCorner().getY()
                xup = envelope.getUpperCorner().getX()
                yup = envelope.getUpperCorner().getY()
                #print xlow, ylow, xup, yup
                frame = Rectangle2D.Double(xlow, ylow, xup, yup)
                print frame
                AExtent.addExtent(frame)
            #elif isinstance(frame, raster):
            elif isinstance(frame, DefaultFLyrRaster):
                print "EXTENT ************ RASTER"
                layer = self.__createSextanteRaster(frame)
                AExtent = AnalysisExtent(layer)
            elif isinstance(frame, list):
                print "EXTENT ************ LIST"
                AExtent = AnalysisExtent()
                xlow, ylow, xup, yup = frame[0], frame[1], frame[2], frame[3]
                frame = Rectangle2D.Double(xlow, ylow, xup, yup)
                print frame
                AExtent.addExtent(frame)
            elif isinstance(frame, gvsig.Layer):
                print "EXTENT ************ layer"
                layer = self.__createSextanteLayer(frame())
                AExtent = AnalysisExtent(layer)
                """
              envelope = frame.data().getEnvelope()
              xlow = envelope.getLowerCorner().getX()
              ylow = envelope.getLowerCorner().getY()
              xup = envelope.getUpperCorner().getX()
              yup = envelope.getUpperCorner().getY()
              """
            else:
                raise NameError("Not Extent Define")

            #Set: cellsize
            if 'CELLSIZE' in kwparams.keys():
                AExtent.setCellSize(kwparams['CELLSIZE'])
                print "| New Cellsize: ", kwparams[
                    'CELLSIZE'], AExtent.getCellSize()
            else:
                print "| Cellsize: ", AExtent.getCellSize()

            algorithm.setAnalysisExtent(AExtent)
            print("| Set Extent")
        else:
            print("| Not Extent")
            #???
            if algorithm.canDefineOutputExtentFromInput():
                algorithm.adjustOutputExtent()
示例#5
0
def squarea(
    self, offset
):  #This is the default area generator. It will be overridden by certain shapes.
    return Area(Rectangle2D.Double(-offset.x, -offset.y, 1, 1))
示例#6
0
    def __defineExtent(self, algorithm, kwparams):
        """ Define Analysis Extent """
        if 'EXTENT' in kwparams.keys(
        ) and algorithm.getUserCanDefineAnalysisExtent():
            frame = kwparams['EXTENT']
            if isinstance(frame, str):
                frame = gvsig.currentView().getLayer(frame)
            #print ("|"+str(frame)+"||"+str(type(frame)))
            if isinstance(frame, str) or isinstance(frame, gvsig.View):
                AExtent = AnalysisExtent()
                print "| EXTENT from VIEW"
                if isinstance(frame, gvsig.View): view = frame
                else: view = gvsig.currentProject().getView(frame)
                envelope = view.getMap().getFullEnvelope()
                xlow = envelope.getLowerCorner().getX()
                ylow = envelope.getLowerCorner().getY()
                xup = envelope.getUpperCorner().getX()
                yup = envelope.getUpperCorner().getY()
                AExtent.setXRange(xlow, xup, False)
                AExtent.setYRange(ylow, yup, False)
                AExtent.setZRange(0, 0, False)
            elif isinstance(frame, DefaultFLyrRaster):
                print "| EXTENT from RASTER"
                layer = self.__createSextanteRaster(frame)
                AExtent = AnalysisExtent(layer)
            elif isinstance(frame, list):
                print "| EXTENT from LIST"
                AExtent = AnalysisExtent()
                xlow, ylow, zlow, xup, yup, zup = frame[0], frame[1], frame[
                    2], frame[3], frame[4], frame[5]
                AExtent.setXRange(xlow, xup, False)
                AExtent.setYRange(ylow, yup, False)
                AExtent.setZRange(zlow, zup, False)
            elif isinstance(frame, gvsig.Layer):
                print "| EXTENT from Layer"
                layer = self.__createSextanteLayer(frame())
                AExtent = AnalysisExtent(layer)
            else:
                raise Exception("Not Extent Define")
        else:
            print("| Not Extent: No input data")
            if algorithm.canDefineOutputExtentFromInput():
                algorithm.adjustOutputExtent()
            AExtent = AnalysisExtent()
            print "| EXTENT from VIEW"
            try:
                envelope = gvsig.currentView().getMap().getFullEnvelope()
            except:
                raise Exception("None open View")
            print "| Setting AExtent: ",
            try:
                xlow = envelope.getLowerCorner().getX()
                ylow = envelope.getLowerCorner().getY()
                zlow = 0
                xup = envelope.getUpperCorner().getX()
                yup = envelope.getUpperCorner().getY()
                zup = 0
                print "| View: ",
                print xlow, ylow, xup, yup
            except:
                xlow, ylow, zlow, xup, yup, zup = 0, 0, 0, 100, 100, 0
                print "| Default:", xlow, ylow, xup, yup
            frame = Rectangle2D.Double(xlow, ylow, xup, yup)
            AExtent.setXRange(xlow, xup, False)
            AExtent.setYRange(ylow, yup, False)
            AExtent.setZRange(zlow, zup, False)
            algorithm.setAnalysisExtent(AExtent)

        #Set: cellsize
        if 'CELLSIZE' in kwparams.keys():
            AExtent.setCellSize(kwparams['CELLSIZE'])
            print "| New Cellsize: ", kwparams[
                'CELLSIZE'], AExtent.getCellSize()
        else:
            print "| Cellsize: ", AExtent.getCellSize()

        if 'CELLSIZEZ' in kwparams.keys():
            AExtent.setCellSizeZ(kwparams['CELLSIZEZ'])
            print "| New Cellsize Z: ", kwparams[
                'CELLSIZEZ'], AExtent.getCellSizeZ()
        else:
            print "| CellsizeZ: ", AExtent.getCellSizeZ()
        algorithm.setAnalysisExtent(AExtent)
        print("| Set Extent")