Android Question Creating Tiles to use them in a TileProvider on GoogleMap

DonManfred

Expert
Licensed User
Hello,

i am in the need to display Offizial GeoTIFFs on a GoogleMap.

I am able to create the Tiles with MapTiler (Windowssoftware) but this software is not Free (or limited in the Free Version).

So i was searching for an Alternative. I did find this:
https://alastaira.wordpress.com/2011/07/11/maptiler-gdal2tiles-and-raster-resampling/

So I’ve been using MapTiler to create some quick raster tilesets from a set of GeoTIFF images. MapTiler is a Windows application that will reproject and cut any GDAL-supported datasource into a set of 256px x 256px image tiles, suitable for use as a custom tile layer in Google Maps or Bing Maps et al.

MapTiler is essentially just a GUI wrapper around the GDAL2Tiles.py python script, which is distributed as part of GDAL.

So i thought i should give it a try. I installed GDAL and all needed tools.

NOTE that i got it working using the Tiles created with MapTiler. All the Tiles matches the Path-structure needed: \[zoom]\[tileX]\[tileY].png

B4X:
                   -={ OSGeo4W Shell Commands }=-

       avcexport           gensprep            proj
       avcimport           geod                psql
       cs2cs               geotifcp            python
       curl                gltpd               python3
       derb                gnmanalyse          pythonw
       dllupdate           gnmmanage           pythonw3
       easy_install3       gpsbabel            qgis-bin-g7.4.0
       example1            gswin32c            qgis-bin
       example2            icuinfo             raw2tiff
       fax2ps              icupkg              rpcgen
       fax2tiff            las2las             sqlite3
       fftw-wisdom         las2ogr             testepsg
       gdaladdo            las2txt             textreplace
       gdalbuildvrt        lasblock            tiff2bw
       gdaldem             lasinfo             tiff2pdf
       gdalenhance         listgeo             tiff2ps
       gdalinfo            makeconv            tiff2rgba
       gdallocationinfo    nad2bin             tiffcmp
       gdalmanage          nccopy              tiffcp
       gdalserver          ncdump              tiffcrop
       gdalsrsinfo         ncgen               tiffdither
       gdaltindex          ncgen3              tiffdump
       gdaltransform       nearblack           tiffinfo
       gdalwarp            nircmd              tiffmedian
       gdal_contour        nircmdc             tiffset
       gdal_grid           ogdi_import         tiffsplit
       gdal_rasterize      ogdi_info           ts2las
       gdal_translate      ogr2ogr             txt2las
       genbrk              ogrinfo             uconv
       genccode            ogrlineref          vcredist-2013-x64
       gencfu              ogrtindex           vcredist_2015_x64
       gencmn              osgeo4w-setup       xmlcatalog
       gencnval            pal2rgb             xmllint
       gendict             pip3                xmlwf
       gennorm2            pkgdata             xxmklink
       genrb               ppm2tiff


       epsg_tr           gdal_pansharpen   ps2pdf13
       esri2wkt          gdal_polygonize   ps2pdf14
       gcps2vec          gdal_proximity    ps2pdfxx
       gcps2wld          gdal_retile       py3_env
       gdal2tiles        gdal_sieve        python-qgis
       gdal2xyz          grass74           qgis-designer
       gdalchksum        gssetgs           qgis-grass7
       gdalcompare       liblas            qgis
       gdalident         make-bat-for-py   qt5_env
       gdalimport        mkgraticule       rgb2pct
       gdalmove          o-help            saga-ltr_gui
       gdal_auth         o4w_env           setup-test
       gdal_calc         ogrmerge          setup
       gdal_edit         pct2rgb
       gdal_fillnodata   ps2pdf
       gdal_merge        ps2pdf12

A lot of tools to try.

I am able to create a Tileset with
gdal_translate –of vrt –expand rgba tq38sw.tif tq38sw_rgba.vrt
followed by
gdal2tiles -z 1-21 –s_srs EPSG:25832 tq38sw_rgba.vrt E:\GeoTIFFS\Export\

I got a Directorystructure created in E:\GeoTIFFS\Export\ which should match

E:\GeoTIFFS\Export\[zoom]\[tileX]\[tileY].png

Up to E:\GeoTIFFS\Export\[zoom]\[tileX]\ the result matches the Output i got using MapTiler.
But for the tileY (which represents the Filename of the png) i got different results using MapTiler and gdal2tiles

You can download both Sets here if you want to have a look.

For example i compared two Tiles.
Zoom 17, TileX 67765, TileY is
43942.png in MapTiler
43942.png

and 87129.png in gdal2tiles

87129.png

Does anybody have an Idea how i could create the same posY tile-name with the Pythonvariant?

Or maybe there is a formular to convert 43942 to 87129. I dont know why i get different results.


I am using Warwounds TileProvider from GoogleMapExtra

B4X:
Sub TileProv_GetTileUrl(TileX As Int, TileY As Int, Zoom As Int) As String
    Log($"TileProv_GetTileUrl(${TileX}, ${TileY}, Zoom ${Zoom})"$)
   
    Dim tileurl As String = $"http://basic4android.de/tiles/${Zoom}/${TileX}/${TileY}.png"$
    Return tileurl
End Sub
Sub MapFragment1_Ready
    Log("MapReady()")
    gmap = MapFragment1.GetMap

    Dim mextra As GoogleMapsExtras
   
    Dim prov As CustomUrlTileProvider
    prov.Initialize("TileProv",256,256)
   
    Dim tileovlopt As TileOverlayOptions
    tileovlopt.Initialize
    tileovlopt.SetTileProvider(prov)
   
    mextra.AddTileOverlay(gmap,tileovlopt)
   
    ' merkstein 50.889222,6.0955466
   
    'Dim m1 As Marker = gmap.AddMarker(50.889222,6.0955466, "test")
    Dim latlon As LatLng
    latlon.Initialize(50.889222,6.0955466)
    Dim cp As CameraPosition
    cp.Initialize(latlon.Latitude, latlon.Longitude, 17) ' Use own location LAT LON
    gmap.AnimateCamera(cp)

   
End Sub

WhatsApp Image 2018-04-15 at 10.35.42.jpeg

Any hints is appreciated :)
 
Last edited:

DonManfred

Expert
Licensed User
Dammit... It was easier than i thought.
I did created another TileProvider in java

B4X:
    public TileProvider GetTileprovider(GoogleMap gmap) {
        TileProvider tileProvider = new UrlTileProvider(256, 256) {
      @Override
      public synchronized URL getTileUrl(int x, int y, int zoom) {
          // The moon tile coordinate system is reversed.  This is not normal.
          int reversedY = (1 << zoom) - y - 1;
          String s = String.format(Locale.GERMAN, MAP_URL_FORMAT, zoom, x, reversedY);
                // Event only informative... This method is returning the URL used to GoogleMaps
          ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_tileurl", true, new Object[] {x,reversedY,zoom,s});
          URL url = null;
          try {
              url = new URL(s);
          } catch (MalformedURLException e) {
              throw new AssertionError(e);
          }
          return url;
      }
        };
        return tileProvider;   
    }

and added it with mapextras

B4X:
    Dim tileovlopt As TileOverlayOptions
    tileovlopt.Initialize
    tileovlopt.SetTileProvider(vh.GetTileprovider(gmap))
    mextra.AddTileOverlay(gmap,tileovlopt)

The tileprovider is now using the same Tile-Structure i got using gdal2tiles :D
 
Upvote 0
Top