Exemple #1
0
def test():
    import shutil

    from core.layerlist import LayerList, Layer
    from animation.data import AnimLayer
    from animation.utils import layerListToCmdsMatrix
    import grass.temporal as tgis
    tgis.init()

    layerList = LayerList()
    layer = AnimLayer()
    layer.mapType = 'strds'
    layer.name = 'JR'
    layer.cmd = ['d.rast', 'map=elev_2007_1m']
    layerList.AddLayer(layer)

    layer = Layer()
    layer.mapType = 'vector'
    layer.name = 'buildings_2009_approx'
    layer.cmd = ['d.vect', 'map=buildings_2009_approx', 'color=grey']
    layer.opacity = 50
    layerList.AddLayer(layer)

    bPool = BitmapPool()
    mapFilesPool = MapFilesPool()

    tempDir = '/tmp/test'
    if os.path.exists(tempDir):
        shutil.rmtree(tempDir)
    os.mkdir(tempDir)
    # comment this line to keep the directory after prgm ends
    #    cleanUp = CleanUp(tempDir)
    #    import atexit
    #    atexit.register(cleanUp)

    prov = BitmapProvider(bPool,
                          mapFilesPool,
                          tempDir,
                          imageWidth=640,
                          imageHeight=480)
    prov.renderingStarted.connect(lambda count: sys.stdout.write(
        "Total number of maps: {c}\n".format(c=count)))
    prov.renderingContinues.connect(lambda current, text: sys.stdout.write(
        "Current number: {c}\n".format(c=current)))
    prov.compositionStarted.connect(lambda count: sys.stdout.write(
        "Composition: total number of maps: {c}\n".format(c=count)))
    prov.compositionContinues.connect(lambda current, text: sys.stdout.write(
        "Composition: Current number: {c}\n".format(c=current)))
    prov.mapsLoaded.connect(
        lambda: sys.stdout.write("Maps loading finished\n"))
    cmdMatrix = layerListToCmdsMatrix(layerList)
    prov.SetCmds(cmdMatrix, [l.opacity for l in layerList])
    app = wx.App()

    prov.Load(bgcolor=(13, 156, 230), nprocs=4)

    for key in bPool.keys():
        if key is not None:
            bPool[key].SaveFile(os.path.join(tempDir, key + '.png'),
                                wx.BITMAP_TYPE_PNG)
Exemple #2
0
    def __init__(
        self,
        parent,
        title=_("Select raster maps"),
        first=None,
        second=None,
        firstLayerList=None,
        secondLayerList=None,
    ):

        wx.Dialog.__init__(
            self,
            parent=parent,
            title=title,
            style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE,
        )

        if firstLayerList is None:
            self._firstLayerList = LayerList()
        else:
            self._firstLayerList = copy.deepcopy(firstLayerList)
        if secondLayerList is None:
            self._secondLayerList = LayerList()
        else:
            self._secondLayerList = copy.deepcopy(secondLayerList)

        self._firstPanel = self._createSimplePanel()
        self._secondPanel = self._createAdvancedPanel()

        self.btnSwitch = Button(self)
        self.btnCancel = Button(self, id=wx.ID_CANCEL)
        self.btnApply = Button(self, id=wx.ID_APPLY)
        self.btnOK = Button(self, id=wx.ID_OK)
        self.btnOK.SetDefault()

        self.btnSwitch.Bind(wx.EVT_BUTTON, self.OnSwitchMode)
        self.btnApply.Bind(wx.EVT_BUTTON, lambda evt: self._apply())
        self.btnOK.Bind(wx.EVT_BUTTON, lambda evt: self._ok())
        self.btnCancel.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
        self.Bind(wx.EVT_CLOSE, lambda evt: self.Hide())

        self.applyChanges = Signal("SwipeMapDialog.applyChanges")

        if first:
            self._firstRaster.SetValue(first)
        if second:
            self._secondRaster.SetValue(second)

        self._layout()
Exemple #3
0
def main():
    rast = options['rast']
    vect = options['vect']
    strds = options['strds']
    stvds = options['stvds']

    numInputs = 0

    if rast:
        numInputs += 1
    if vect:
        numInputs += 1
    if strds:
        numInputs += 1
    if stvds:
        numInputs += 1

    if numInputs > 1:
        grass.fatal(
            _("%s=, %s=, %s= and %s= are mutually exclusive.") %
            ("rast", "vect", "strds", "stvds"))

    if numInputs > 0:
        # We need to initialize the temporal framework in case
        # a space time dataset was set on the command line so that
        # the AnimLayer() class works correctly
        tgis.init()

    layerList = LayerList()
    if rast:
        layer = AnimLayer()
        layer.mapType = 'rast'
        layer.name = rast
        layer.cmd = ['d.rast', 'map={name}'.format(name=rast.split(',')[0])]
        layerList.AddLayer(layer)
    if vect:
        layer = AnimLayer()
        layer.mapType = 'vect'
        layer.name = vect
        layer.cmd = ['d.vect', 'map={name=}'.format(name=vect.split(',')[0])]
        layerList.AddLayer(layer)
    if strds:
        layer = AnimLayer()
        layer.mapType = 'strds'
        layer.name = strds
        layer.cmd = ['d.rast', 'map=']
        layerList.AddLayer(layer)
    if stvds:
        layer = AnimLayer()
        layer.mapType = 'stvds'
        layer.name = stvds
        layer.cmd = ['d.vect', 'map=']
        layerList.AddLayer(layer)

    app = wx.App()
    if not CheckWxVersion([2, 9]):
        wx.InitAllImageHandlers()

    frame = AnimationFrame(parent=None, giface=StandaloneGrassInterface())
    frame.CentreOnScreen()
    frame.Show()
    if len(layerList) >= 1:
        frame.SetAnimations([layerList] + [None] * (MAX_COUNT - 1))
    app.MainLoop()
Exemple #4
0
def main():
    options, flags = gscript.parser()

    # import wx only after running parser
    # to avoid issues when only interface is needed
    import grass.temporal as tgis
    import wx

    from grass.script.setup import set_gui_path
    set_gui_path()

    from core.giface import StandaloneGrassInterface
    from core.layerlist import LayerList
    from animation.frame import AnimationFrame, MAX_COUNT
    from animation.data import AnimLayer

    rast = options['raster']
    vect = options['vector']
    strds = options['strds']
    stvds = options['stvds']

    numInputs = 0

    if rast:
        numInputs += 1
    if vect:
        numInputs += 1
    if strds:
        numInputs += 1
    if stvds:
        numInputs += 1

    if numInputs > 1:
        gscript.fatal(_("%s=, %s=, %s= and %s= are mutually exclusive.") %
                       ("raster", "vector", "strds", "stvds"))

    if numInputs > 0:
        # We need to initialize the temporal framework in case
        # a space time dataset was set on the command line so that
        # the AnimLayer() class works correctly
        try:
            tgis.init()
        except FatalError as e:
            print(e)

    layerList = LayerList()
    if rast:
        layer = AnimLayer()
        layer.mapType = 'raster'
        layer.name = rast
        layer.cmd = ['d.rast', 'map={name}'.format(name=rast.split(',')[0])]
        layerList.AddLayer(layer)
    if vect:
        layer = AnimLayer()
        layer.mapType = 'vector'
        layer.name = vect
        layer.cmd = ['d.vect', 'map={name}'.format(name=vect.split(',')[0])]
        layerList.AddLayer(layer)
    if strds:
        layer = AnimLayer()
        layer.mapType = 'strds'
        layer.name = strds
        layer.cmd = ['d.rast', 'map=']
        layerList.AddLayer(layer)
    if stvds:
        layer = AnimLayer()
        layer.mapType = 'stvds'
        layer.name = stvds
        layer.cmd = ['d.vect', 'map=']
        layerList.AddLayer(layer)

    app = wx.App()

    frame = AnimationFrame(parent=None, giface=StandaloneGrassInterface())
    frame.CentreOnScreen()
    frame.Show()
    if len(layerList) >= 1:
        # CallAfter added since it was crashing with wxPython 3 gtk
        wx.CallAfter(frame.SetAnimations,
                     [layerList] + [None] * (MAX_COUNT - 1))
    app.MainLoop()
Exemple #5
0
 def SetDefaultValues(self, windowIndex, animationIndex):
     self.windowIndex = windowIndex
     self.name = _("Animation %d") % (animationIndex + 1)
     self.layerList = LayerList()
Exemple #6
0
 def __init__(self, parent):
     wx.Frame.__init__(self,
                       parent=parent,
                       title="Simple layer manager test")
     SimpleLayerManager(parent=self, layerList=LayerList())
Exemple #7
0
 def __init__(self, parent):
     wx.Frame.__init__(self, parent=parent)
     SimpleLayerManager(parent=self, layerList=LayerList())