Esempio n. 1
0
    def read(self, obj):
        tree = parse(obj)
        if tree is not None:
            root = tree.getroot()
            root_ns = root.nsmap[root.prefix]
            use_21 = root_ns in namespaces_21
            decoder = EOOMFormatDecoder(tree, use_21)

            metadata_type = None

            if root_ns in (NS_OPT_20, NS_OPT_21):
                metadata_type = "OPT"
            # TODO: fixme
            # elif root_ns in (NS_ALT_20, NS_ALT_21):
            #     metadata_type = "ALT"
            elif root_ns in (NS_SAR_20, NS_SAR_21):
                metadata_type = "SAR"

            return {
                "identifier": decoder.identifier,
                "begin_time": decoder.begin_time,
                "end_time": decoder.end_time,
                "footprint": MultiPolygon(*decoder.polygons),
                "format": "eogml",
                "metadata": to_dict(EOOMExtraMetadataDecoder(tree, use_21)),
                # "product_metadata": to_dict(
                #     EOOMProductMetadataDecoder(tree, use_21)
                # ),
                # "metadata_type": metadata_type
            }

        raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 2
0
 def test(self, obj):
     tree = parse(obj)
     return (
         tree is not None
         and tree.find("siteName") is not None
         and tree.find("siteLongitude") is not None
         and tree.find("siteLatitude") is not None
         and tree.find("siteElevation") is not None
     )
Esempio n. 3
0
 def test(self, obj):
     tree = parse(obj)
     if tree is None:
         return False
     ename = etree.QName(tree.find('.').tag)
     return (
         ename.localname == "EarthObservation"
         and ename.namespace in NS_EOP_ALL
     )
Esempio n. 4
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = EOOMFormatDecoder(tree)
         return {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": MultiPolygon(*decoder.polygons),
             "format": "eogml"
         }
     raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 5
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = InspireFormatDecoder(tree)
         return {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": decoder.footprint,
             "format": "inspire"
         }
     raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 6
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = GSCFormatDecoder(tree)
         return {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": decoder.footprint,
             "format": "gsc"
         }
     raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 7
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = NativeFormatDecoder(tree)
         return {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": MultiPolygon(*decoder.polygons),
             "format": "native"
         }
     raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 8
0
    def read(self, obj):
        tree = parse(obj)
        if self.test(tree):
            version = tree.xpath(
                "Metadadata_Id/METADATA_FORMAT/"
                "|Metadata_Identification/METADATA_FORMAT"
            )[0].get("version", "1.1")
            if version.startswith("1.1"):
                decoder = DimapGeneralFormat11Decoder(tree)
            elif version.startswith("2.0"):
                decoder = DimapGeneralFormat20Decoder(tree)
            else:
                raise Exception(
                    "DIMAP version '%s' is not supported." % version
                )

            values = {
                "identifier": decoder.identifier,
                "format": "dimap"
            }

            # in Dimap, pretty much everything is optional
            def cond_set(dct, key, value):
                if value is not None:
                    dct[key] = value

            # decode
            begin_time = decoder.begin_time
            end_time = decoder.end_time
            footprint = decoder.footprint
            projection = decoder.projection
            size = decoder.size
            gt = decoder.geotransform

            # calculate extent
            extent = None
            if size and gt:
                extent = (
                    gt[0], gt[3], gt[0] + gt[1] * size[0], gt[3] + gt[5] * size[1]
                )

            # set values
            cond_set(values, "begin_time", begin_time)
            cond_set(values, "end_time", begin_time)
            cond_set(values, "footprint", begin_time)
            cond_set(values, "size", begin_time)
            cond_set(values, "extent", begin_time)
            cond_set(values, "projection", begin_time)

            return values

        raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 9
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = GSCFormatDecoder(tree)
         values = {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": decoder.footprint,
             "format": "gsc",
         }
         values.update(to_dict(GSCFormatExtendedDecoder(tree)))
         return values
Esempio n. 10
0
 def read(self, obj):
     tree = parse(obj)
     if tree is not None:
         decoder = EOOMFormatDecoder(tree)
         return {
             "identifier": decoder.identifier,
             "begin_time": decoder.begin_time,
             "end_time": decoder.end_time,
             "footprint": decoder.footprint,
             "vmasks": [v for v in decoder.vmasks if v is not None],
             "format": "eogml"
         }
     raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 11
0
    def read(self, obj):
        tree = parse(obj)
        if self.test(tree):
            version = tree.xpath(
                "Metadadata_Id/METADATA_FORMAT/"
                "|Metadata_Identification/METADATA_FORMAT")[0].get(
                    "version", "1.1")
            if version.startswith("1.1"):
                decoder = DimapGeneralFormat11Decoder(tree)
            elif version.startswith("2.0"):
                decoder = DimapGeneralFormat20Decoder(tree)
            else:
                raise Exception("DIMAP version '%s' is not supported." %
                                version)

            values = {"identifier": decoder.identifier, "format": "dimap"}

            # in Dimap, pretty much everything is optional
            def cond_set(dct, key, value):
                if value is not None:
                    dct[key] = value

            # decode
            begin_time = decoder.begin_time
            end_time = decoder.end_time
            footprint = decoder.footprint
            projection = decoder.projection
            size = decoder.size
            gt = decoder.geotransform

            # calculate extent
            extent = None
            if size and gt:
                extent = (gt[0], gt[3], gt[0] + gt[1] * size[0],
                          gt[3] + gt[5] * size[1])

            # set values
            cond_set(values, "begin_time", begin_time)
            cond_set(values, "end_time", begin_time)
            cond_set(values, "footprint", begin_time)
            cond_set(values, "size", begin_time)
            cond_set(values, "extent", begin_time)
            cond_set(values, "projection", begin_time)

            return values

        raise Exception("Could not parse from obj '%s'." % repr(obj))
Esempio n. 12
0
    def read(self, obj):
        tree = parse(obj)
        if self.test(tree):
            decoder = SiteFormatDecoder(tree)
            location = Point(decoder.longitude, decoder.latitude)

            return {
                "identifier": decoder.identifier,
                "location": location,
                "footprint": MultiPolygon(location.buffer(0.01)),
                "elevation": decoder.elevation,
                "coverage_type": "",
                "size": (decoder.size, 1),
                "projection": 4326,
                "begin_time": min(decoder.start_times),
                "end_time": max(decoder.end_times),
                "extent": (0, 0, 1, 1),
                "coverage_type": "dav_prc.models.SiteDataset",
            }
        raise Exception("Could not parse from obj '%r'." % obj)
Esempio n. 13
0
    def read(self, obj):
        tree = parse(obj)
        if self.test(tree):
            decoder = SiteFormatDecoder(tree)
            location = Point(decoder.longitude, decoder.latitude)

            return {
                "identifier": decoder.identifier,
                "location": location,
                "footprint": MultiPolygon(location.buffer(0.01)),
                "elevation": decoder.elevation,
                "coverage_type": "",
                "size": (decoder.size, 1),
                "projection": 4326,
                "begin_time": min(decoder.start_times),
                "end_time": max(decoder.end_times),
                "extent": (0, 0, 1, 1),
                "coverage_type": "dav_prc.models.SiteDataset"
            }
        raise Exception("Could not parse from obj '%r'." % obj)
Esempio n. 14
0
 def test(self, obj):
     tree = parse(obj)
     tag = tree.getroot().tag if tree is not None else None
     return tree is not None and tag in [
         ns('EarthObservation') for ns in namespaces_20 + namespaces_21
     ]
Esempio n. 15
0
    def test(self, obj):
        tree = parse(obj)

        tag = tree.getroot().tag if tree is not None else None
        return tree is not None and tag == NS_GSC('report')
Esempio n. 16
0
 def test(self, obj):
     xml = parse(obj)
     return xml is not None and xml.getroot().tag == "Metadata"
Esempio n. 17
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.getroot().tag == NS_EOP("EarthObservation")
Esempio n. 18
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.getroot().tag == NS_GSC("report")
Esempio n. 19
0
 def get_ids(self, response):
     root = parse(response.content).getroot()
     return root.xpath('atom:entry/atom:id/text()',
                       namespaces={'atom': 'http://www.w3.org/2005/Atom'})
Esempio n. 20
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.getroot().tag == "Dimap_Document"
Esempio n. 21
0
def create_rectified_vrt(path_or_ds,
                         vrt_path,
                         srid_or_wkt=None,
                         resample=0,
                         memory_limit=0.0,
                         max_error=APPROX_ERR_TOL,
                         method=METHOD_GCP,
                         order=0,
                         size=None,
                         resolution=None):
    """ Creates a VRT dataset that symbolizes a rectified version of the
    passed "referenceable" GDAL dataset.

    :param path_or_ds: a :class:`GDAL Dataset <eoxserver.contrib.gdal.Dataset>`
                       or a path to such
    :param vrt_path: the path to store the VRT dataset under

    :param resample: the resample method to be used; defaults to 0 which means
                     a nearest neighbour resampling
    :param memory_limit: the memory limit; by default no limit is used
    :param max_error: the maximum allowed error
    :param method: either of :const:`METHOD_GCP`, :const:`METHOD_TPS` or
                   :const:`METHOD_TPS_LSQ`.
    :param order: the order of the function; see :func:`get_footprint_wkt` for
                  reference
    """

    if size and resolution:
        raise ValueError('size and resolution ar mutually exclusive')

    ds = _open_ds(path_or_ds)
    ptr = C.c_void_p(int(ds.this))

    if isinstance(srid_or_wkt, int):
        srs = osr.SpatialReference()
        srs.ImportFromEPSG(srid_or_wkt)
        wkt = srs.ExportToWkt()
        srs = None
    elif isinstance(srid_or_wkt, str):
        wkt = srid_or_wkt
    else:
        wkt = ds.GetGCPProjection()

    # transformer = _create_generic_transformer(
    #     ds, None, None, wkt, method, order
    # )

    # x_size = C.c_int()
    # y_size = C.c_int()
    # geotransform = (C.c_double * 6)()

    # GDALSuggestedWarpOutput(
    #     ptr,
    #     GDALGenImgProjTransform, transformer, geotransform,
    #     C.byref(x_size), C.byref(y_size)
    # )

    # GDALSetGenImgProjTransformerDstGeoTransform(transformer, geotransform)

    # options = GDALCreateWarpOptions()
    # options.dfWarpMemoryLimit = memory_limit
    # options.eResampleAlg = resample
    # options.pfnTransformer = GDALGenImgProjTransform
    # options.pTransformerArg = transformer
    # options.hDstDS = C.c_void_p(int(ds.this))

    # nb = options.nBandCount = ds.RasterCount

    # src_bands = C.cast(CPLMalloc(C.sizeof(C.c_int) * nb), C.POINTER(C.c_int))
    # dst_bands = C.cast(CPLMalloc(C.sizeof(C.c_int) * nb), C.POINTER(C.c_int))

    # # ctypes.cast(x, ctypes.POINTER(ctypes.c_ulong))

    # options.panSrcBands = src_bands
    # options.panDstBands = dst_bands

    # # TODO: nodata value setup
    # for i in xrange(nb):
    #     options.panSrcBands[i] = i + 1
    #     options.panDstBands[i] = i + 1

    # if max_error > 0:
    #     GDALApproxTransform = _libgdal.GDALApproxTransform

    #     options.pTransformerArg = GDALCreateApproxTransformer(
    #         options.pfnTransformer, options.pTransformerArg, max_error
    #     )
    #     options.pfnTransformer = GDALApproxTransform
    # TODO: correct for python
    #GDALApproxTransformerOwnsSubtransformer(options.pTransformerArg, False)

    # if size:
    #     extent = _to_extent(x_size.value, y_size.value, geotransform)
    #     size_x, size_y = size
    #     x_size.value = size_x
    #     y_size.value = size_y
    #     geotransform = _to_gt(size[0], size[1], extent)

    # elif resolution:
    #     extent = _to_extent(x_size.value, y_size.value, geotransform)

    #     geotransform[1] = resolution[0]
    #     geotransform[5] = resolution[1]

    #     size_x, size_y = _to_size(geotransform, extent)
    #     x_size.value = size_x
    #     y_size.value = size_y

    # vrt_ds = GDALCreateWarpedVRT(ptr, x_size, y_size, geotransform, options)
    if isinstance(wkt, str):
        wkt = b(wkt)
    vrt_ds = GDALAutoCreateWarpedVRT(ptr, None, wkt, resample, max_error, None)
    # GDALSetProjection(vrt_ds, wkt)
    if isinstance(vrt_path, str):
        vrt_path = b(vrt_path)

    GDALSetDescription(vrt_ds, vrt_path)
    GDALClose(vrt_ds)
    # GDALDestroyWarpOptions(options)

    # if size of resolution is overridden parse the VRT and adjust settings
    if size or resolution:
        with vsi.open(vrt_path) as f:
            root = parse(f).getroot()

        size_x = int(root.attrib['rasterXSize'])
        size_y = int(root.attrib['rasterYSize'])
        gt_elem = root.find('GeoTransform')

        gt = [
            float(value.strip()) for value in gt_elem.text.strip().split(',')
        ]

        if size:
            extent = _to_extent(size_x, size_y, gt)
            size_x, size_y = size
            gt = _to_gt(size[0], size[1], extent)

        elif resolution:
            extent = _to_extent(size_x, size_y, gt)

            gt[1] = resolution[0]
            gt[5] = resolution[1]

            size_x, size_y = _to_size(gt, extent)

        # Adjust XML
        root.attrib['rasterXSize'] = str(size_x)
        root.attrib['rasterYSize'] = str(size_y)

        gt_str = ",".join(str(v) for v in gt)
        gt_elem.text = gt_str
        root.find('GDALWarpOptions/Transformer/ApproxTransformer/'
                  'BaseTransformer/GenImgProjTransformer/DstGeoTransform'
                  ).text = gt_str

        inv_gt = gdal.InvGeoTransform(gt)
        root.find('GDALWarpOptions/Transformer/ApproxTransformer/'
                  'BaseTransformer/GenImgProjTransformer/DstInvGeoTransform'
                  ).text = ",".join(str(v) for v in inv_gt)

        # write XML back to file
        with vsi.open(vrt_path, "w") as f:
            f.write(etree.tostring(root, pretty_print=True))
Esempio n. 22
0
 def test(self, obj):
     xml = parse(obj)
     return xml is not None and xml.tag == "Metadata"
Esempio n. 23
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.getroot().tag == NS_GMD("MD_Metadata")
Esempio n. 24
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.getroot().tag == "Dimap_Document"
Esempio n. 25
0
 def test(self, obj):
     tree = parse(obj)
     return tree is not None and tree.tag == NS_EOP("EarthObservation")
Esempio n. 26
0
 def test(self, obj):
     tree = parse(obj)
     return (tree is not None and tree.find("siteName") is not None
             and tree.find("siteLongitude") is not None
             and tree.find("siteLatitude") is not None
             and tree.find("siteElevation") is not None)