Blog d’Anita Graser

https://anitagraser.com

  • PyQGIS101 part 10 published! 5 janvier 2019
    PyQGIS 101: Introduction to QGIS Python programming for non-programmers has now reached the part 10 milestone! Beyond the obligatory Hello world! example, the contents so far include: Loading a vector layer Viewing vector layer attributes Filtering features Styling vector layers Loading a raster layer Running Processing tools Exporting layouts Creating & editing a new vector layer Chaining Processing tools If you’ve been thinking about learning Python programming, but never got around to actually start doing it, give PyQGIS101 a try. I’d like to thank everyone who has already provided feedback to the exercises. Every comment is important to help me understand the pain points of learning Python for QGIS. I recently read an article – unfortunately I forgot to bookmark it and cannot locate it anymore – that described the problems with learning to program very well: in the beginning, it’s rather slow going, you don’t know the right terminology and therefore don’t know what to google for when you run into issues. But there comes this point, when you finally get it, when the terminology becomes clearer, when you start thinking “that might work” and it actually does! I hope that PyQGIS101 …
  • Movement data in GIS #18: creating evaluation data for trajectory predictions 15 décembre 2018
    We’ve seen a lot of explorative movement data analysis in the Movement data in GIS series so far. Beyond exploration, predictive analysis is another major topic in movement data analysis. One of the most obvious movement prediction use cases is trajectory prediction, i.e. trying to predict where a moving object will be in the future. The two main categories of trajectory prediction methods I see are those that try to predict the actual path that a moving object will take versus those that only try to predict the next destination. Today, I want to focus on prediction methods that predict the path that a moving object is going to take. There are many different approaches from simple linear prediction to very sophisticated application-dependent methods. Regardless of the prediction method though, there is the question of how to evaluate the prediction results when these methods are applied to real-life data. As long as we work with nice, densely, and regularly updated movement data, extracting evaluation samples is rather straightforward. To predict future movement, we need some information about past movement. Based on that past movement, we can then try to predict future positions. …
  • Movement data in GIS #17: spatial analysis of GeoPandas trajectories 2 décembre 2018
    In Movement data in GIS #16, I presented a new way to deal with trajectory data using GeoPandas and how to load the trajectory GeoDataframes as a QGIS layer. Following up on this initial experiment, I’ve now implemented a first version of an algorithm that performs a spatial analysis on my GeoPandas trajectories. The first spatial analysis algorithm I’ve implemented is Clip trajectories by extent. Implementing this algorithm revealed a couple of pitfalls: To achieve correct results, we need to compute spatial intersections between linear trajectory segments and the extent. Therefore, we need to convert our point GeoDataframe to a line GeoDataframe. Based on the spatial intersection, we need to take care of computing the corresponding timestamps of the events when trajectories enter or leave the extent. A trajectory can intersect the extent multiple times. Therefore, we cannot simply use the global minimum and maximum timestamp of intersecting segments. GeoPandas provides spatial intersection functionality but if the trajectory contains consecutive rows without location change, these will result in zero length lines and those cause an empty intersection result. So far, the clip resu …
  • TimeManager 3.0.2 released! 29 novembre 2018

    Bugfix release 3.0.2 fixes an issue where “accumulate features” was broken for timestamps with milliseconds.

    If you like TimeManager, know your way around setting up Travis for testing QGIS plugins, and want to help improve TimeManager stability, please get in touch!

  • Movement data in GIS #16: towards pure Python trajectories using GeoPandas 18 novembre 2018
    Many of my previous posts in this series [1][2][3] have relied on PostGIS for trajectory data handling. While I love PostGIS, it feels like overkill to require a database to analyze smaller movement datasets. Wouldn’t it be great to have a pure Python solution? If we look into moving object data literature, beyond the “trajectories are points with timestamps” perspective, which is common in GIS, we also encounter the “trajectories are time series with coordinates” perspective. I don’t know about you, but if I hear “time series” and Python, I think Pandas! In the Python Data Science Handbook, Jake VanderPlas writes: Pandas was developed in the context of financial modeling, so as you might expect, it contains a fairly extensive set of tools for working with dates, times, and time-indexed data. Of course, time series are one thing, but spatial data handling is another. Lucky for us, this is where GeoPandas comes in. GeoPandas has been around for a while and version 0.4 has been released in June 2018. So far, I haven’t found examples that use GeoPandas to manage movement data, so I’ve set out to give it a shot. My trajectory class uses a GeoDataFrame df for data storage. For visualiza …
  • My favorite new recipe in QGIS Map Design 2nd ed 10 novembre 2018
    If you follow me on Twitter, you have probably already heard that the ebook of “QGIS Map Design 2nd Edition” has now been published and we are expecting the print version to be up for sale later this month. Gretchen Peterson and I – together with our editor Gary Sherman (yes, that Gary Sherman!) – have been working hard to provide you with tons of new and improved map design workflows and many many completely new maps. By Gretchen’s count, this edition contains 23 new maps, so it’s very hard to pick a favorite! Like the 1st edition, we provide increasingly advanced recipes in three chapters, each focusing on either layer styling, labeling, or creating print layouts. If I had to pick a favorite, I’d have to go with “Mastering Rotated Maps”, one of the advanced recipes in the print layouts chapter. It looks deceptively simple but it combines a variety of great QGIS features and clever ideas to design a map that provides information on multiple levels of detail. Besides the name inspiring rotated map items, this design combines map overviews map themes graduated lines and polygons a rotated north arrow fancy leader lines all in one: “QGIS Map Design 2nd Edition” provides how-to instru …
  • Geocoding with Geopy 11 septembre 2018

    Need to geocode some addresses? Here’s a five-lines-of-code solution based on “An A-Z of useful Python tricks” by Peter Gleeson:

    from geopy import GoogleV3
    place = "Krems an der Donau"
    location = GoogleV3().geocode(place)
    print(location.address)
    print("POINT({},{})".format(location.latitude,location.longitude))
    

    For more info, check out geopy:

    geopy is a Python 2 and 3 client for several popular geocoding web services.
    geopy includes geocoder classes for the OpenStreetMap Nominatim, ESRI ArcGIS, Google Geocoding API (V3), Baidu Maps, Bing Maps API, Yandex, IGN France, GeoNames, Pelias, geocode.earth, OpenMapQuest, PickPoint, What3Words, OpenCage, SmartyStreets, GeocodeFarm, and Here geocoder services.

  • Plotting GPS Trajectories with error ellipses using Time Manager 4 septembre 2018
    This is a guest post by Time Manager collaborator and Python expert, Ariadni-Karolina Alexiou. Today we’re going to look at how to visualize the error bounds of a GPS trace in time. The goal is to do an in-depth visual exploration using QGIS and Time Manager in order to learn more about the data we have. The Data We have a file that contains GPS locations of an object in time, which has been created by a GPS tracker. The tracker also keeps track of the error covariance matrix for each point in time, that is, what confidence it has in the measurements it gives. Here is what the file looks like: Error Covariance Matrix What are those sd* fields? According to the manual: The estimated standard deviations of the solution assuming a priori error model and error parameters by the positioning options. What it basically means is that the real GPS location will be located no further than three standard deviations across north and east from the measured location, most of (99.7%) the time. A way to represent this visually is to create an ellipse that maps this area of where the real location can be. An ellipse can be uniquely defined from the lengths of the segments a and b and its rotation a …
  • Movement data in GIS #15: writing a PL/pgSQL stop detection function for PostGIS trajectories 19 juillet 2018
    Do you sometimes start writing an SQL query and around at line 50 you get the feeling that it might be getting out of hand? If so, it might be useful to start breaking it down into smaller chunks and wrap those up into custom functions. Never done that? Don’t despair! There’s an excellent PL/pgSQL tutorial on postgresqltutorial.com to get you started. To get an idea of the basic structure of a PL/pgSQL function and to proof that PostGIS datatypes work just fine in this context, here’s a basic function that takes a trajectory geometry and outputs its duration, i.e. the difference between its last and first timestamp: CREATE OR REPLACE FUNCTION AG_Duration(traj geometry) RETURNS numeric LANGUAGE ‘plpgsql’ AS $BODY$ BEGIN RETURN ST_M(ST_EndPoint(traj))-ST_M(ST_StartPoint(traj)); END; $BODY$; My end goal for this exercise was to implement a function that takes a trajectory and outputs the stops along this trajectory. Commonly, a stop is defined as a long stay within an area with a small radius. This leads us to the following definition: CREATE OR REPLACE FUNCTION AG_DetectStops( traj geometry, max_size numeric, min_duration numeric) RETURNS TABLE(sequence integer, geom geometry) — imp …
  • Movement data in GIS #14: updates from GI_Forum 2018 9 juillet 2018
    Last week, I traveled to Salzburg to attend the 30th AGIT conference and co-located English-speaking GI_Forum. Like in previous year, there were a lot of mobility and transportation research related presentations. Here are my personal highlights: This year’s keynotes touched on a wide range of issues, from Sandeep Singhal (Google Cloud Storage) who – when I asked about the big table queries he showed – stated that they are not using a spatial index but are rather brute-forcing their way through massive data sets, to Laxmi Ramasubramanian @nycplanner (Hunter College City University of New York) who cautioned against tech arrogance and tendency to ignore expertise from other fields such as urban planning: Next up: Sandeep Singhal Director, @Google Cloud Storage #GIForum2018 pic.twitter.com/fiRL9TUNpr — Anita Graser (@underdarkGIS) July 4, 2018 https://platform.twitter.com/widgets.js One issue that Laxmi particularly highlighted was the fact that many local communities are fighting excessive traffic caused by apps like Waze that suggest shortcuts through residential neighborhoods. Just because we can do something with (mobility) data, doesn’t necessarily mean that we should! L. Ramasu …