Geospatial analysis is all about making sense of data based on places and locations. In this post, we’re focusing on how to use a tool called QGIS to merge polygons. This means taking smaller bits of a map, like specific postcodes, and combining them into bigger areas. This method helps us see the big picture, like how sales trends work across different regions. Using QGIS for merging polygons simplifies the data, making it easier to understand and use for our analysis.
Understanding spatial data and geographic trends is crucial in various fields, from urban planning to market analysis. Geographic analysis allows us to visualize complex data, identify patterns, and make informed decisions. In this context, tools like QGIS become indispensable for handling and interpreting spatial data effectively.
Today, we will reshape and merge the 4 digit postal code polygons of Switzerland. Often the detailed postal code level has too many polygons and maps in Power BI struggle with the number of polygons. Plus, it can make the analysis and your report very slow!
Geographic Information Systems (GIS) are powerful tools for visualizing and analyzing spatial data, extending far beyond simple map creation. GIS integrates location data with descriptive information, offering a foundation for detailed mapping and analysis used in various industries. This technology helps in understanding complex patterns, relationships, and geographic contexts, enhancing decision-making and communication.
Specifically, polygons in GIS play a crucial role. They represent areas like cities, lakes, or postcodes on maps. The process of merging polygons in QGIS, a popular GIS software, is particularly beneficial. It simplifies detailed data, such as postcodes, into broader, more manageable regions for analysis. This technique is vital for gaining a more strategic overview of spatial trends and patterns, making drawing meaningful conclusions from the data easier. For a deeper understanding of GIS, you can explore more at Esri’s GIS Overview.
Polygons are key features in GIS, representing various boundaries on maps, like postal codes or city limits. They are formed by connecting multiple points, each defined by latitude and longitude coordinates, creating a defined area on a map. For example, to depict a neighborhood, points around its perimeter are identified and connected in sequence.
Polygons in GIS are defined by a series of latitude and longitude coordinates that outline a specific area. For instance, a polygon representing a small park might be coded as follows:
"geometry": {
"type": "Polygon",
"coordinates": [
[
[longitude1, latitude1], // Point 1
[longitude2, latitude2], // Point 2
[longitude3, latitude3], // Point 3
[longitude4, latitude4], // Point 4
[longitude1, latitude1] // Back to Point 1
]
]
}
Each pair of longitude and latitude values represents a corner of the polygon. In this example, the polygon is closed by returning to the first point. For a more detailed explanation and examples, you can visit Spotzi’s description of polygons. Now that you understand the most important concepts, let’s merge Polygons in QGIS!
Head over to the official QGIS website and download QGIS Desktop version. Simply follow the installation procedure. The use of the tool is free!
Now its time to connect your GeoJson file. You can also use shape files as well!
Now you can see a beautiful map of the 4-digit postal codes of Switzerland:
The Attribute Table in QGIS displays data associated with each feature in a layer. It’s organized in a spreadsheet-like format, with rows representing individual features (like polygons) and columns displaying different attributes (like names, area sizes, or specific codes). You can view and edit the data, perform queries to select features or create new attributes. It’s a crucial tool for managing and understanding the data within your map layers, allowing you to look deeper into the specifics of each feature you’re working within QGIS.
Now you can see the table and its columns: As you can see we have information about id, object ID, PLZ4 (which is our 4-digit postal code), the name of the city, the language they speak in this area and the shape length. For us, the most important feature is the PLZ4 column. Based on that we will later merge Polygons in QGIS.
Now we have a new column with Postalcode Area. Based on that we can merge all polygons with the same 2-digit number!
Now, we don’t want to manually go over each polygon and select the matching polygons of one postcode area. What is the smartest way to select all polygons starting with “10” in the postcode area? The solution: We are going to make use of the “Select Features using an expression” functionality
Now only Postal Codes starting with “10” are selected!
Now all polygons starting with 10 are merged in QGIS:
In step number 6 we created a new layer which you can see on the left side of the QGIS desktop application. The standard name will simply be “Dissolved”. But if we are merging all the postal codes of Switzerland we will almost end up with around 100 polygons. That is why it is important to rename the newly created layer, to make it less confusing!
Every time we merge polygons together, we will create a new layer. Simply follow step 6 as often as you need to create the desired polygons. In the end, for Switzerland we will have around 100 layers. For demonstration purposes, I show you here how to combine two polygons. In this example, I will merge the postal code areas 10 and 11. Now you also understand why the naming is important, as we only want to combine 2 specific polygons. Without naming it would be hard to identify them in a batch of dozens of polygons!
In the last step, we want to safe our newly generated map to a GeoJson file:
In conclusion, merging polygons in QGIS is a powerful method for simplifying and analyzing geographic data. We’ve walked through the process using Switzerland’s postal codes as an example. This technique, particularly useful for large datasets that can slow down analysis in tools like Power BI, allows for a more efficient and strategic overview of spatial data. By understanding GIS and the role of polygons, and following the detailed steps from connecting GeoJson files to saving the final GeoJson output, users can effectively manage and interpret spatial data, enhancing their geospatial analysis capabilities.
If you want to see how to integrate GeoJson files in Power BI, I highly recommend to read my article “How to Create a Dynamic Territory Report in Power BI for Germany”
If you like this post or have a question, simply leave a comment below. Thanks!
👇
.
.
.
.