Giter Site home page Giter Site logo

commenthol / gdal2tiles-leaflet Goto Github PK

View Code? Open in Web Editor NEW
459.0 22.0 130.0 59.35 MB

Generate raster image tiles for use with leaflet.

Home Page: https://commenthol.github.io/leaflet-rastercoords/

License: MIT License

Python 94.76% JavaScript 4.66% Shell 0.29% HTML 0.30%
tile-generator leaflet raster coordinates

gdal2tiles-leaflet's Introduction

gdal2tiles-leaflet

Generate raster image tiles for use with leaflet.

Example in action.

This is a modified version of gdal2tiles.py which adds support for raster images as plain 2D maps in leafletjs.

It adds the option -l or --leaflet to generate the resulting images with the reference point [0,0] in the upper-left (North-West) corner, opposed to the standard behaviour for TMS tiles using the lower-left (South-East) corner.

Together with the small leafletjs plugin leaflet-rastercoords you'll be able to add markers at the correct position using the (x, y) coordinates of the full-size image.

Prerequisites

On Debian style OS:

sudo apt install python-gdal

for python3

sudo apt install python3-gdal

for others give your search-engine a try...

Basic usage

$ gdal2tiles.py -l -p raster -z 0-5 -w none <image> <tilesdir>

Check test/createtiles.sh for usage.

If the -z option is omitted then the tool considers the min. zoom level otherwise note...

Note: The min zoom level for tile generation must be greater or equal to log2(max(width, height)/tilesize)

Assuming an image with 2000x3000 pixels:

# take the larger dimension -> here height = 3000px
$ echo "l(3000/256)/l(2)" | bc -l
# 3.55 --> min zoomlevel for tile generation is 4
# means: `gdal2tiles.py -l -p raster -z 0-2 ...`
#                                          \__ is not allowed
# correct usage
$ gdal2tiles -l -p raster -z 0-4 ...

Multicore usage

The same works with multicore support, thanks to gdal2tiles-Ticket-4379.

$ gdal2tiles-multiprocess.py -l -p raster -z 0-5 -w none <image> <tilesdir>

Usage with Leaflet

To use the generated tiles with Leaflet there is a small plugin to correctly set the required projection for raster images. Please refer to the documention at leaflet-rastercoords.

Example

To run the example you'll need to generate the tiles for the large image first.

$ cd test
$ ./createtiles.sh
$ open index.html

Then open index.html in a browser.

The sample in test

Or see it here in action.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the respective license. You are also implicitly verifying that all code is your original work or correctly attributed with the source of its origin and licence.

License

Modifications and samples are MIT licensed.

gdal2tiles.py: (MIT licensed)

  • Copyright (c) 2008, Klokan Petr Pridal
  • Copyright (c) 2010-2013, Even Rouault

References

gdal2tiles-leaflet's People

Contributors

alejandrocabeza avatar carlostighe avatar commenthol avatar guvener avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gdal2tiles-leaflet's Issues

gdal2tiles.py: error: no such option: -l

Great tool, unfortunately when I try to use the leaflet option
gdal2tiles.py -l -p raster -z 0-5 -w none test.jpg tiles

it breaks with the statement

gdal2tiles.py: error: no such option: -l

same if I try the --leaflet option
Any ideas?

tiling issue compared to vanilla gdal2tiles

I'm attempting to move a panorama viewer from Openlayers 2 to Leaflet and tried out your modified version of gdal2tiles.

It works great on 95% of the images I give it but a handful return tiles like this link:
http://dev.gregwacker.com/#/photos/panorama/clat_adams_bicentennial_park_pano_2__6_photos_.jpg

The original image I tried to tile can be found here:
http://dev.gregwacker.com/photoalbums/ThePanoramas/fullsize/clat_adams_bicentennial_park_pano_2__6_photos_.jpg

The vanilla gdal2tiles output can be seen here:
http://www.gregwacker.com/photos/_panoramasViewer.cfm?panoID=232

Any ideas on why the leaflet version chokes on some images like the one above? The setting are identical with the exception of the Leaflet switch.

Another alternative since I'm not worried about x,y maker coordinates is to use the TMS tiles from vanilla gdal2iles with TMS set to true in leaflet, but I can't quite figure out the math for the bounds. Would you have any interest in providing an alternate rastercoords.js for TMS tiles?

Thanks for sharing the work you've done with gdal2tiles-leaflet to date.

add python 3.x support

Sadly this does not work with python 3.x. It would be great if the script could be updated to work on new versions of python.

 File "gdal2tiles-multiprocess.py", line 50
    print 'You are using "old gen" bindings. gdal2tiles needs "new gen" bindings.'
                                                                                 ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('You are using "old gen" bindings. gdal2tiles needs "new gen" bindings.')?

This is the error when I try to run it

Retina support

Hi, it would be great to add support for retina / high DPI displays!

Some tiles are missing

I use a command
$ gdal2tiles-multiprocess.py --leaflet --processes=6 raster -z 0-4 -w none karta.jpg /tiles
and tiles 0-0-0 and 1-1-0 are missing
but
$ gdal2tiles-multiprocess.py --leaflet --processes=2 raster -z 0-4 -w none karta.jpg /tiles
gives me a full set of tiles

Generating tiles return empty tiles directories tree

I cloned the project and tested it as well. No problem. But when I try it with My own image the result is just empty directories, no images inside.

I exported the image from Gimp, maybe there are an option to set the get the right jpg format?

Test on Ubuntu

python3 ../gdal2tiles-multiprocess.py -l -p raster map.jpg tiles
Generating Base Tiles:
Generating Overview Tiles:

Compressed version with the same issue
map2.zip

Edit
I tested

python3 ../gdal2tiles.py -l -p raster map2.jpg tiles
Generating Base Tiles:
ERROR 6: Reading this image would require libjpeg to allocate at least 3774873600 bytes. This is disabled since above the 104857600 threshold. You may override this restriction by defining the GDAL_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, or recompile GDAL by defining the GDAL_LIBJPEG_LARGEST_MEM_ALLOC macro to a value greater than 104857600
ERROR 1: map2.jpg, band 1: IReadBlock failed at X offset 0, Y offset 0: Reading this image would require libjpeg to allocate at least 3774873600 bytes. This is disabled since above the 104857600 threshold. You may override this restriction by defining the GDAL_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, or recompile GDAL by defining the GDAL_LIBJPEG_LARGEST_MEM_ALLOC macro to a value greater than 104857600

I tried to add GDAL_ALLOW_LARGE_LIBJPEG_MEM_ALLOC=yes as an env variable but no success

Correct Tile row and col number

After using gdal2tiles2.py to cut tiles, the row and column number of the generated image starts from 0 and 0 by default. Can I input the longitude and latitude to make the row and column number correct? At the same time, in this case, the upper left corner of the image is taken as the starting point of slice by default. However, the upper left corner of any image is not exactly located in the upper left corner of a bounding rectangle under the leaflet slicing rule. Is there any way to crack it?

--tilesize=<PIXELS> option support

First of all, I wanted to thank you for this handy tool. I was using the "vanilla" gdal2tiles, but was having a lot of trouble using it with leaflet. After finding this leaflet version, I was finally able to get my tiles to display properly on the y-axis!

However, I came to realize that gdal2tiles-leaflet unfortunately doesn't have support for the new "--tilesize" option from gdal2tiles 3.1 (see https://gdal.org/programs/gdal2tiles.html#cmdoption-gdal_translate-tilesize). With the original program, I was generating my tiles at 215x215 rather than 256px, since my image is 13760x6880. This means that when I use the leaflet version to generate the tiles, it ends up a little wonky.

And so, I wanted to request the addition of the --tilesize option, if possible. I tried hacking it together myself, but unfortunately I have no experience with python.

Thank you for your time.

MInimum zoom level

the example shows the calculation saying the minimum zoom level must be at least 4, but then continues to say that 0-4 is correct? This is very confusing. Doesn't 0-4 mean minimum zoom level 0 and maximum zoom level 4? Also it says if you don't pass -z it 'considers' the minimum zoom level. What does this mean? It assumes a minimum zoom level of 0 and a maximum zoom level of ? it automatically calculates the appropriate zoom levels?

Requests for missing files when using leaflet

Hi,

I'm using leaflet with simple crs and I used your (great!) python script to split an image of ~15k px X ~8k px to tiles.

The result of the zoom calculation was 5.9.. so I changed 0-4 to 0-6, but I'm receiving 404 on paths like "2/3/-1", "2/2/-1", "4/-1/4", why is that? where did I go wrong? what is this -1? is it something on my JS declaration?

Thanks.
Rotem

Zoom range lower than native zoom ignored?

If I want to tile just zoom levels 0 and 1 (-z 0-1) it ignores my parameter and tiles 0-5.

5 being the "Native zoom of the raster".

My goal is to host this on AWS Lambda and allocate a single zoom level to each process so that I can process tiles as fast as possible through parallel computing power (low powered single core machines)

WriteRaster TypeError: not a string

ubuntu@ip-172-31-31-248:~$ python gdal2tiles-leaflet/gdal2tiles.py -z 0-11 -l -p raster -w none /mnt/1000/combined2.png /mnt/1000/out/
Generating Base Tiles:
0...10...20...30...40...50...60...70..ERROR 1: libpng: Read Error
ERROR 1: /mnt/1000/combined2.png, band 1: IReadBlock failed at X offset 0, Y offset 49257
Traceback (most recent call last):
  File "gdal2tiles-leaflet/gdal2tiles.py", line 2925, in <module>
    gdal2tiles.process()
  File "gdal2tiles-leaflet/gdal2tiles.py", line 606, in process
    self.generate_base_tiles()
  File "gdal2tiles-leaflet/gdal2tiles.py", line 1718, in generate_base_tiles
    + 1)),
  File "/usr/lib/python2.7/dist-packages/osgeo/gdal.py", line 2038, in WriteRaster
    buf_pixel_space, buf_line_space, buf_band_space )
TypeError: not a string

Not sure if this is reproducible yet as generating tiles takes ages:

/mnt/1000/combined2.png: PNG image data, 65536 x 65536, 8-bit/color RGB, non-interlaced

Generating base tiles getting stuck

I am trying to convert different .tiff files using this command python /tmp/gdal2tiles-multiprocess.py blueprint.tif tiles -z 16-22 --processes=4 and having this issue, In every 10 files any random 3-4 files getting stuck at "Generating base tiles" and takes too long to process sometimes 24-48 hours. any ideas ?

Alignment changes when zooming

I'm trying to render a map of a Hilbert curve - basically a flat 2D image. Here's one zoom level:

image

And here's the same image zoomed in:

image

Please let me know where could I upload the input file - it's pretty big (167M):

out.png: PNG image data, 65536 x 65536, 8-bit/color RGB, non-interlaced

And the command was:

/usr/bin/python gdal2tiles.py -l -p raster out.png outdir

Used latest git checkout on master.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.