def _get_water_depth_extent(self, scenario): pl = scenario.presentationlayer.filter( presentationtype__id=PRESENTATIONTYPE_MAX_WATERDEPTH)[0] png = pl.presentationgrid.png_default_legend.file_location png = external_file_location(png) return json.dumps(geo.GeoImage(png).extent())
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 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 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 legend_shapedata(request): """Draws a ShapeDataLegend input: GET['object_id']: ShapeDataLegend.id output: png image of the legend """ 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 == PresentationType.GEO_TYPE_GRID: 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})