geodesign / django-raster

Django-raster allows you to create tiled map services (TMS) and raster map algebra end points for web maps. It is Python-based, and requires GeoDjango with a PostGIS backend.
BSD 3-Clause "New" or "Revised" License
96 stars 39 forks source link

Question regarding raster display #30

Closed ElijasZ closed 6 years ago

ElijasZ commented 6 years ago

Hello, i am completely new regarding GDAL and Django GIS coul you give an example of code on how to pass raster stored in raster database to leaflet (since you mention it in documentation)

ArnaudLevaufre commented 6 years ago

Hi, According to http://django-raster.readthedocs.io/en/latest/installation.html you should add the following url to your project urlpatterns definition.

url(r'^raster/', include('raster.urls')),

Then according to https://leafletjs.com/ you can use django-raster's TMS endpoint in leaflet as demonstrated bellow:

// replace the setView arguments so it's centered and zoomed on you area of interest. 
// Here it's centered to lat 51.505, lon -0.09 and it's using the 13th zoom level.
var map = L.map('map').setView([51.505, -0.09], 13);

// Openstreemap background tiles
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

// Your tiles
L.tileLayer('http://localhost:8000/raster/tiles/layer_id/{z}/{x}/{y}.png', {
    attribution: 'Something'
}).addTo(map);

I'm not entirely sure about the leaflet setup as I use openlayers but it should work that way. By default django-raster will display the tilling using a simple grayscale, so checkout the TMS endpoint documentation to see how to add colors.

ElijasZ commented 6 years ago

Thank you very much, it worked like a charm.