예제 #1
0
def handler(path):
    try:
        # Returns metadata for girder to save it on the file model
        metadata = {}
        metadata['type_'] = 'vector'
        dataset = ogr.Open(path)
        if not dataset:
            raise CannotHandleError()
        metadata['driver'] = dataset.GetDriver().GetName()
        metadata['layers'] = dataset.GetLayerCount()
        metadata['layerInfo'] = get_layers(dataset)
        layerBounds = [Polygon.from_bounds(i['nativeBounds']['left'],
                                           i['nativeBounds']['bottom'],
                                           i['nativeBounds']['right'],
                                           i['nativeBounds']['top'])
                       for i in metadata['layerInfo']]
        union = unary_union(layerBounds)
        layer = dataset.GetLayer(0)
        crs = layer.GetSpatialRef().ExportToProj4()
        bounds = {'left': union.bounds[0], 'right': union.bounds[2],
                  'bottom': union.bounds[1], 'top': union.bounds[3]}
        metadata['crs'] = crs
        metadata['nativeBounds'] = bounds
        metadata['type_'] = 'vector'
        metadata['bounds'] = from_bounds_to_geojson(bounds, crs)

        schema = VectorSchema()
        return schema.load(metadata)
    except AttributeError:
        raise CannotHandleError('Ogr could not open dataset')
예제 #2
0
def handler(path):
    try:
        # Returns metadata for girder to save it on the file model
        metadata = {}
        metadata['type_'] = 'raster'

        dataset = gdal.Open(path)
        if dataset.GetSubDatasets():
            raise CannotHandleError('Cannot handle this data type')

        crs = get_projection_as_proj4(dataset)
        bounds = get_bounds(dataset)

        metadata['crs'] = crs
        metadata['bands'] = dataset.RasterCount
        metadata['bandInfo'] = get_band_info(dataset)
        metadata['affine'] = list(dataset.GetGeoTransform())
        metadata['width'] = dataset.RasterXSize
        metadata['height'] = dataset.RasterYSize
        metadata['driver'] = dataset.GetDriver().LongName
        metadata['nativeBounds'] = bounds
        metadata['bounds'] = from_bounds_to_geojson(bounds, crs)
        schema = RasterSchema()
        try:
            return schema.load(metadata)
        except ValidationError as e:
            raise CannotHandleError(e.messages)
    except AttributeError:
        raise CannotHandleError('Gdal could not open dataset')
예제 #3
0
def sampleBounds():
    crs = '+proj=utm +zone=10 +datum=WGS84 +units=m +no_defs '
    nativeBounds = {
        'left': 271785.000,
        'bottom': 4345785.000,
        'right': 506715.000,
        'top': 4584315.000
    }
    return from_bounds_to_geojson(nativeBounds, crs)
예제 #4
0
def get_layer_info(layer):
    metadata = {}
    extent = layer.GetExtent()
    crs = layer.GetSpatialRef().ExportToProj4()
    bounds = {'left': extent[0], 'right': extent[1],
              'bottom': extent[2], 'top': extent[3]}
    metadata['crs'] = crs
    metadata['nativeBounds'] = bounds
    metadata['type_'] = 'vector'
    metadata['bounds'] = from_bounds_to_geojson(bounds, crs)
    metadata['featureCount'] = layer.GetFeatureCount()
    definition = layer.GetLayerDefn()
    count = definition.GetFieldCount()
    metadata['geomType'] = ogr.GeometryTypeToName(definition.GetGeomType())
    metadata['layerFields'] = [get_field_info(definition.GetFieldDefn(i)) for i in range(count)]
    return metadata
예제 #5
0
def get_subdataset_info(subDataset):
    dataset = gdal.Open(subDataset)

    crs = get_projection_as_proj4(
        dataset) or '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs '
    metadata = {}
    bounds = get_bounds(dataset)
    metadata['crs'] = crs
    metadata['type_'] = 'grid'
    metadata['name'] = dataset.GetDescription()
    metadata['driver'] = dataset.GetDriver().LongName
    metadata['nativeBounds'] = bounds
    metadata['bounds'] = from_bounds_to_geojson(bounds, crs)
    metadata['affine'] = list(dataset.GetGeoTransform())
    metadata['width'] = dataset.RasterXSize
    metadata['height'] = dataset.RasterYSize

    return metadata
예제 #6
0
def handler(path):
    # Returns metadata for girder to save it on the file model
    metadata = {}
    metadata['type_'] = 'raster'

    dataset = gdal.Open(path)
    crs = get_projection_as_proj4(dataset)
    bounds = get_bounds(dataset)

    metadata['crs'] = crs
    metadata['bands'] = dataset.RasterCount
    metadata['bandInfo'] = get_band_info(dataset)
    metadata['affine'] = list(dataset.GetGeoTransform())
    metadata['width'] = dataset.RasterXSize
    metadata['height'] = dataset.RasterYSize
    metadata['driver'] = dataset.GetDriver().LongName
    metadata['nativeBounds'] = bounds
    metadata['bounds'] = from_bounds_to_geojson(bounds, crs)
    schema = GeotiffSchema()
    return schema.load(metadata)
예제 #7
0
def handler(path):
    try:
        # Returns metadata for girder to save it on the file model
        metadata = {}
        metadata['type_'] = 'grid'
        main_dataset = gdal.Open(path)
        try:
            gdal.Open(main_dataset.GetSubDatasets()[0][0])
        except IndexError:
            raise CannotHandleError('Does not have subdatasets')
        dataset = gdal.Open(main_dataset.GetSubDatasets()[0][0])
        crs = get_projection_as_proj4(
            dataset) or '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs '
        metadata = {}
        metadata['subDatasets'] = get_subdatasets(main_dataset)
        subDatasetBounds = [
            Polygon.from_bounds(i['nativeBounds']['left'],
                                i['nativeBounds']['bottom'],
                                i['nativeBounds']['right'],
                                i['nativeBounds']['top'])
            for i in metadata['subDatasets']
        ]
        union = unary_union(subDatasetBounds)
        bounds = {
            'left': union.bounds[0],
            'right': union.bounds[2],
            'bottom': union.bounds[1],
            'top': union.bounds[3]
        }
        metadata['crs'] = crs
        metadata['type_'] = 'grid'
        metadata['driver'] = dataset.GetDriver().LongName
        metadata['nativeBounds'] = bounds
        metadata['bounds'] = from_bounds_to_geojson(bounds, crs)

        schema = GridSchema()
        return schema.load(metadata)
    except AttributeError:
        raise CannotHandleError('Gdal could not open dataset')
예제 #8
0
def handler(path, girder_item, girder_file):
    if ".obj" not in girder_file['name'] and \
            ".OBJ" not in girder_file['name']:
        raise CannotHandleError(girder_file['name'] + ' is not an OBJ file')
    try:
        jsonItem = Item().findOne({
            'name':
            girder_file['name'].replace("obj", "json"),
            'folderId':
            girder_item['folderId']
        })
        jsonFile = [i for i in Item().childFiles(jsonItem, limit=1)][0]
        jsonContent = json.loads(''.join(
            list(File().download(jsonFile, headers=False)())))
        projectionParams = jsonContent['scenes'][0]['coordinate_system'][
            'parameters']
        ellps = projectionParams[0].upper()
        m = re.compile('(utm) zone ([0-9]+)N',
                       re.IGNORECASE).match(projectionParams[1])
        proj = m.group(1).lower()
        zone = m.group(2)
        sourceSrs = Proj(proj=proj, zone=zone, ellps=ellps).srs
        offset = [
            projectionParams[2], projectionParams[3], projectionParams[4]
        ]
        bounds = getOBJBounds(path, offset)
        geoJsonBounds = from_bounds_to_geojson(bounds, sourceSrs)
        geometa = {
            'crs': sourceSrs,
            'nativeBounds': bounds,
            'bounds': geoJsonBounds,
            'type_': 'vector',
            'driver': 'OBJ'
        }
        schema = OBJSchema()
        return schema.load(geometa)
    except Exception:
        raise CannotHandleError('Failed to add geometa to OBJ file' +
                                girder_file['name'])