Skip to content

Commit

Permalink
moved rastercoords to its own repo
Browse files Browse the repository at this point in the history
  • Loading branch information
commenthol committed Oct 22, 2016
1 parent a3ee2c8 commit 071ff3b
Show file tree
Hide file tree
Showing 24 changed files with 497 additions and 9,528 deletions.
7 changes: 1 addition & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
The MIT License (MIT)

gdal2tiles.py
Copyright (c) 2008, Klokan Petr Pridal
Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org>

rastercoords.js
Copyright (c) 2015, commenthol
Copyright (c) 2016, commenthol

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
126 changes: 31 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,51 @@

> Generate raster image tiles for use with leaflet.
This is a modified version of [gdal2tiles.py][] which adds support for
raster images as plain 2D maps in [leafletjs][].
[Example][example] in action.

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.
This is a modified version of [gdal2tiles.py][] which adds support for raster images as plain 2D maps in [leafletjs][].

Together with the small [leafletjs][] plugin `rastercoords.js` you'll
be able to add markers at the correct position using the x,y coords of
the full-size image.
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.

## Basic usage

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

See [test/createtiles.sh](test/createtiles.sh).
Check [test/createtiles.sh](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 karta.jpg tiles
$ gdal2tiles-multiprocess.py -l -p raster -z 0-5 -w none <image> <tilesdir>
````

## Usage with Leaflet

To use the generated tiles with [leafletjs][] there is a simple plugin
to correctly set the required projection [rastercoords.js](rastercoords.js).

```` html
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" href="leaflet-0.7.3/leaflet.css" />
<script src="leaflet-0.7.3/leaflet-src.js"></script>
<script src="rastercoords.js"></script>
<script src="index.js"></script>
<style>
html, body, #map { width:100%; height:100%; margin:0; padding:0; background-color: #B0B0B0 }
</style>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>
````

In the `index.js`:

```` js
function init() {
var minZoom = 0,
maxZoom = 5,
img = [
3831, // original width of image
3101 // original height of image
];

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

// assign map and image dimensions
var rc = new L.RasterCoords(map, img);
// set the bounds on map
rc.setMaxBounds();

// set the view centered ...
map.setView(rc.unproject([img[0]/2, img[1]/2]), 5);

// set marker at the image bound edges
var layerBounds = L.layerGroup([
L.marker(rc.unproject([0,0])).bindPopup('[0,0]'),
L.marker(rc.unproject(img)).bindPopup(JSON.stringify(img))
]);
map.addLayer(layerBounds);

// set markers on click events in the map
map.on('click', function(event){
var coords = rc.project(event.latlng);
var marker = L.marker(rc.unproject(coords))
.addTo(layerBounds);
marker.bindPopup('['+Math.floor(coords.x)+','+Math.floor(coords.y)+']')
.openPopup();
});

// the tile layer containing the image generated with gdal2tiles --leaflet ...
L.tileLayer('./tiles/{z}/{x}/{y}.png', {
noWrap: true,
attribution: 'Map <a href="https://commons.wikimedia.org/wiki/'+
'File:Karta_%C3%B6ver_Europa,_1672_-_Skoklosters_slott_-_95177.tif">'+
'Karta över Europa, 1672 - Skoklosters</a> under '+
'<a href="https://creativecommons.org/publicdomain/zero/1.0/deed.en">CC0</a>',
}).addTo(map);
}
````

Please check the example in folder [test](test) which uses [Leaflet 0.7.3][leafletjs].
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

Expand All @@ -138,7 +64,6 @@ Then open `index.html` in a browser.

Or see it [here][example] in action.


## Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your
Expand All @@ -148,21 +73,32 @@ with the source of its origin and licence.

## License

gdal2tiles.py: (MIT licensed)
Modifications and samples are [MIT licensed][LICENSE].

[gdal2tiles.py][]: (MIT licensed)
* Copyright (c) 2008, Klokan Petr Pridal
* Copyright (c) 2010-2013, Even Rouault

rastercoords.js + sample: (MIT licensed)
* Copyright (c) 2015 commenthol

leaflet for sample: [(License)](https://github.com/Leaflet/Leaflet/blob/master/LICENSE)
* Copyright (c) 2010-2015, Vladimir Agafonkin
* Copyright (c) 2010-2011, CloudMade

See [LICENSE][] for more info.
## References

<!-- !ref -->

* [/gdal-1.11.1/swig/python/scripts/gdal2tiles.py][gdal2tiles.py]
* [example][example]
* [gdal2tiles-Ticket-4379][gdal2tiles-Ticket-4379]
* [leaflet-rastercoords][leaflet-rastercoords]
* [leafletjs][leafletjs]
* [LICENSE][LICENSE]

<!-- ref! -->

[LICENSE]: ./LICENSE
[leafletjs]: http://leafletjs.com
[leaflet-rastercoords]: https://github.com/commenthol/leaflet-rastercoords
[gdal2tiles.py]: http://download.osgeo.org/gdal/1.11.1/gdal-1.11.1.tar.gz "/gdal-1.11.1/swig/python/scripts/gdal2tiles.py"
[gdal2tiles-Ticket-4379]: http://trac.osgeo.org/gdal/ticket/4379
[example]: https://commenthol.github.io/gdal2tiles-leaflet/test/index.html
58 changes: 0 additions & 58 deletions rastercoords.js

This file was deleted.

Binary file modified test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Binary file added test/images/marker-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<title>Test</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" href="leaflet-0.7.3/leaflet.css" />
<script src="leaflet-0.7.3/leaflet-src.js"></script>
<script src="../rastercoords.js"></script>
<link rel="stylesheet" href="leaflet/leaflet.css" />
<script src="leaflet/leaflet.js"></script>
<script src="rastercoords.js"></script>
<script src="index.js"></script>
<style>
html, body, #map { width:100%; height:100%; margin:0; padding:0; background-color: #B0B0B0 }
Expand Down
Loading

0 comments on commit 071ff3b

Please sign in to comment.