Exemple #1
0
def lithology_geojson(request, **kwargs):
    realtime = request.GET.get('realtime') in ('True', 'true')
    if realtime:
        sw_long = request.query_params.get('sw_long')
        sw_lat = request.query_params.get('sw_lat')
        ne_long = request.query_params.get('ne_long')
        ne_lat = request.query_params.get('ne_lat')
        bounds = None
        bounds_sql = ''

        if sw_long and sw_lat and ne_long and ne_lat:
            bounds_sql = 'and geom @ ST_MakeEnvelope(%s, %s, %s, %s, 4326)'
            bounds = (sw_long, sw_lat, ne_long, ne_lat)

        iterator = GeoJSONIterator(LITHOLOGY_SQL.format(bounds=bounds_sql),
                                   LITHOLOGY_CHUNK_SIZE, connection.cursor(),
                                   bounds)
        response = StreamingHttpResponse((item for item in iterator),
                                         content_type='application/json')
        response[
            'Content-Disposition'] = 'attachment; filename="lithology.json"'
        return response
    else:
        # Generating spatial data realtime is much too slow,
        # so we have to redirect to a pre-generated instance.
        url = 'https://{}/{}/{}'.format(
            get_env_variable('S3_HOST'),
            get_env_variable('S3_WELL_EXPORT_BUCKET'),
            'api/v1/gis/lithology.json')
        return HttpResponseRedirect(url)
Exemple #2
0
def aquifer_geojson_v2(request, **kwargs):
    realtime = request.GET.get('realtime') in ('True', 'true')
    if realtime:

        sw_long = request.query_params.get('sw_long')
        sw_lat = request.query_params.get('sw_lat')
        ne_long = request.query_params.get('ne_long')
        ne_lat = request.query_params.get('ne_lat')

        if sw_long and sw_lat and ne_long and ne_lat:
            bounds_sql = 'and geom @ ST_Transform(ST_MakeEnvelope(%s, %s, %s, %s, 4326), 3005)'
            bounds = (sw_long, sw_lat, ne_long, ne_lat)
        else:
            bounds = None
            bounds_sql = ''

        iterator = GeoJSONIterator(AQUIFERS_SQL_V2.format(bounds=bounds_sql),
                                   AQUIFER_CHUNK_SIZE, connection.cursor(),
                                   bounds)
        response = StreamingHttpResponse((item for item in iterator),
                                         content_type='application/json')
        response[
            'Content-Disposition'] = 'attachment; filename="aquifers.json"'
        return response
    else:
        # TODO: Update export_databc command to upload a v2 version of the aquifers JSON:
        # https://apps.nrs.gov.bc.ca/int/jira/browse/WATER-1049
        # Generating spatial data realtime is much too slow,
        # so we have to redirect to a pre-generated instance.
        url = 'https://{}/{}/{}'.format(
            get_env_variable('S3_HOST'),
            get_env_variable('S3_WELL_EXPORT_BUCKET'),
            'api/v1/gis/aquifers.json')
        return HttpResponseRedirect(url)
Exemple #3
0
def aquifer_geojson_simplified(request, **kwargs):
    """
    Sadly, GeoDjango's ORM doesn't seem to directly support a call to
    ST_AsGEOJSON, but the latter performs much better than processing WKT
    in Python, so we must generate SQL here.
    """

    SQL = """
    SELECT
           ST_AsGeoJSON(geom_simplified, 8) :: json AS "geometry",
           aquifer.aquifer_id                       AS id
    FROM aquifer;
    """

    iterator = GeoJSONIterator(SQL, AQUIFER_CHUNK_SIZE, connection.cursor())
    response = StreamingHttpResponse((item for item in iterator),
                                     content_type='application/json')
    return response
Exemple #4
0
def aquifer_geojson_simplified_v1(request, **kwargs):
    """
    Sadly, GeoDjango's ORM doesn't seem to directly support a call to
    ST_AsGEOJSON, but the latter performs much better than processing WKT
    in Python, so we must generate SQL here.
    """

    sql = """
    SELECT
        ST_AsGeoJSON((ST_GeometryN(geom_simplified, 1)), 8) :: json AS "geometry",
        aquifer.aquifer_id AS id
    FROM aquifer
    """

    if not request.user.groups.filter(name=AQUIFERS_EDIT_ROLE).exists():
        sql += "WHERE effective_date <= NOW() AND expiry_date >= NOW() AND retire_date >= NOW()"

    iterator = GeoJSONIterator(sql, AQUIFER_CHUNK_SIZE, connection.cursor())
    response = StreamingHttpResponse((item for item in iterator),
                                     content_type='application/json')
    return response