📜 ⬆️ ⬇️

Creating a map cache in Geoserver using third-party services

It all started with the fact that when developing geoportals using ArcGis, customers increasingly began to say something like: “We like everything, but we can do everything the same, but using open source software”, implying at the same time replacing the MSSQL + ArcGis bundle Server + ArcGis Javascript (Silverlight) Toolkit on Postgres (PostGis) + Geoserver + Openlayers.

Well, in general, you can understand them, because 1-2-3 million rubles change for 0 rubles. There was no particular problem in the majority, vector data is transferred either through SHP files, or through converters from MSSQL to PostGis (or simply via SQL queries). There is a question with raster data. For example, there is a well-traced, tuned and multi-level cache map of Russia. In ArcGis, it is stored either in a compact form (in the form of bundles understandable only by ArcGis format) or non-compact, that is, the map tiles are simply located in directories. Then I was delighted and thought that in the second case everything would be exactly simple. But no - the tiles are of course divided into levels, however, they have strange names and may lie in strange subfolders, and with the geo-referencing of this cache, just a disaster.

But then a very simple and quick solution came - scan your own service (since the service sends tiles to the clear URL of the form "... MapServer / tile / Z / Y / X" where Z is the level number, and X and Y are tiles numbers according to horizontals and verticals respectively). Now there is another question - how to put these linked tiles on the Geoserver? In Geoserver, for such purposes Image Pyramid Plugin is used , or rather not exactly for such - it is mainly used to simplify working with giant TIFF files, the gdal_retile script from the gdal package traverses the TIFF file and creates many small geolocated tiles at different levels, divided into folders with numbers of levels.
')
That's all the original data. At first, I wrote the application in my native C #, but decided to follow the path of this OSS and rewrote it in Java, naturally putting the code on GitHub.

The main form is:

image

Everything is simple:
- Tile url pattern - the url pattern for the tile, where {2} is the position of the level number, {0} is the position of the tile number horizontally (X), {1} is vertically (Y).
- Max layer bounds - geolocation of the entire layer, i.e. where the countdown begins and ends
- Region layer bounds - geolocation of the desired region
- Levels: Start - the initial "lower" level, for example 4, End the final "upper", for example 0 (the whole map is in one tile)
-Tile size - the size of the tile, which gives the service
- Jpeg compression - if you want output tiff to use compression.
- Reference system WKT - text describing the coordinate system, examples of coordinate systems can be found here
- Path folder for output files

That's all - after writing these parameters, click run and download tiles.

You can download the program here (need Java)
INFA is here
The code is here

And now a small tutorial for those who did not understand, but it became interesting

1. Download and install Geoserver ;
2. Download and install the ImagePyramid plugin ;
3. Download , unpack and run the application;
4. Click the OSM Example button - the fields are automatically filled in for the OpenStreetMap tiles, the first 5 layers;
5. Select the folder where to create tiles;
6. After completion, open the geoserver and create a pyramid storage and layer;
7. Open the layer preview and enjoy;
8. All the same, but with pictures here .

PS There is a glitch with not square pyramids, that is, those whose base is not a square, but a rectangle (very often in the UK epsg: 4326). For all rectangular (EPSG: 3857 (90013), EPSG: 3395) starting with 0 it seems to work correctly (OSM, Google, Yandex). And remember about the license agreement services when using content. Do not break them.

Source: https://habr.com/ru/post/166205/


All Articles