Beispiel #1
0
def make_pyramid(layer):
    """ Build a pyramid from a dataset. """
    logger.info('Building pyramid for {}'.format(layer))
    # Get paths
    pyramid_path = utils.get_pyramid_path(layer)
    dataset_path = utils.get_bathymetry_path(layer)
    # Create pyramid
    try:
        pyramid = rasters.Pyramid(path=pyramid_path, compression='DEFLATE')
        if pyramid.has_data():
            logger.info('Pyramid has data for {}'.format(layer))
            return
        dataset = gdal.Open(str(dataset_path))

        logger.info("Pyramid path: %r" % pyramid_path)
        logger.info("Dataset path: %r" % dataset_path)
        # it defaults to rijksdriehoek (28992)
        bathy_srs = utils.get_bathymetry_srs(dataset_path)
        logger.info("Bathy srs: %r" % bathy_srs)
        dataset.SetProjection(projections.get_wkt(bathy_srs))
        pyramid.add(dataset)
    except rasters.LockError:
        logger.info('Pyramid busy for {}'.format(layer))
        return
    logger.info('Pyramid completed for {}'.format(layer))
Beispiel #2
0
def get_response_for_getinfo(get_parameters):
    """ Return json with bounds and timesteps. """
    # Read netcdf
    path = utils.get_netcdf_path(layer=get_parameters['layers'])
    with Dataset(path) as dataset:
        v = dataset.variables
        fex, fey = v['FlowElemContour_x'][:], v['FlowElemContour_y'][:]
        timesteps = v['s1'].shape[0]
        bathymetry = v['bath'][0, :]

    limits = bathymetry.min(), bathymetry.max()
    netcdf_extent = fex.min(), fey.min(), fex.max(), fey.max()

    # Determine transformed extent
    srs = get_parameters['srs']
    if srs:
        # Read projection from bathymetry file, defaults to RD.
        bathy_path = utils.get_bathymetry_path(layer=get_parameters['layers'])
        # It defaults to Rijksdriehoek RD
        source_projection = utils.get_bathymetry_srs(bathy_path)

        logging.info('Source projection: %r' % source_projection)
        #source_projection = 22234 if 'kaapstad' in path.lower() else rasters.RD
        target_projection = srs
        extent = gislib_utils.get_transformed_extent(
            extent=netcdf_extent,
            source_projection=source_projection,
            target_projection=target_projection,
        )
    else:
        logging.warning('No srs data available.')
        extent = netcdf_extent

    # Prepare response
    content = json.dumps(dict(bounds=extent,
                              limits=limits,
                              timesteps=timesteps))
    return content, 200, {
        'content-type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET'}
Beispiel #3
0
def make_monolith(layer):
    """ Build a monolith from a netcdf. """
    logging.info('Building monolith for {}'.format(layer))
    # Get paths
    monolith_path = utils.get_monolith_path(layer)
    netcdf_path = utils.get_netcdf_path(layer)
    bathy_path = utils.get_bathymetry_path(layer)
    projection = utils.get_bathymetry_srs(bathy_path)
    #if projection is not None: 
    #    projection = int(projection)
    logging.info('Monolith projection is {}'.format(projection))
    # Create monolith
    try:
        monolith = rasters.Monolith(path=monolith_path, compression='DEFLATE')
        if monolith.has_data():
            logging.info('Monolith has data for {}'.format(layer))
            return
        monolith.add(quads.get_dataset(path=netcdf_path, projection=projection))
    except rasters.LockError:
        logging.info('Monolith busy for {}'.format(layer))
        return
    logging.info('Monolith completed for {}'.format(layer))