Exemple #1
0
 def __del__(self):
     info("Cleaning up interpolated layer {}".format(self.layer.name()))
     qgs.removeLayer(self.memLayer.id())
     try:
         del self.memLayer
     except Exception:
         pass
Exemple #2
0
def make_animation(out_folder,
                   delay_millis,
                   frame_pattern=DEFAULT_FRAME_PATTERN):
    if not can_animate():
        error("Imagemagick is not in path")
        raise Exception(
            "Imagemagick is not in path. Please install ImageMagick!")
    out_file = os.path.join(out_folder, DEFAULT_ANIMATION_NAME)
    all_frames = glob.glob(os.path.join(out_folder, frame_pattern))
    if len(all_frames) == 0:
        msg = "Couldn't find any frames with pattern {} in folder {} to animate".format(
            frame_pattern, out_folder)
        error(msg)
        raise Exception(msg)
    all_frames.sort()
    fps = 1000 / delay_millis
    args = [IMAGEMAGICK, "-delay", "1x" + str(fps)] + all_frames + [out_file]
    ret = subprocess.check_call(args)
    if (ret != 0):
        msg = "Something went wrong creating the animated gif from frames"
        error(msg)
        raise Exception(msg)
    info("Exported {} frames to gif {} (call :{})".format(
        len(all_frames), out_file, args))
    return out_file
 def guessTimePositionInStr(cls, str_with_time):
     try:
         m = re.match(cls.TIME_REGEX, str_with_time)
         return m.start(2), m.end(2)
     except Exception as e:
         info("Could not guess timestamp in raster filename. Cause {}".format(e))
         return (0, 0)
Exemple #4
0
    def __init__(self, settings, iface=None):
        TimeLayer.__init__(self, settings.layer, settings.isEnabled)

        try:
            self.layer = settings.layer
            self.iface = iface
            self.minValue, self.maxValue = None, None
            self.fromTimeAttribute = settings.startTimeAttribute
            self.toTimeAttribute = settings.endTimeAttribute if settings.endTimeAttribute != "" \
                else self.fromTimeAttribute
            self.accumulate = settings.accumulate
            self.resetsss = settings.resetSubsetString
            self.originalSubsetString = settings.subsetStr
            self.currSubsetString = self.originalSubsetString
            if self.resetsss:
                self.setSubsetString("")
            else:
                self.setSubsetString(self.originalSubsetString)
            self.geometriesCount = settings.geometriesCount
            self.type = time_util.DateTypes.determine_type(
                self.getRawMinValue())
            if self.type not in time_util.DateTypes.QDateTypes:
                # call to throw an exception early if no format can be found
                self.findValidValues(self.fromTimeAttribute,
                                     settings.timeFormat)
                if self.fromTimeAttribute != self.toTimeAttribute:
                    self.findValidValues(self.toTimeAttribute,
                                         settings.timeFormat)

            self.timeFormat = self.determine_format(self.getRawMinValue(),
                                                    settings.timeFormat)
            if self.toTimeAttribute != self.fromTimeAttribute:
                type2 = time_util.DateTypes.determine_type(
                    self.getRawMaxValue())
                tf2 = self.determine_format(self.getRawMaxValue(),
                                            settings.timeFormat)
                if self.type != type2 or self.timeFormat != tf2:
                    raise InvalidTimeLayerError(
                        QCoreApplication.translate(
                            'TimeManager',
                            "Invalid time layer: To and From attributes must have "
                            "exact same format"))

            self.offset = int(settings.offset)
            assert (self.timeFormat != time_util.PENDING)
            extents = self.getTimeExtents()
            info("Layer extents" + str(extents))
            if self.resetsss:
                self.setSubsetString(self.originalSubsetString)
        except ValueError as e:
            # ValueErrors appear for virtual layers, see https://github.com/anitagraser/TimeManager/issues/219
            error(traceback.format_exc(e))
            raise InvalidTimeLayerError(
                QCoreApplication.translate(
                    'TimeManager',
                    'This layer type is currently not supported. Cause:{}').
                format(str(e)))
        except Exception as e:
            error(traceback.format_exc(e))
            raise InvalidTimeLayerError(str(e))
Exemple #5
0
 def guessTimePositionInStr(cls, str_with_time):
     try:
         m = re.match(cls.TIME_REGEX, str_with_time)
         return m.start(2), m.end(2)
     except Exception as e:
         info("Could not guess timestamp in raster filename. Cause {}".
              format(e))
         return (0, 0)
    def __init__(self, settings, iface=None):
        TimeLayer.__init__(self, settings.layer, settings.isEnabled)

        try:
            self.layer = settings.layer
            self.iface = iface
            self.minValue, self.maxValue = None, None
            self.fromTimeAttribute = settings.startTimeAttribute
            self.toTimeAttribute = settings.endTimeAttribute if settings.endTimeAttribute != "" \
                else self.fromTimeAttribute
            self.accumulate = settings.accumulate
            self.resetsss = settings.resetSubsetString
            self.originalSubsetString = settings.subsetStr
            self.currSubsetString = self.originalSubsetString
            if self.resetsss:
                self.setSubsetString("")
            else:
                self.setSubsetString(self.originalSubsetString)
            self.geometriesCount = settings.geometriesCount
            self.type = time_util.DateTypes.determine_type(self.getRawMinValue())
            if self.type not in time_util.DateTypes.QDateTypes:
                # call to throw an exception early if no format can be found
                self.findValidValues(self.fromTimeAttribute, settings.timeFormat)
                if self.fromTimeAttribute != self.toTimeAttribute:
                    self.findValidValues(self.toTimeAttribute, settings.timeFormat)

            self.timeFormat = self.determine_format(self.getRawMinValue(), settings.timeFormat)
            if self.toTimeAttribute != self.fromTimeAttribute:
                type2 = time_util.DateTypes.determine_type(self.getRawMaxValue())
                tf2 = self.determine_format(self.getRawMaxValue(), settings.timeFormat)
                if self.type != type2 or self.timeFormat != tf2:
                    raise InvalidTimeLayerError(
                        QCoreApplication.translate(
                            'TimeManager',
                            "Invalid time layer: To and From attributes must have "
                            "exact same format"
                        )
                    )

            self.offset = int(settings.offset)
            assert (self.timeFormat != time_util.PENDING)
            extents = self.getTimeExtents()
            info("Layer extents" + str(extents))
            if self.resetsss:
                self.setSubsetString(self.originalSubsetString)
        except ValueError as e:
            # ValueErrors appear for virtual layers, see https://github.com/anitagraser/TimeManager/issues/219
            error(traceback.format_exc(e))
            raise InvalidTimeLayerError(
                QCoreApplication.translate(
                    'TimeManager',
                    'This layer type is currently not supported. Cause:{}'
                ).format(str(e))
            )
        except Exception as e:
            error(traceback.format_exc(e))
            raise InvalidTimeLayerError(str(e))
 def load(self):
     """Load the plugin"""
     # Order matters!
     self.timeLayerManager = TimeLayerManager(self.iface)
     self.guiControl = TimeManagerGuiControl(self.iface, self.timeLayerManager)
     self.initGuiConnections()
     self.initLayerManagerConnections()
     self.initQGISConnections()
     self.restoreDefaults()
     info("TimeManager: $Id$ loaded!")
Exemple #8
0
 def load(self):
     """Load the plugin"""
     # Order matters!
     self.timeLayerManager = TimeLayerManager(self.iface)
     self.guiControl = TimeManagerGuiControl(self.iface,
                                             self.timeLayerManager)
     self.initGuiConnections()
     self.initLayerManagerConnections()
     self.initQGISConnections()
     self.restoreDefaults()
     info("TimeManager: $Id$ loaded!")
Exemple #9
0
def make_video(out_folder, digits):
    outfile = os.path.join(out_folder, "out.mp4")
    # something like frame%03d.png as expected by ffmpeg
    frame_pattern = os.path.join(
        out_folder, "{}%0{}d.{}".format(FRAME_FILENAME_PREFIX, digits,
                                        FRAME_EXTENSION))
    # TODO: Make this configurable (when understanding how it works)
    video_script = os.path.join(file_dir, "video.sh")
    subprocess.check_call(["sh", video_script, frame_pattern, outfile])
    info("Exported video to {}".format(outfile))
    return outfile
Exemple #10
0
    def __init__(self, settings, iface):
        TimeVectorLayer.__init__(self, settings, iface=iface)
        try:
            info(
                "Trying to create time interpolated layer with interpolation mode: {}"
                .format(settings.interpolationMode))
            try:
                import numpy as np  # NOQA
            except ImportError:
                raise Exception("Need to have numpy installed")

            if not qgs.isPointLayer(self.layer):
                raise Exception("Want point geometry!")

            self.idAttribute = settings.idAttribute
            self.memLayer = self.getMemLayer()

            # adjust memLayer to have same crs and same color as original layer, only half transparent
            self.memLayer.setCrs(self.layer.crs())
            # copy the layer style to memLayer
            renderer = self.layer.renderer()
            r2 = renderer.clone()
            self.memLayer.setRenderer(r2)
            # qgs.setLayerTransparency(self.memLayer, 0.5)
            qgs.refreshSymbols(self.iface, self.memLayer)

            qgs.addLayer(self.memLayer)

            provider = self.getProvider()
            self.fromTimeAttributeIndex = provider.fields().indexFromName(
                self.fromTimeAttribute)
            self.toTimeAttributeIndex = provider.fields().indexFromName(
                self.toTimeAttribute)

            if self.hasIdAttribute():
                self.idAttributeIndex = provider.fields().indexFromName(
                    self.idAttribute)
                self.uniqueIdValues = set(
                    provider.uniqueValues(self.idAttributeIndex))
            else:
                self.uniqueIdValues = set([conf.DEFAULT_ID])

            self.mode = settings.interpolationMode
            self.fromInterpolator = ifactory.get_interpolator_from_text(
                self.mode)
            self.fromInterpolator.load(self)
            self.n = 0
            info("Interpolated layer {} created successfully!".format(
                self.layer.name()))
        except Exception as e:
            raise InvalidTimeLayerError("Traceback:" + traceback.format_exc(e))
 def __init__(self, iface):
     """Initialize the plugin"""
     global control
     try:
         control
     except NameError:
         try:
             overrideLocale = bool(QSettings().value("locale/overrideFlag", False))
             if not overrideLocale:
                 lang = QLocale.system().name().split("_")[0]
             else:
                 lang = QSettings().value("locale/userLocale", "").split("_")[0]
         except Exception:
             lang = "en"  # could not get locale, OSX may have this bug
         info("Plugin language loaded: {}".format(lang))
         self.changeI18n(lang)
         control = TimeManagerControl(iface)
Exemple #12
0
 def __init__(self, iface):
     """Initialize the plugin"""
     global control
     try:
         control
     except NameError:
         try:
             overrideLocale = bool(QSettings().value(
                 "locale/overrideFlag", False))
             if not overrideLocale:
                 lang = QLocale.system().name().split("_")[0]
             else:
                 lang = QSettings().value("locale/userLocale",
                                          "").split("_")[0]
         except Exception:
             lang = "en"  # could not get locale, OSX may have this bug
         info("Plugin language loaded: {}".format(lang))
         self.changeI18n(lang)
         control = TimeManagerControl(iface)
    def __init__(self, settings, iface=None):
        TimeLayer.__init__(self, settings.layer, settings.isEnabled)

        self.layer = settings.layer
        self.iface = iface
        self.minValue, self.maxValue = None, None
        self.fromTimeAttribute = settings.startTimeAttribute
        self.toTimeAttribute = settings.endTimeAttribute if settings.endTimeAttribute != "" \
            else self.fromTimeAttribute
        self.accumulate = settings.accumulate
        self.resetsss = settings.resetSubsetString
        self.originalSubsetString = settings.subsetStr
        self.currSubsetString = self.originalSubsetString
        if self.resetsss:
            self.setSubsetString("")
        else:
            self.setSubsetString(self.originalSubsetString)
        self.geometriesCount = settings.geometriesCount

        if self.layer.dataProvider().storageType() == 'Memory storage':
            self.raiseInvalidLayerError("Invalid time layer: Memory layers are not supported")

        raw_min_value = self.getRawMinValue()
        info("Raw min value: {}".format(raw_min_value))
        self.timestamp_type = time_util.DateTypes.determine_type(raw_min_value)
        info("Time stamp type: {}".format(self.timestamp_type))

        try:
            if self.timestamp_type not in time_util.DateTypes.QDateTypes:
                # call to throw an exception early if no format can be found
                self.findValidValues(self.fromTimeAttribute, settings.timeFormat)
                if self.fromTimeAttribute != self.toTimeAttribute:
                    self.findValidValues(self.toTimeAttribute, settings.timeFormat)

            self.timeFormat = self.determine_format(self.getFromValue(), settings.timeFormat)
            info("Time format: {}".format(self.timeFormat))

            if self.toTimeAttribute != self.fromTimeAttribute:
                type2 = time_util.DateTypes.determine_type(self.getRawMaxValue())
                tf2 = self.determine_format(self.getToValue(), settings.timeFormat)
                if self.timestamp_type != type2 or self.timeFormat != tf2:
                    self.raiseInvalidLayerError("Invalid time layer: To and From attributes must have exact same format")

            self.offset = int(settings.offset)
            assert (self.timeFormat != time_util.PENDING)
            extents = self.getTimeExtents()
            info("Layer extents" + str(extents))
            if self.resetsss:
                self.setSubsetString(self.originalSubsetString)

        except Exception as e:
            error(e)
            raise InvalidTimeLayerError(str(e))