A Guide for Developers Traveling Through OpenLayers - 4. Trying Out QGIS
A Guide for Developers Traveling Through OpenLayers - 4. Trying Out QGIS
I mentioned earlier that most geospatial data is provided in SHP by default. The trouble is, I have no idea how to open this SHP thing. Text-based data like GeoJSON or CSV can at least be opened and inspected somehow, but that's not possible with SHP.
That's why we need some kind of tool that can open and manipulate SHP—fortunately several already exist, so it's not a big problem. There are two especially representative tools.
- ArcGIS: A commercial program developed by ESRI with powerful performance. It commands an overwhelming share of the GIS industry, but it's expensive.
- QGIS: An open-source program. Free, but a bit sluggish when handling large volumes of data.
Unless you're doing tile map production or handling extremely large-scale data, QGIS can cover most needs just fine. It has great compatibility with Python, which means you can use a variety of Python-based plugins. If you have some skill with Python, you can even write your own scripts to perform complex operations. But if you're doing that level of work in QGIS, you're closer to a data-focused role than a developer.
Trying to work with OpenLayers without a sufficient understanding of geospatial data will only add to the confusion. That's why, before explaining OpenLayers, we'll first cover how to work with SHP through QGIS.
You can download QGIS from the official website.
Launch QGIS and try dragging in an SHP file. If it's a valid geospatial file, the related data will display in the window.
The data above is building data for Sejong City provided via road-name addresses. Even someone doing this for the first time can at least tell that some valid data got rendered.
Buildings take the form of polygons. Each shape represents a building.
Knowing that the data appeared is one thing, but it's very hard to tell exactly where in the real world those buildings actually are. In other words, it's much more convenient to overlay a complete map you can use for comparison alongside it.
QGIS provides an Open Street Map (hereafter OSM) layer by default.
OSM is a world map maintained autonomously by mapping contributors around the globe. Since each country's map is contributed to by that country's own developers, it's both well-localized and well-globalized, making it handy to use right away. That said, it isn't as specialized for Korea as Naver Map or Kakao Map, so it's a bit lacking for services meant specifically for domestic use.
Of course, that's only a concern when it comes to actually running a service—for simply comparing data against real locations right now, nothing beats it.
In the left sidebar, double-click [XYZ Tiles - OpenStreetMap] to add it as a layer.
Since the display priority depends on layer order, try to keep Open Street Map at the very bottom.
Placing the most basic map at the bottom ensures it doesn't cover up other elements.
This makes comparison much easier. Looking at the data, you can confirm that it lines up roughly with the terrain of Sejong City.
You can click on the data to check its information. Click the [Identify Features (Ctrl + Shift + I)] button in the top menu, then click on an object to view its information.
Right-click a layer to see the available menu. Clicking [Open Attribute Table] lets you view the attributes of all the data. It's very similar in form to a DB.
You can search for data, display selected data on the map, and of course also edit or delete data.
QGIS checks the coordinate system of each layer and converts it to the project's primary coordinate system when displaying it in QGIS.
For example, let's say the following:
- Primary coordinate system: EPSG:4326
- Layer A coordinate system: EPSG:5179
- Layer B coordinate system: EPSG:3857
Since the primary coordinate system is EPSG:4326, layers A and B get converted to EPSG:4326 and displayed in QGIS accordingly. Ultimately, the user sees a map expressed in EPSG:4326.
You can set the primary coordinate system in the bottom-right corner of QGIS. Find and specify the desired EPSG code, and the data will automatically be converted to and displayed in that coordinate system.
Each layer's coordinate system can be converted through the corresponding menu. Make sure to always specify the coordinate system that actually matches that layer.
For example, if a layer defined in the EPSG:5181 coordinate system is mistakenly specified as EPSG:4326, it'll be calculated to an entirely wrong location.
To put it simply, it's the same as a translator recognizing Italian as English and translating it that way. Since it translates something that isn't English as if it were English, the resulting words come out completely meaningless. Likewise, if you specify the wrong coordinate system for a layer, it gets converted to an entirely wrong location, so be careful. If this happens, double-check the layer's coordinate system.
If you've changed the data content or coordinate system in QGIS, you can export this data as SHP or an equivalent geospatial data format for use.
Click [Export - Save Features As] to bring up the save menu.
Enter your desired data format and settings, and the data will be saved.
※ Thanks to everyone who kindly corrected mistakes in this article.
