[Qgis-user] Accessing temporal controller stuff via the python console

Cory Albrecht maps at hanfastolfe.com
Mon Jan 24 10:36:25 PST 2022


So I am using the following python scriptlet that I paste into the QGIS
python console:


listOfDates = [ "1815-06-09",
"1816-12-11",
"1817-12-10",
…
"1911-09-30" ]


navigator = iface.mapCanvas().temporalController()


i = 1
for d in listOfDates:
  print(d)
  dt = QDateTime.fromString(d, 'yyyy-MM-dd')
  f = navigator.findBestFrameNumberForFrameStart(dt)
  print(f)
  fn = '/home/cory/Downloads/image-{:06d}.png'.format(i)
  print(fn)
  navigator.setCurrentFrameNumber(f)
  iface.mapCanvas().saveAsImage(fn)
  print("\n")
  i = i + 1


print('Done!')


I get the expected output:

1815-06-09
54003
/home/cory/Downloads/image-000001.png



1816-12-11
54554
/home/cory/Downloads/image-000002.png



1817-12-10
54918
/home/cory/Downloads/image-000003.png


But the `navigator.setCurrentFrameNumber(f)` doesn't change the canvas'
temporal frame.

If I do `f=54003` manually in the console and then
`navigator.setCurrentFrameNumber(f)` manually as well, the frame changes.
I've used time.sleep() with values up to 5 seconds to see if setting the
frame was just a background task that returns early before actually
completed, but that didn;t make any difference.

Why does it not change the frame in the middle of the for loop?

On Tue, Jan 18, 2022 at 2:32 PM Cory Albrecht <maps at hanfastolfe.com> wrote:

> Thanks, I'll check it out.
>
> On Sun, Jan 16, 2022 at 8:04 PM Nyall Dawson <nyall.dawson at gmail.com>
> wrote:
>
>> On Mon, 17 Jan 2022 at 10:46, Cory Albrecht <maps at hanfastolfe.com> wrote:
>> >
>> > Thanks for the pointer, but unfortunately it is incomplete. It tells me
>> this:
>> >
>> >     # get the current  responsible for the mapCanvas behaviour and
>> Temporal Controller gui
>> >     navigator = iface.mapCanvas().temporalController()
>> >
>> > And a few other methods for that object, but it's all about mimicking
>> the "Save Animation" button with no explanation how to choose a specific
>> frame or even anything as simple as going forward or backward by a single
>> frame. Is there no list anywhere of all that temporal controller object's
>> methods?
>>
>> Yes, in the usual place (the PyQGIS API reference):
>>
>>  https://qgis.org/pyqgis/master/core/QgsTemporalNavigationObject.html
>>
>> Nyall
>>
>> >
>> >
>> >
>> > On Sun, Jan 16, 2022 at 3:40 PM Delaz J <delazj at gmail.com> wrote:
>> >>
>> >> Hi Cory,
>> >>
>> >> I don't know if it's still compatible with API and of any help, but
>> there's that stale pull request in the docs by Richard (
>> https://github.com/qgis/QGIS-Documentation/pull/5521) you might want to
>> look at.
>> >>
>> >> Regards,
>> >>
>> >> Harrissou
>> >>
>> >> Le 16/01/2022 à 18:34, Cory Albrecht a écrit :
>> >>
>> >> Hello,
>> >>
>> >> Is there a way I can access and change/set stuff for the dynamic
>> temporal controller programmatically in python? I'm looking to make a
>> simple script that I can just cut and paste into the python console that
>> will change the current frame of the DTC to a given timestamp, export the
>> canvas to a PNG, and repeat for all the timestamps in an array.
>> >>
>> >> _______________________________________________
>> >> Qgis-user mailing list
>> >> Qgis-user at lists.osgeo.org
>> >> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> >> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> >
>> > _______________________________________________
>> > Qgis-user mailing list
>> > Qgis-user at lists.osgeo.org
>> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220124/b4d44516/attachment.html>


More information about the Qgis-user mailing list