Estilización de una red fluvial con expresiones (QGIS3)

Contribución de: Steven Kim

En el tutorial anterior Crear un mapa del mundo en bloques (QGIS3) utilizamos expresiones para escalar valores y aplicar una rampa de color. Nos basamos en esos conceptos y aprender a utilizar expresiones para visualizar los ríos en un estilo popular.

Nota

Este tutorial se centra en el uso de expresiones para estilizar. Puede consultar nuestro otro tutorial Creación de un mapa de cuenca fluvial coloreado (QGIS3) que crea una versión diferente del mapa mostrado aquí utilizando un flujo de trabajo basado en herramientas.

Visión general de la tarea

Utilizaremos expresiones para filtrar y estilizar los ríos sudamericanos, con líneas que representen la superficie de las tierras altas y colores que representen la identificación de la cuenca a partir de HydroRIVERS.

../../_images/output4.png

Obtener los datos

El conjunto de datos HydroRIVERS ofrece una cobertura mundial sin fisuras de tramos fluviales de tamaño coherente, apoyada por información geométrica que permite realizar análisis básicos de la topología de las redes fluviales, como la conectividad y las distancias de los arroyos. Los datos son un subconjunto del completo paquete HydroATLAS de WWF. Descarguemos el archivo shape de los ríos de Sudamérica.

  1. Visit the HydroRIVERS homepage.

../../_images/data126.png
  1. The page has links for global and regional extracts of HydroRIVERS in shapefile and geodatabase formats. Scroll down and click on the download link for the South America shapefile. You will see the HydroRIVERS_v10_sa_shp.zip file downloaded which is used for this tutorial.

../../_images/data28.png

For convenience, you may directly download a copy of the above layer from below: HydroRIVERS_v10_sa_shp.zip

Data Source: [HYDROSHEDS]

Procedure

  1. Locate the HydroRIVERS_v10_sa_shp.zip file in the QGIS Browser and expand it. Select the HydroRIVERS_v10_sa_shp/HydroRIVERS_v10_sa.shp file and drag it to the canvas.

../../_images/1152.png
  1. A new layer HydroRIVERS_v10_sa will now be loaded in QGIS and you should see a map of rivers in South America. Click on Open Layer Styling Panel.

../../_images/2128.png
  1. Switch from Single Symbol to Rule-based.

../../_images/366.png
  1. Double-click on the default rule to enter the Edit Rule dialog.

../../_images/437.png
  1. To filter using an expression, click the Filter ε. This will open the Expression Builder.

../../_images/533.png
  1. Select the Expression box on the left to input the expression as follows and click OK. This expression selects river features with an upland area equal to or greater than 100 square km.

"UPLAND_SKM" >= 100
../../_images/632.png
  1. The map now shows the filtered rivers with large upland areas. You can adjust this threshold based on the scale of your region.

../../_images/732.png
  1. Now that we have used an expression to filter features, let us use an expression to color each river segment based on the field MAIN_RIV. Scroll-down to the Symbol options in the styling panel and select Simple Line to bring up styling options such as color, stroke width and more. Click on Data define override button for the Color and select Edit… on the menu.

../../_images/831.png
  1. This brings up the Expression Builder dialog for color. Enter the expression below. This expression combines the functions ramp_color() and scale_linear() to select colors from the spectral color ramp using the range of MAIN_RIV id values. Click OK to exit the dialog.

ramp_color('Spectral',scale_linear("MAIN_RIV",
minimum("MAIN_RIV"),maximum("MAIN_RIV"),0,1))
../../_images/932.png
  1. At the Edit Rule dialog, click on Data define override button for Stroke width and select Edit… on the menu. Enter the following expression. The expression scales line width based on the upland area of each river segment, with a minimum of 0.01 mm to a maximum of 0.1 mm for rivers with an upland area equal to or larger than 10,000 sqkm.

scale_linear("UPLAND_SKM",100,10000,0.01,0.1)
../../_images/1038.png
  1. Click OK to exit the dialog. The river lines will now be rendered in different widths based on their upland area. The expression needs to be evaluated for each feature and thus the rendering may take some time.

../../_images/1153.png
  1. Let’s change the background color to black to contrast with our color choices. Navigate to Project ‣ Properties ‣ General. Click on the down arrow and select black. Click OK.

../../_images/1241.png
  1. You should now see the completed river network of South America.

../../_images/1339.png

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)