Using the QMetaTiles plugin in Qgis to download XYZ tiles offline

Table of contents

foreword

1. Qgis plugin library

1. Introduction to plug-in library

2. Introduction to QMetaTiles

Two, QMetaTiles plug-in installation

1. Online installation

2. Offline installation

 3. Tile download

1. Open the QmeaTiles plugin

2. Leaflet loads the downloaded tiles

 Summarize


foreword

        Electronic maps are the cornerstone of map applications and serve as the basis of the entire system. Other layer elements are built on top of the basemap, whether it is Google, Gaode or Baidu, their basemaps are composed of tiles one by one. It is organized as the following, and the relevant knowledge about tiles will not be repeated here. You can refer to this blog, Practical operation of Qgis loading online XYZ tile image service . In Internet mode, the way of loading tiles has been briefly introduced.

        In many cases, our application system needs to be accessed in an offline environment, such as an intranet environment. And in order to access these offline tiles in the intranet, what method needs to be used to publish them? If you also encounter this kind of problem during your usual work and study, you may wish to learn how to use the QMetaTiles plug-in to download tiles in Qgis. This article will briefly introduce the QMetaTiles plug-in, and use the QMetaTiles plug-in to offline tiles, publish the downloaded tiles in nginx, and finally use Leaflet to load the downloaded offline tiles.

1. Qgis plugin library

1. Introduction to plug-in library

        In addition to the rich software functions of Qgis itself, the plug-in, as the extended ecology of Qgis, greatly enriches and expands the functions of Qgis, adding bricks and tiles to it, and at the same time it is convenient for everyone to use Qgis software better. The address of the plug-in library is: qgis plug-in library .

         It can be seen that the plug-in library of Qgis is still very rich, and you can download the corresponding plug-ins as needed to make your work even more powerful.

2. Introduction to QMetaTiles

        Generates MetaTiles for export to the LatLonGO mobile solution.Generate tiles (using metatiling) from your QGIS project. Provides a QGIS export for LatLonGO. Can save metatile files in MapBox and Zip formats. Based on QTiles plugin.

        The above is the relevant introduction about QMetaTiles on the official website. It can be seen that the tile download function can be completed by using the QMetaTiles plug-in. Its development author is wedoit, and the developer's team is we-do-it Development Team. The details are shown in the table below:

serial number name illustrate
1 Author we-do-IT Development Team
2 Maintainer wedoit
3 Tags raster , tiles , mbtiles , zip , mapbox , latlongo
4

Plugin home page

Bitbucket
5

Tracker

Browse and report bugs
6

Latest stable version

1.5
7 Latest experimental vesion 1.0

        Of course, as a Qgis plug-in, there is a corresponding relationship between the version of QMetaTiles and the version of Qgis. This is also a problem of software version adaptation. When you use the software, you must pay attention to the software version. Otherwise, it is very likely that an error will be reported, or even the software will not be available. Let's take a look at the version correspondence between QMetaTiles and Qgis. With the version correspondence, you have more choices when choosing a version.

Two, QMetaTiles plug-in installation

1. Online installation

        Open the Qgis software, click the plug-in button in the upper menu bar, and open the pop-up window of the plug-in, as shown in the figure below:

         Search for the desired plug-in in the search bar and follow the prompts to install it. Opening the plug-in library in Qgis is very slow on my computer due to network reasons, so we changed to another installation mode, offline installation. The offline installation mode, as the name implies, is to install plug-ins without a network. So first we need to download the plug-in locally.

2. Offline installation

        On the plugin download page of QMetaTiles, click the download button to jump to the corresponding download window. Then download the plug-in locally and wait for installation.

         The downloaded plug-in compressed package is shown in the figure below:

         In Qgis, use the zip offline installation method to install the plug-in, the details are shown in the figure below:

         After the completion, click Install Plug-in, and close the window after the installation is successful. After the installation is successful, you can see the menu entry of the QMetaTiles plugin in the menu bar.

 3. Tile download

        Here we will use the QMetaTiles plug-in to download the marked tiles of the star map earth. This example is for reference. In the actual production environment, the use of the map needs to be cautious and approved by a qualified unit.

1. Open the QmeaTiles plugin

        In the plug-in menu above Qgis, select QMetaTiles, click to enter the main program page, the details are shown in the figure below:

         Instructions for setting key parameters when downloading tiles:

1 parameter illustrate
2 File Generate compressed files, support zip or rar
3 Directory file directory generation
4 tileset name The tile set name, which is equivalent to the folder name
5 extent Download four tiles, generally download all by default
6 minzoom Minimum download level
7 maxzoom maximum download level
8 tile width tile width
8 tile height tile height
10 format tile format

        Friends who are interested in other parameters can conduct different tests in Qgis. In order to reduce data display here, only download 3-

Level 4 tiles (almost none if the label layer is too small). After the parameters are set, click the Ok button to download the tiles.

         After clicking Finish, you can see that there is already corresponding tile data in the folder.

         There will be some black tiles, because there is no data under the current level (you can ignore it temporarily).

2. Leaflet loads the downloaded tiles

Regarding how to display tile information in Leaflet, I won’t go into details here, and post the specific code here for your reference.

<!DOCTYPE html>
<html>
<head>
  <title>Leaflet 本地瓦块Preview</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
   integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
   crossorigin=""/>
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"
   integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
   crossorigin=""></script>
  <style type="text/css">
    body {
       margin: 0;
       padding: 0;
    }
    html, body, #map{
       width: 100%;
       height: 100%;
    }
  </style>
</head>
<body>
  <div id="map"></div>
  <script>
      var map = L.map('map').setView([1.4210854715202004e-14, 8.526512829121202e-14], 3.5);
      L.tileLayer('file:///D%3A/wzh_test/qmetatiles0617/img/{z}/{x}/{y}.png', {
        minZoom: 3,
        maxZoom: 4,
        tms: false,
        attribution: '加载xyz瓦片'
      }).addTo(map);
  </script>
</body>
</html>

        Please note: The js and css of Leaflet here adopt the online method. In the offline environment, the leaflet can be downloaded to the local, and the code is the same. For the sake of simplicity, the layer loading service here uses the file protocol instead of the common http protocol (the service form after putting the tiles into server middleware such as nginx or apache), and it can be used in this way during testing . The final effect is shown in the figure below:

 Summarize

        The above is the main content of this article. This article will briefly introduce the QMetaTiles plug-in, and use the QMetaTiles plug-in to offline tiles, publish the downloaded tiles in nginx, and finally use Leaflet to load the downloaded offline tiles. The article is written in a hurry. If there are any problems, friends are welcome to criticize and correct.

Guess you like

Origin blog.csdn.net/yelangkingwuzuhu/article/details/131254647
xyz