gdal2tiles.py: Slice an image with its center being (0,0)

291 views Asked by At

I made a map for my Minetest Game I play.

The project is here : https://github.com/amelaye/aiwMapping I created the map with the Python script gdal2tiles, like this : ./gdal2tiles.py -l -p raster -z 0-10 -w none ../map.png ../tiles

Here is the interesting part of code :

    var minZoom = 0
    var maxZoom = 9
    var img = [
        20000, // original width of image
        20000  // original height of image
    ]

    // create the map
    var map = L.map(mapid, {
        minZoom: minZoom,
        maxZoom: maxZoom
    })

    var rc = new L.RasterCoords(map, img)
    map.setView(rc.unproject([9000, 10554]), 7)
    L.control.layers({
        'Spawn': layerGeoGlobal(window.geoInfoSpawn, map, rc, 'red', 'star', 'fa'),
    }, {
        'Bounds': layerBounds(map, rc, img),
    }).addTo(map)

    L.tileLayer('./tiles/{z}/{x}/{y}.png', {
        noWrap: true,
        attribution: ''
    }).addTo(map)

It works like a charm, but there is a problem : in Minetest, the coords (lat and lon) go to -10000 to 10000. In my Leaflet map, the coords still positive, then they go from 0 to 20000.

How can I solve this problem ?

CRS SIMPLE does not work.

PS : No relative questions have been posted, please read my message carefully.

1

There are 1 answers

3
IvanSanchez On

When gdal2tiles is not given a georeferenced image (or a world file accompanying the image), it will assume that the (0,0) coordinate is at one of the corners of the image, and that one pixel equals one map unit (both horizontally and vertically).

Since your input image is a .png file, the most straightforward way of working around the issue will be creating an appropriate world file.

If your input image is map.png, create a new plain text file named map.pgw with the following contents...

1
0
0
1
-10000
-10000

...then run gdal2tiles.py again. Note that this worldfile assumes that one pixel equals one map unit, and the image's first corner is at the (-10000,-10000) coordinate.