i want to add raster functionality in django using postgis database using django-raster package and this docs.

here my code :


from django.contrib.gis.db import models
class RasterWithName(models.Model):
    raster = models.RasterField()
    name = models.TextField()

add raster using console :

from django.contrib.gis.gdal import GDALRaster
from myapp.models import RasterWithName
gdal_raster = GDALRaster('C:/Users/username/Desktop/image.tif')
rast = RasterWithName(name='one', raster=gdal_raster)

but i am very confused with Rendering tiles and urls.

docs say :

/raster/tiles/layer_id/{z}/{x}/{y}.png where the layer_id is the primary key of a raster layer. This structure can be used directly in online mapping software such as OpenLayers or Leaflet. An example request could look like this: /raster/tiles/23/8/536/143.png, returning a tile in png format of the layer with ID pk=23 at zoom level z=8 and indexes x=536 and y=143

but indexes x,y mean some random x,y coordinate in image ?anyway i using this url or x,y in my image) and i take a black window in my browser,any idea where i have wrong in my url rendering ?

1 Answer 1


In your code example you create your own raster model. That is not compatible with the functionality of the django-raster package. The goal of django-raster is to avoid having to create and manage raster models.

To use it, first make sure django-raster is correctly installed, see https://django-raster.readthedocs.io/en/stable/installation.html).

Then the raster files itself should be stored using the RasterLayer model that comes with the django-raster package. The easiest way to add your image is to use the django admin site. Simply create a new RasterLayer in the admin and upload your file using the rasterfile field.

So to display your raster data you don't need to write (much) code, just configure django-raster in your Django project and start using its functionality (such as ingesting and displaying raster data).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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