Tuesday, December 11, 2018

Generate Single Mosaic Raster/Map from Map Tiles (Basemap Series Part 6)

This post is designed as continuation from previous Post


Now if you understand from my previous blog posts, many online map providers publish their online maps as tiled raster/vector map. There also many geospatial data format has been developed to store these tiles. One of them is MBTILES Format.

MBTILES stores all tiles into one packed file grouped into its respective zoom levels. Because the tiles structure inside the MBTILES has been standardized, mosaicking those tiles into one single raster dataset is pretty much possible.

There are plenty ways to do the mosaicking, one of them is utilizing MOBAC software. You can also use SasPlanet to do this.

At my previous post, I show you how to make custom styles of Google Maps using snazzymaps, now I will continue to generate single raster maps of my Area of Interest from the custom google maps.

Here is the workflow

1. From my previous post, the endpoint URL of my custom styled Google Maps is shown below.

https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i368045027!3m14!2sen-US!3sUS!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcC52Om9uLHMuZTpnfHAudjpvbixzLmU6bHxwLnY6b2ZmLHMuZTpsLnQuZnxwLnM6MzZ8cC5jOiNmZjAwMDAwMHxwLmw6NDAscy5lOmwudC5zfHAudjpvbnxwLmM6I2ZmMDAwMDAwfHAubDoxNixzLmU6bC5pfHAudjpvZmYscy50OjF8cC52Om9mZixzLnQ6MXxzLmU6Z3xwLnY6b2ZmLHMudDoxfHMuZTpnLmZ8cC5jOiNmZjAwMDAwMHxwLmw6MjB8cC52Om9mZixzLnQ6MXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjE3fHAudzoxLjIscy50OjIwfHAudjpvZmYscy50OjIwfHMuZTpnfHAudjpvZmYscy50OjIxfHAudjpvZmYscy50OjIxfHMuZTpnfHAudjpvZmYscy50OjV8cC52Om9mZixzLnQ6NXxzLmU6Z3xwLmM6I2ZmMjUzYzMyfHAubDoyMHxwLnY6b24scy50OjV8cy5lOmx8cC52Om9mZixzLnQ6ODF8cC52Om9mZixzLnQ6ODF8cy5lOmd8cC52Om9mZixzLnQ6MnxwLnY6b2ZmLHMudDoyfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjIxLHMudDoyfHMuZTpsfHAudjpvZmYscy50OjN8cC52Om9uLHMudDozfHMuZTpnfHAudjpvbnxwLmM6I2ZmYjgxOTE5fHAuczotNDR8cC5sOi0zMixzLnQ6M3xzLmU6Zy5zfHAuYzojZmY2YjU2NTYscy50OjN8cy5lOmx8cC52Om9mZixzLnQ6NDl8cC52Om9uLHMudDo0OXxzLmU6Zy5mfHAuYzojZmYwMDAwMDB8cC5sOjE3LHMudDo0OXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjI5fHAudzowLjIscy50OjQ5fHMuZTpsfHAudjpvZmYscy50OjUwfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE4LHMudDo1MXxwLnY6b24scy50OjUxfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE2LHMudDo1MXxzLmU6bHxwLnY6b2ZmLHMudDo0fHAudjpvZmYscy50OjR8cy5lOmd8cC5jOiNmZjAwMDAwMHxwLmw6MTkscy50OjZ8cy5lOmd8cC5jOiNmZjBmMTkyZXxwLmw6MTd8cC52Om9u!4e0 

2. Now create An XML file using text editor (like Notepad++), and prepare XML structure like this below, and paste the above URL between the url Tag.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?><customMultiLayerMapSource>

<name>Google_Custom</name>

<tileType>png</tileType>

<layers>

<customMapSource>
<name>Google_Custom_Styles</name>
<minZoom>0</minZoom>

<maxZoom>19</maxZoom>

<tileType>png</tileType>

<tileUpdate>None</tileUpdate>
<url>paste the URL above here</url>
<backgroundColor>#000000</backgroundColor>

</customMapSource>

</layers>
</customMultiLayerMapSource>
3. Modify the {z}, {x} and {y} from the URL to {$z}, {$x} and {$y}, then save the XML file into MapSources folder in the MOBAC folder. 

4. Open the MOBAC software, Create New Atlas in MBTILES Format. 


5. Boot Up the Google Custom Map created in the previous steps until the tiles shown in the map page. 


6. Continue with the Zoom level selection, Add Zoom level selection and Create Atlas. 

7. Once the atlas creation finished, click Atlas Menu on the top left corner of MOBAC interface, and choose Convert Atlas Format, Choose PNG + World File Format. 



8. Click Create Atlas Button once again, MOBAC will generate mosaic of the downloaded tiles in PNG format, for every Zoom Level. 

9. The coordinate system used in the mosaic dataset depends on the coordinate system used by the Map Provider (usually in Web Mercator Projection), if you need another Coordinate System, you can convert it using QGIS, ArcGIS or any other GIS software. 

10. Here is an example of mosaic created from 5435 tiles of Google Maps custom style at Zoom Level 19. 




Cheers! 



Monday, December 10, 2018

Modify Google Maps Vector Tiles and Open it in QGIS (Basemap Series Part 5)

It is been a while since last time I discuss about vector tiles basemap. And today I found something cool that may be useful for you too.

As you already know, Google nowadays is also publish it online maps to vector tiles format which make their maps more beauty as well as faster to load.

And because vector tiles based online maps can be stylized in a custom way, there goes also the google maps vector tiles. You can modify how it looks to suit your application needs without spending additional money or resources.

Now, lets go to how to do that.

1. First, go to application that enabling us to customize the Google Maps style using CSS. https://snazzymaps.com is one example. You can explore styles made by other people or make a new style for yourself if you have enough knowledge about CSS.



2. After you find certain style that you are interested in, go to inspect element (chrome) or Firebird (Firefox) and find out the URL for a tile image. Below is an example.

https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i15!2i5199!3i11524!4i256!2m3!1e0!2sm!3i368045027!3m14!2sen-US!3sUS!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcC52Om9uLHMuZTpnfHAudjpvbixzLmU6bHxwLnY6b2ZmLHMuZTpsLnQuZnxwLnM6MzZ8cC5jOiNmZjAwMDAwMHxwLmw6NDAscy5lOmwudC5zfHAudjpvbnxwLmM6I2ZmMDAwMDAwfHAubDoxNixzLmU6bC5pfHAudjpvZmYscy50OjF8cC52Om9mZixzLnQ6MXxzLmU6Z3xwLnY6b2ZmLHMudDoxfHMuZTpnLmZ8cC5jOiNmZjAwMDAwMHxwLmw6MjB8cC52Om9mZixzLnQ6MXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjE3fHAudzoxLjIscy50OjIwfHAudjpvZmYscy50OjIwfHMuZTpnfHAudjpvZmYscy50OjIxfHAudjpvZmYscy50OjIxfHMuZTpnfHAudjpvZmYscy50OjV8cC52Om9mZixzLnQ6NXxzLmU6Z3xwLmM6I2ZmMjUzYzMyfHAubDoyMHxwLnY6b24scy50OjV8cy5lOmx8cC52Om9mZixzLnQ6ODF8cC52Om9mZixzLnQ6ODF8cy5lOmd8cC52Om9mZixzLnQ6MnxwLnY6b2ZmLHMudDoyfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjIxLHMudDoyfHMuZTpsfHAudjpvZmYscy50OjN8cC52Om9uLHMudDozfHMuZTpnfHAudjpvbnxwLmM6I2ZmYjgxOTE5fHAuczotNDR8cC5sOi0zMixzLnQ6M3xzLmU6Zy5zfHAuYzojZmY2YjU2NTYscy50OjN8cy5lOmx8cC52Om9mZixzLnQ6NDl8cC52Om9uLHMudDo0OXxzLmU6Zy5mfHAuYzojZmYwMDAwMDB8cC5sOjE3LHMudDo0OXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjI5fHAudzowLjIscy50OjQ5fHMuZTpsfHAudjpvZmYscy50OjUwfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE4LHMudDo1MXxwLnY6b24scy50OjUxfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE2LHMudDo1MXxzLmU6bHxwLnY6b2ZmLHMudDo0fHAudjpvZmYscy50OjR8cy5lOmd8cC5jOiNmZjAwMDAwMHxwLmw6MTkscy50OjZ8cy5lOmd8cC5jOiNmZjBmMTkyZXxwLmw6MTd8cC52Om9u!4e0!5m1!5f2&amp;token=27244\

if you open above link in your browser, you will get this tile image.


3. Paste the url in Notepad or any other text editor, and change the URL at this portion (using above URL),
pb=!1m5!1m4!1i15!2i5199!3i11524! to pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!
4. Delete all  characters after "!4e0" , because this custom styles doesn't need API key.

5. The URL now will looks like this :

https://maps.googleapis.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i368045027!3m14!2sen-US!3sUS!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!12m4!1e26!2m2!1sstyles!2zcC52Om9uLHMuZTpnfHAudjpvbixzLmU6bHxwLnY6b2ZmLHMuZTpsLnQuZnxwLnM6MzZ8cC5jOiNmZjAwMDAwMHxwLmw6NDAscy5lOmwudC5zfHAudjpvbnxwLmM6I2ZmMDAwMDAwfHAubDoxNixzLmU6bC5pfHAudjpvZmYscy50OjF8cC52Om9mZixzLnQ6MXxzLmU6Z3xwLnY6b2ZmLHMudDoxfHMuZTpnLmZ8cC5jOiNmZjAwMDAwMHxwLmw6MjB8cC52Om9mZixzLnQ6MXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjE3fHAudzoxLjIscy50OjIwfHAudjpvZmYscy50OjIwfHMuZTpnfHAudjpvZmYscy50OjIxfHAudjpvZmYscy50OjIxfHMuZTpnfHAudjpvZmYscy50OjV8cC52Om9mZixzLnQ6NXxzLmU6Z3xwLmM6I2ZmMjUzYzMyfHAubDoyMHxwLnY6b24scy50OjV8cy5lOmx8cC52Om9mZixzLnQ6ODF8cC52Om9mZixzLnQ6ODF8cy5lOmd8cC52Om9mZixzLnQ6MnxwLnY6b2ZmLHMudDoyfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjIxLHMudDoyfHMuZTpsfHAudjpvZmYscy50OjN8cC52Om9uLHMudDozfHMuZTpnfHAudjpvbnxwLmM6I2ZmYjgxOTE5fHAuczotNDR8cC5sOi0zMixzLnQ6M3xzLmU6Zy5zfHAuYzojZmY2YjU2NTYscy50OjN8cy5lOmx8cC52Om9mZixzLnQ6NDl8cC52Om9uLHMudDo0OXxzLmU6Zy5mfHAuYzojZmYwMDAwMDB8cC5sOjE3LHMudDo0OXxzLmU6Zy5zfHAuYzojZmYwMDAwMDB8cC5sOjI5fHAudzowLjIscy50OjQ5fHMuZTpsfHAudjpvZmYscy50OjUwfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE4LHMudDo1MXxwLnY6b24scy50OjUxfHMuZTpnfHAuYzojZmYwMDAwMDB8cC5sOjE2LHMudDo1MXxzLmU6bHxwLnY6b2ZmLHMudDo0fHAudjpvZmYscy50OjR8cy5lOmd8cC5jOiNmZjAwMDAwMHxwLmw6MTkscy50OjZ8cy5lOmd8cC5jOiNmZjBmMTkyZXxwLmw6MTd8cC52Om9u!4e0 

6. Load your QGIS, and Open the Catalog Window. Go to XYZ Tiles Tab, and Create New Connection.

7. Paste the modified URL to the URL BOX, and give it a title. After you done, load the files to QGIS Canvas using right click of the mouse.

8. Here is an example of the result.







Here is an video tutorial demonstration 



Cool and Cheers!