def boundary_layer_detail(request, table_code, obj_id): geojson = get_layer_shape(table_code, obj_id) if geojson: return Response(json.loads(geojson)) else: return Response(status=status.HTTP_404_NOT_FOUND)
def to_internal_value(self, data): """ If the input has an 'area_of_interest' key, return 'area_of_interest' to its validated, geojson string representation, and 'wkaoi' as None. If the input has a 'wkaoi' key, its shape is pulled from the appropriate database, and returned as 'area_of_interest' with the value of 'wkaoi' returned unchanged. If the input has a 'huc' key, then we use it to look up the 'wkaoi'. Args: data: Only one of the keys is necessary { 'area_of_interest': { <geojson dict or string> } 'wkaoi': '{table}__{id}', 'huc': '<huc8, huc10, or huc12 id>', } """ wkaoi = data.get('wkaoi', None) huc = data.get('huc', None) aoi = data.get('area_of_interest', None) if (not aoi and not wkaoi and not huc): raise ValidationError(detail='Must supply exactly one of: ' + 'the area of interest (GeoJSON), ' + 'a WKAoI ID, or a HUC.') if (huc and not wkaoi): wkaoi = wkaoi_from_huc(huc) if (wkaoi and not aoi): try: table, id = wkaoi.split('__') except Exception: raise ValidationError('wkaoi must be of the form table__id') aoi = get_layer_shape(table, id) if (not aoi): raise ValidationError(detail=f'Invalid wkaoi: {wkaoi}') huc = aoi['properties'].get('huc') aoi_field = MultiPolygonGeoJsonField().to_internal_value(aoi) return { 'area_of_interest': aoi_field, 'wkaoi': wkaoi, 'huc': huc, }
def to_internal_value(self, data): """ If the input has an 'area_of_interest' key, return 'area_of_interest' to its validated, geojson string representation, and 'wkaoi' as None. If the input has a 'wkaoi' key, its shape is pulled from the appropriate database, and returned as 'area_of_interest' with the value of 'wkaoi' returned unchanged. Args: data: Only one of the keys is necessary { 'area_of_interest': { <geojson dict or string> } 'wkaoi': '{table}__{id}', } """ wkaoi = data.get('wkaoi', None) aoi = data.get('area_of_interest', None) if (not aoi and not wkaoi): raise ValidationError(detail='Must supply either ' + 'the area of interest (GeoJSON), ' + 'or a WKAoI ID.') if (wkaoi and not aoi): try: table, id = wkaoi.split('__') except: raise ValidationError('wkaoi must be of the form table__id') aoi = get_layer_shape(table, id) if (not aoi): raise ValidationError(detail='Invalid wkaoi: {}'.format(wkaoi)) aoi_field = MultiPolygonGeoJsonField().to_internal_value(aoi) return { 'area_of_interest': aoi_field, 'wkaoi': wkaoi }