2

I have 2 raster images (.png), 2 maps that are geographically next to each other (east part and west part of a city). These images are part of a bigger set, and cannot be merged (or my PC dies).

These PNGs have been georeferenced (WGS 84) using QGIS georeferencer, and I have 2 tilemapresource.xml has a result. The maps have then been split in tile-trees using gdal2tiles.

The problem is that when running my server, leaflet consistently loads both maps exactly on top of each other (which can bee seen because maps are loaded in order, the second one replacing the first one after a second).

I feel like this is how it's supposed to work (I never feed leaflet my .xml files, so it just put them at the default coordinates), but I have no idea how to tell leaflet where to place my map.

My code looks like this:

var map = L.map('map', {
center: [0, 0],
zoom: 1
});

var tif_map = L.tileLayer('http://localhost:5000/test/{z}/{y}/{x}', {
    maxZoom: 8,
    continuousWorld: true,
    noWrap: true,
    attribution: 'Astrosias'
}).addTo(map);

var png_map = L.tileLayer('http://localhost:5000/test0/{z}/{y}/{x}', {
    maxZoom: 8,
    continuousWorld: true,
    noWrap: true,
    attribution: 'Astrosias'
}).addTo(map);

What is the regular way to locate my layers ? I know I can do it quite easly in openlayer.js using the "TileGrid" parameter of the layers, but I found no such parameter in leaflet.

10
  • The way you tried to combine those two layers does not work in Leaflet. You have two different extents with equally numbered tilesets. For Leaflet this are two different projections, but Leaflet supports only one CRS per map.
    – TomazicM
    Mar 5 at 19:15
  • I've never used it/tried it, but you could try Leaflet.TileCorrection plugin (github.com/z632896862/Leaflet.TileCorrection). Since you have the same projection for your both tilesets, just different origin and extent, it might work for you.
    – TomazicM
    Mar 5 at 19:21
  • There is no native way ? How do people do to make city-wide maps in only 1 tree ?
    – Astrosias
    Mar 5 at 20:39
  • 1
    First join the two images into one image and then make tiles.
    – TomazicM
    Mar 5 at 20:40
  • I don't have 2 images. I have 37, and each one is 40000x40000 pixels, my computer can't handle merging them.
    – Astrosias
    Mar 5 at 20:42

1 Answer 1

4

Build a VRT tileset and use that as input to gdal2tiles. That way you get a single tiletree that is a mosaic of your source images.

My data: I cut a USGS topo map into 3 PNG files, 1.png, 2.png and 3.png. I then georeferenced these with world files.

Thats my baseline, you already have your data.

Then I ran gdalbuildvrt ( see https://gdal.org/programs/gdalbuildvrt.html ) to get a VRT dataset (you have to provide the SRS):

gdalbuildvrt -a_srs EPSG:26914 123.vrt 1.png 2.png 3.png

The 123.vrt holds a XML with metadata for all bands of all files. Its size is 5 kilobytes in my case.

Then I used the 123.vrt as input for gdal2tiles

gdal2tiles 123.vrt outtiles/
4
  • 1
    This looks like what I need, I'll give it a go tomorrow.
    – Astrosias
    Mar 5 at 21:58
  • Did it work out or did you run into problems? If it works please mark the answer as accepted by clicking the checkmark under the answer score.
    – til_b
    Mar 7 at 7:00
  • Sorry, I didn't find the time to try it out yet, but will update ASAP. From what I see, using this feature will still require me to process the whole vrt in one gdal2tiles run, which is kinda impossible in my specific case (I can't wait 2 days for it to end).
    – Astrosias
    Mar 7 at 20:53
  • 1
    I accepted your answer, as it seems like the correct way to proceed. Given my chaotic database, I didn't manage to use it, and resolved to split each image separately, then create a mega-tree with a custom script.
    – Astrosias
    Mar 20 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.