In this task, we will use python scripting for converting a Comma-Separated Values file (also known as CSV file) to a shapefile using PyQGIS. We will use a sample dataset available from SpatialKey, which contains: 36634 records in Florida for 2012 from a sample company that implemented an aggressive growth plan in 2012. We will only use […]Read more "How to convert a CSV file to a shapefile in QGIS using Python"
This task is based on my answer to this question from gis.stackexchange.com. Sometimes it happens that, when importing external files in QGIS (typically .CSV files), the fields specifying the longitude and latitude coordinates are accidentally inverted: this behavior will produce a different result in respect of the desired output. If we don’t want to repeat the same procedure, we may run a […]Read more "How to invert lon/lat coordinates in QGIS using Python"
This task is based on my answer to this question poped up on gis.stackexchange.com. We start from one point vector layer and one line vector layer: the goal for this task is to literally “snap” the line vector layer to the nearest points on the basis of a searching distance (i.e. we want to snap the line to the points which are […]Read more "How to snap lines to points in QGIS using Python"
In this task we will use python scripting to count the number of duplicate geometries from a point vector layer and store the result in a memory layer. Starting, from something like this (overlapping points are not visible!): we will see how it’s easy (and fast) to do the task using a QgsSpatialIndex. The first […]Read more "How to count duplicate points in QGIS using Python"
In this task we will use python scripting to count the number of points which lie inside a polygon and store the result in a memory layer. The Processing algorithm Count points in polygon does the same thing, but we want to do the task without using it. We will use two datasets available from Natural Earth: the first one […]Read more "How to count points in polygons in QGIS using Python"
In this task we will use python scripting to buffer the features of a vector layer (using a buffer distance stored in a field) and save it as a memory layer. The Processing algorithm Variable distance buffer does the same thing, but we want to do it using Python. We can use the following code (if you don’t […]Read more "How to buffer vectors (from fields) in QGIS using Python"
In this task we will see how to get the attributes of a vector layer and export them in a text file. Furthermore, at the end of the task we will order these attributes alphabetically before writing them in the output file. As a sample, we will use the vector layer that we have filtered in […]Read more "How to export attributes from QGIS to a .txt file using Python"