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)
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)
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()
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()
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()
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()
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)
def savepng(self, filename, size=(500, 500)): ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
def __init__(self, dir=None): dir = dir or os.getcwd() params = {'directory': util.toFile(dir)} Workspace.__init__(self, PropertyDataStoreFactory(), params)
def savepng(self, filename, size=(500,500)): ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
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))
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)
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)