Skip to content

Instantly share code, notes, and snippets.

@sfc
Created February 11, 2010 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfc/6e86aa28466aaaa2b72d to your computer and use it in GitHub Desktop.
Save sfc/6e86aa28466aaaa2b72d to your computer and use it in GitHub Desktop.
def wms(request):
import mapscript
image = None
for field in ['IMAGE', 'COVERAGE', 'image', 'coverage', 'id', 'ID']:
if field in request.GET: image = request.GET[field]
try:
image = int(image)
obj = Map.objects.get(pk=image)
filename = obj.warped
except:
filename = "%s" % image
filename = "%s/%s" % (settings.MAP_PATH, os.path.basename(filename))
ows = mapscript.OWSRequest()
for k, v in request.GET.items():
if k.lower() in ['image', 'coverage']: continue
ows.setParameter(k, v)
ows.setParameter("LAYERS", "image")
ows.setParameter("COVERAGE", "image")
map = mapscript.mapObj('%s/wms.map' % settings.BASE_PATH)
raster = mapscript.layerObj(map)
raster.name = 'image'
raster.type = mapscript.MS_LAYER_RASTER
raster.data = filename
raster.status = mapscript.MS_DEFAULT
raster.setProjection( "+init=epsg:4326" )
raster.dump = mapscript.MS_TRUE
raster.metadata.set("wcs_formats", "GEOTIFF JPEG2000")
mapscript.msIO_installStdoutToBuffer()
contents = map.OWSDispatch(ows)
content_type = mapscript.msIO_stripStdoutBufferContentType()
content = mapscript.msIO_getStdoutBufferBytes()
return HttpResponse(content, content_type = content_type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment