-
-
Save sfc/6e86aa28466aaaa2b72d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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