Ejemplo n.º 1
0
    def write(self, bbox, size):
        scx, scy = bbox.width / size[0], -1 * bbox.height / size[1]
        at = AffineTransform(scx, 0, 0, scy, bbox.west + scx / 2.0,
                             bbox.north + scy / 2.0)

        f = util.toFile(self.file)
        WorldFileWriter(f, at)
Ejemplo n.º 2
0
    def __init__(self, file, schema=None):
        f = util.toFile(file)
        name = path.splitext(path.basename(file))[0]

        from geoscript.workspace import Directory
        Layer.__init__(self,
                       name,
                       Directory(f.canonicalFile.parent),
                       schema=schema)
Ejemplo n.º 3
0
    def write(self, raster):
        """
     Replaces the content of this raster. 

     The *raster* parameter is a :class:`Raster` to write out.
     """
        if self.mode != 'w':
            raise Exception('Raster not created in write mode')

        w = self._format.getWriter(util.toFile(self.file))
        w.write(raster._coverage, None)
        w.dispose()
Ejemplo n.º 4
0
  def write(self, raster):
     """
     Replaces the content of this raster. 

     The *raster* parameter is a :class:`Raster` to write out.
     """
     if self.mode != 'w':
       raise Exception('Raster not created in write mode')

     w = self._format.getWriter(util.toFile(self.file))
     w.write(raster._coverage, None)
     w.dispose()
Ejemplo n.º 5
0
    def animated(images, file=None, delay=300, loop=False):
        """
     Generates an anmiated GIF. 

     The *images* parameter is a sequence of objects that can be read as 
     GIF images, such as an array of bytes.

     The *file* parameter specifies the file to generate. When omitted the 
     resulting animated GIF is returned from this function as an array byte. 

     The *delay* specifies the frame rate in milliseconds. 

     The *loop* parameter specifies whether the animated GIF should loop 
     continously.
     """
        from com.sun.media.imageioimpl.plugins.gif import GIFImageWriter
        from com.sun.media.imageioimpl.plugins.gif import GIFImageWriterSpi

        out = ByteArrayOutputStream() if file is None else util.toFile(file)
        ios = ImageIO.createImageOutputStream(out)
        w = GIFImageWriter(GIFImageWriterSpi())
        w.setOutput(ios)
        w.prepareWriteSequence(None)

        wp = w.getDefaultWriteParam()
        wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
        wp.setCompressionType('LZW')
        wp.setCompressionQuality(0.75)

        for img in images:
            iis = ImageIO.createImageInputStream(util.toInputStream(img))
            ri = ImageIO.read(iis)

            md = w.getDefaultImageMetadata(ImageTypeSpecifier(ri), wp)
            t = IIOMetadataTree(md)
            t.set('GraphicControlExtension', delayTime=delay / 10)
            if loop is True:
                n = t.set('ApplicationExtensions',
                          'ApplicationExtension',
                          applicationID='NETSCAPE',
                          authenticationCode='2.0')
                n.setUserObject(jarray.array([0x1, 0, 0], 'b'))
            t.commit()

            w.writeToSequence(IIOImage(ri, None, md), wp)

        w.endWriteSequence()
        ios.flush()
        ios.close()

        if file is None:
            return out.toByteArray()
Ejemplo n.º 6
0
   def animated(images, file=None, delay=300, loop=False):
     """
     Generates an anmiated GIF. 

     The *images* parameter is a sequence of objects that can be read as 
     GIF images, such as an array of bytes.

     The *file* parameter specifies the file to generate. When omitted the 
     resulting animated GIF is returned from this function as an array byte. 

     The *delay* specifies the frame rate in milliseconds. 

     The *loop* parameter specifies whether the animated GIF should loop 
     continously.
     """
     from com.sun.media.imageioimpl.plugins.gif import GIFImageWriter
     from com.sun.media.imageioimpl.plugins.gif import GIFImageWriterSpi

     out = ByteArrayOutputStream() if file is None else util.toFile(file)
     ios = ImageIO.createImageOutputStream(out)
     w = GIFImageWriter(GIFImageWriterSpi())
     w.setOutput(ios)
     w.prepareWriteSequence(None)

     wp = w.getDefaultWriteParam()
     wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
     wp.setCompressionType('LZW')
     wp.setCompressionQuality(0.75)

     for img in images:   
       iis = ImageIO.createImageInputStream(util.toInputStream(img))
       ri = ImageIO.read(iis)

       md = w.getDefaultImageMetadata(ImageTypeSpecifier(ri),wp)
       t = IIOMetadataTree(md)
       t.set('GraphicControlExtension', delayTime=delay/10)
       if loop is True:
         n = t.set('ApplicationExtensions', 'ApplicationExtension', 
           applicationID='NETSCAPE', authenticationCode='2.0')
         n.setUserObject(jarray.array([0x1,0, 0], 'b'))
       t.commit()

       w.writeToSequence(IIOImage(ri, None, md), wp)

     w.endWriteSequence()
     ios.flush()
     ios.close()

     if file is None:
       return out.toByteArray()
Ejemplo n.º 7
0
   def _encode(self, img, g, size, **opts):
      file = opts['file'] if opts.has_key('file') else None
      if file:
        # write out to file
        ImageIO.write(img, self.format, util.toFile(file))
      else:
        # write to byte array
        out = ByteArrayOutputStream()
        ImageIO.write(img, self.format, out)
        bytes = out.toByteArray()

        # check for strencode flag to check whether to return result as raw 
        # bytes or as string
        if opts.has_key('strencode'):
          return str(String(bytes, 0, 0, len(bytes)))
        return out.toByteArray()
Ejemplo n.º 8
0
    def _encode(self, img, g, size, **opts):
        file = opts['file'] if opts.has_key('file') else None
        if file:
            # write out to file
            ImageIO.write(img, self.format, util.toFile(file))
        else:
            # write to byte array
            out = ByteArrayOutputStream()
            ImageIO.write(img, self.format, out)
            bytes = out.toByteArray()

            # check for strencode flag to check whether to return result as raw
            # bytes or as string
            if opts.has_key('strencode'):
                return str(String(bytes, 0, 0, len(bytes)))
            return out.toByteArray()
Ejemplo n.º 9
0
  def __init__(self, format, file=None, proj=None, coverage=None, reader=None,
               mode='r'):
    self.file = file
    self._format = format
    self._coverage = coverage
    self._reader = reader
    self.mode = mode

    if mode == 'r': 
      if not coverage:
        if not reader:
          hints = Hints()
          if proj:
            proj = Projection(proj)
            hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, proj._crs) 

          self._reader = format.getReader(util.toFile(file), hints)
        self._coverage = self._reader.read(None)
Ejemplo n.º 10
0
    def __init__(self,
                 format,
                 file=None,
                 proj=None,
                 coverage=None,
                 reader=None,
                 mode='r'):
        self.file = file
        self._format = format
        self._coverage = coverage
        self._reader = reader
        self.mode = mode

        if mode == 'r':
            if not coverage:
                if not reader:
                    hints = Hints()
                    if proj:
                        proj = Projection(proj)
                        hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM,
                                  proj._crs)

                    self._reader = format.getReader(util.toFile(file), hints)
                self._coverage = self._reader.read(None)
Ejemplo n.º 11
0
 def savepng(self, filename, size=(500, 500)):
     ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
Ejemplo n.º 12
0
 def __init__(self, dir=None):
     dir = dir or os.getcwd()
     params = {'directory': util.toFile(dir)}
     Workspace.__init__(self, PropertyDataStoreFactory(), params)
Ejemplo n.º 13
0
 def savepng(self, filename, size=(500,500)):
   ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
Ejemplo n.º 14
0
  def __init__(self, file):
    f = util.toFile(file) 
    name = path.splitext(path.basename(file))[0]

    from geoscript.workspace import Directory
    Layer.__init__(self, name, Directory(f.canonicalFile.parent))
Ejemplo n.º 15
0
 def write(self, bbox, size): 
   scx, scy = bbox.width / size[0], -1*bbox.height / size[1]
   at = AffineTransform(scx, 0, 0, scy, bbox.west+scx/2.0, bbox.north+scy/2.0)
   
   f = util.toFile(self.file)
   WorldFileWriter(f, at)
Ejemplo n.º 16
0
    def read(self):
        f = util.toFile(self.file)
        if f is None or not f.exists():
            raise Exception('No such file %s' % self.file)

        return WorldFileReader(f)
Ejemplo n.º 17
0
 def __init__(self, dir=None):
   dir = dir or os.getcwd()
   params = {'directory': util.toFile(dir)}
   Workspace.__init__(self, PropertyDataStoreFactory(), params)
Ejemplo n.º 18
0
   def read(self):
     f = util.toFile(self.file)
     if f is None or not f.exists():
       raise Exception('No such file %s' % self.file)

     return WorldFileReader(f)