def _get_water_depth_extent(self, scenario): pl = scenario.presentationlayer.filter( presentationtype__id=PRESENTATIONTYPE_MAX_WATERDEPTH)[0] result = pyramids.get_result_by_presentationlayer(pl) png = external_file_location(result.absolute_resultloc) logger.debug("PGN location:\n{}".format(png)) extent = json.dumps(geo.GeoImage(png).extent()) logger.debug(extent) return extent
def service_get_gridframe(request, presentationlayer_id, legend_id, framenr=0): """get png of grid of given timestep, with given legend (of legend is None, use default legend) input presentationlayer legend timestep Conditions: - from given scenario (check permission for given scenario) output: png """ pl = get_object_or_404(PresentationLayer, pk=presentationlayer_id) result = pyramids.get_result_by_presentationlayer(pl) if result is not None and result.animation: # New style animation response = HttpResponse() colormap = request.GET.get('colormap') maxvalue = request.GET.get('maxvalue') result.animation.save_image_to_response( response, framenr, colormap, maxvalue) return response log.debug('get png name') png_name = external_file_location( pl.presentationgrid.png_default_legend.file_location) if pl.presentationtype.value_type == 3: log.debug('get png name with number.') numberstring = '%04i' % framenr png_name = png_name.replace('####', numberstring) log.debug('load files %s' % png_name) response = HttpResponse(open(png_name, 'rb').read()) response['Content-type'] = 'image/png' return response
def service_get_gridframe(request, presentationlayer_id, legend_id, framenr=0): """get png of grid of given timestep, with given legend (of legend is None, use default legend) input presentationlayer legend timestep Conditions: - from given scenario (check permission for given scenario) output: png """ pl = get_object_or_404(PresentationLayer, pk=presentationlayer_id) result = pyramids.get_result_by_presentationlayer(pl) if result is not None and result.animation: # New style animation response = HttpResponse() colormap = request.GET.get('colormap') maxvalue = request.GET.get('maxvalue') result.animation.save_image_to_response(response, framenr, colormap, maxvalue) return response log.debug('get png name') png_name = external_file_location( pl.presentationgrid.png_default_legend.file_location) if pl.presentationtype.value_type == 3: log.debug('get png name with number.') numberstring = '%04i' % framenr png_name = png_name.replace('####', numberstring) log.debug('load files %s' % png_name) response = HttpResponse(open(png_name, 'rb').read()) response['Content-type'] = 'image/png' return response
def legend_shapedata(request): """Draws a ShapeDataLegend input: GET['object_id']: ShapeDataLegend.id output: png image of the legend """ ## FIRST check if this is a new style grid, with dynamic legend presentationlayer_id = request.GET.get('presentationlayer_id') # Hack -- object_id really means legend id, but sometimes the # presentationlayer_id is passed in that way (because I do that # explictly in NPyramidOverlay.js, but I don't know why # presentationlayer_id isn't passed in in the first place) if presentationlayer_id is None: presentationlayer_id = request.GET.get('object_id') if presentationlayer_id: try: presentationlayer = PresentationLayer.objects.get( pk=presentationlayer_id) result = pyramids.get_result_by_presentationlayer( presentationlayer) if result: # Handle these elsewhere, dynamic template_variables = pyramids.result_legend( result, presentationlayer, request.GET.get('colormap'), request.GET.get('maxvalue')) return render_to_response( 'visualization/legend_shapedata_grid.html', template_variables) except PresentationLayer.DoesNotExist: pass # No, it's not, continue in the old way shapedatalegend = get_object_or_404( ShapeDataLegend, pk=request.GET['object_id']) geo_type = shapedatalegend.presentationtype.geo_type if geo_type == PresentationType.GEO_TYPE_POINT: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response('visualization/legend_shapedata_point.html', {'title': title, 'blocks': blocks}) elif geo_type == PresentationType.GEO_TYPE_LINE: if shapedatalegend.id in [20]: legend_data = [(100, '005bff'), (500, '00ebff'), (1000, '4dff00'), (5000, 'fff100'), (20000, 'ff4100')] return render_to_response( 'visualization/legend_shapedata_grid.html', {'title': shapedatalegend.name, 'content': legend_data}) else: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response( 'visualization/legend_shapedata_point.html', {'title': title, 'blocks': blocks}) elif geo_type == PresentationType.GEO_TYPE_POLYGON: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response('visualization/legend_shapedata_point.html', {'title': title, 'blocks': blocks}) elif geo_type in (PresentationType.GEO_TYPE_GRID, PresentationType.GEO_TYPE_PYRAMID): try: pl = get_object_or_404( PresentationLayer, pk=request.GET['presentationlayer_id']) file_location = ( pl.presentationgrid.png_default_legend.file_location) file_folder = file_location[:file_location.rfind('\\')] color_mapping = file_folder + '\colormapping.csv' f = open(external_file_location(color_mapping), 'rb') try: reader = list(csv.DictReader(f)) legend_data = [ (float(r['leftbound']), r['colour']) for r in reader] finally: f.close() except: legend_data = [] return render_to_response('visualization/legend_shapedata_grid.html', {'title': shapedatalegend.name, 'content': legend_data})
def _max_water_depth_layer(self, scenario): pl = scenario.presentationlayer.filter( presentationtype__id=PRESENTATIONTYPE_MAX_WATERDEPTH)[0] result = pyramids.get_result_by_presentationlayer(pl) if result is not None and result.raster: return result.raster.layer
def service_get_presentationlayer_settings( request, pl_id): """get_settings of presentationlayer return: overlaytype: presentationtype_overlaytype - integer - (wms, map, general, (point, line)) type: presentationtype_valuetype - integer - (timeserie, classification, singlevalue, static) has_value_source (kan ik waarden of grafieken van een punt opvragen??) legend: array of legends with: id: name: in case of default: dtype (0=personal default, 1=project default, 2=presentationType default) in case of grid: extent (in original srid) - north, south, west,east srid nrrows nrcols gridsize in case of animation: firstnr (nr first timestep) startnr (where default starts the animation slider) lastnr (nr last timestep) dt (delta time between timesteps) in case of classification: firstnr (nr first class) startnr (default class, which is first showed when ) lastnr (nr last timestep) array of class boundaries voor resultaten met figuren, haalt afmetingen en extents op """ pl = get_object_or_404(PresentationLayer, pk=pl_id) pm = PermissionManager(request.user) if not pm.check_permission( pl, PermissionManager.PERMISSION_PRESENTATIONLAYER_VIEW): raise Http404 result = pyramids.get_result_by_presentationlayer(pl) if result is not None and result.animation: return JSONResponse( pyramids.settings_for_animation( result.animation, result.scenario)) rec = {} if pl.presentationtype.geo_type == PresentationType.GEO_TYPE_GRID: try: pl.presentationgrid except PresentationGrid.DoesNotExist: return JSONResponse({}) rec['bounds'] = {} rec['bounds']['projection'] = pl.presentationgrid.bbox_orignal_srid extent = pl.presentationgrid.extent.extent if pl.presentationgrid.bbox_orignal_srid == 28992: (rec['bounds']['south'], rec['bounds']['west'], rec['bounds']['north'], rec['bounds']['east']) = extent rec['bounds']['projection'] = 28992 else: (rec['bounds']['west'], rec['bounds']['south'], rec['bounds']['east'], rec['bounds']['north']) = extent rec['bounds']['projection'] = 4326 rec['height'] = pl.presentationgrid.rownr rec['width'] = pl.presentationgrid.colnr rec['gridsize'] = pl.presentationgrid.gridsize anim = {} if (pl.presentationtype.value_type == PresentationType.VALUE_TYPE_TIME_SERIE): anim['firstnr'] = pl.animation.firstnr anim['lastnr'] = pl.animation.lastnr anim['options'] = {} anim['options']['startnr'] = pl.animation.startnr if (pl.animation.delta_timestep > 0): anim['options']['delta'] = pl.animation.delta_timestep * 24 * 3600 legends = pm.get_legends(pl) legend_objects = [{'id': l.id, 'name': l.name} for l in legends] default_legend = ShapeDataLegend.objects.get( pk=pl.presentationtype.default_legend_id) log.debug('got default legend') info = {} info['rec'] = rec info['anim'] = anim info['legends'] = legend_objects info['default_legend'] = { 'id': default_legend.id, 'name': default_legend.name } if ((pl.presentationtype.value_type == PresentationType.VALUE_TYPE_TIME_SERIE) and pl.presentationtype.geo_type in [ PresentationType.GEO_TYPE_POLYGON, PresentationType.GEO_TYPE_LINE, PresentationType.GEO_TYPE_POINT]): anim['lastnr'] = pl.animation.lastnr pass log.debug('json dump van info') log.debug(json.dumps(info)) return JSONResponse(info)
def service_get_presentationlayer_settings(request, pl_id): """get_settings of presentationlayer return: overlaytype: presentationtype_overlaytype - integer - (wms, map, general, (point, line)) type: presentationtype_valuetype - integer - (timeserie, classification, singlevalue, static) has_value_source (kan ik waarden of grafieken van een punt opvragen??) legend: array of legends with: id: name: in case of default: dtype (0=personal default, 1=project default, 2=presentationType default) in case of grid: extent (in original srid) - north, south, west,east srid nrrows nrcols gridsize in case of animation: firstnr (nr first timestep) startnr (where default starts the animation slider) lastnr (nr last timestep) dt (delta time between timesteps) in case of classification: firstnr (nr first class) startnr (default class, which is first showed when ) lastnr (nr last timestep) array of class boundaries voor resultaten met figuren, haalt afmetingen en extents op """ pl = get_object_or_404(PresentationLayer, pk=pl_id) pm = PermissionManager(request.user) if not pm.check_permission( pl, PermissionManager.PERMISSION_PRESENTATIONLAYER_VIEW): raise Http404 result = pyramids.get_result_by_presentationlayer(pl) if result is not None and result.animation: return JSONResponse( pyramids.settings_for_animation(result.animation, result.scenario)) rec = {} if pl.presentationtype.geo_type == PresentationType.GEO_TYPE_GRID: try: pl.presentationgrid except PresentationGrid.DoesNotExist: return JSONResponse({}) rec['bounds'] = {} rec['bounds']['projection'] = pl.presentationgrid.bbox_orignal_srid extent = pl.presentationgrid.extent.extent if pl.presentationgrid.bbox_orignal_srid == 28992: (rec['bounds']['south'], rec['bounds']['west'], rec['bounds']['north'], rec['bounds']['east']) = extent rec['bounds']['projection'] = 28992 else: (rec['bounds']['west'], rec['bounds']['south'], rec['bounds']['east'], rec['bounds']['north']) = extent rec['bounds']['projection'] = 4326 rec['height'] = pl.presentationgrid.rownr rec['width'] = pl.presentationgrid.colnr rec['gridsize'] = pl.presentationgrid.gridsize anim = {} if (pl.presentationtype.value_type == PresentationType.VALUE_TYPE_TIME_SERIE): anim['firstnr'] = pl.animation.firstnr anim['lastnr'] = pl.animation.lastnr anim['options'] = {} anim['options']['startnr'] = pl.animation.startnr if (pl.animation.delta_timestep > 0): anim['options']['delta'] = pl.animation.delta_timestep * 24 * 3600 legends = pm.get_legends(pl) legend_objects = [{'id': l.id, 'name': l.name} for l in legends] default_legend = ShapeDataLegend.objects.get( pk=pl.presentationtype.default_legend_id) log.debug('got default legend') info = {} info['rec'] = rec info['anim'] = anim info['legends'] = legend_objects info['default_legend'] = { 'id': default_legend.id, 'name': default_legend.name } if ((pl.presentationtype.value_type == PresentationType.VALUE_TYPE_TIME_SERIE) and pl.presentationtype.geo_type in [ PresentationType.GEO_TYPE_POLYGON, PresentationType.GEO_TYPE_LINE, PresentationType.GEO_TYPE_POINT ]): anim['lastnr'] = pl.animation.lastnr pass log.debug('json dump van info') log.debug(json.dumps(info)) return JSONResponse(info)
def legend_shapedata(request): """Draws a ShapeDataLegend input: GET['object_id']: ShapeDataLegend.id output: png image of the legend """ ## FIRST check if this is a new style grid, with dynamic legend presentationlayer_id = request.GET.get('presentationlayer_id') # Hack -- object_id really means legend id, but sometimes the # presentationlayer_id is passed in that way (because I do that # explictly in NPyramidOverlay.js, but I don't know why # presentationlayer_id isn't passed in in the first place) if presentationlayer_id is None: presentationlayer_id = request.GET.get('object_id') if presentationlayer_id: try: presentationlayer = PresentationLayer.objects.get( pk=presentationlayer_id) result = pyramids.get_result_by_presentationlayer( presentationlayer) if result: # Handle these elsewhere, dynamic template_variables = pyramids.result_legend( result, presentationlayer, request.GET.get('colormap'), request.GET.get('maxvalue')) return render_to_response( 'visualization/legend_shapedata_grid.html', template_variables) except PresentationLayer.DoesNotExist: pass # No, it's not, continue in the old way shapedatalegend = get_object_or_404(ShapeDataLegend, pk=request.GET['object_id']) geo_type = shapedatalegend.presentationtype.geo_type if geo_type == PresentationType.GEO_TYPE_POINT: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response('visualization/legend_shapedata_point.html', { 'title': title, 'blocks': blocks }) elif geo_type == PresentationType.GEO_TYPE_LINE: if shapedatalegend.id in [20]: legend_data = [(100, '005bff'), (500, '00ebff'), (1000, '4dff00'), (5000, 'fff100'), (20000, 'ff4100')] return render_to_response( 'visualization/legend_shapedata_grid.html', { 'title': shapedatalegend.name, 'content': legend_data }) else: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response( 'visualization/legend_shapedata_point.html', { 'title': title, 'blocks': blocks }) elif geo_type == PresentationType.GEO_TYPE_POLYGON: sm = SymbolManager(settings.SYMBOLS_DIR) mpl = MapnikPointLegend(shapedatalegend, sm) title, blocks = mpl.get_legend_data() return render_to_response('visualization/legend_shapedata_point.html', { 'title': title, 'blocks': blocks }) elif geo_type in (PresentationType.GEO_TYPE_GRID, PresentationType.GEO_TYPE_PYRAMID): try: pl = get_object_or_404(PresentationLayer, pk=request.GET['presentationlayer_id']) file_location = ( pl.presentationgrid.png_default_legend.file_location) file_folder = file_location[:file_location.rfind('\\')] color_mapping = file_folder + '\colormapping.csv' f = open(external_file_location(color_mapping), 'rb') try: reader = list(csv.DictReader(f)) legend_data = [(float(r['leftbound']), r['colour']) for r in reader] finally: f.close() except: legend_data = [] return render_to_response('visualization/legend_shapedata_grid.html', { 'title': shapedatalegend.name, 'content': legend_data })