Exemplo n.º 1
0
    def setUp(self):
        super(GDALDatasetTestCase, self).setUp()
        _, self.tmppath = tempfile.mkstemp("." +
                                           self.getFileExtension("raster"))

        data = self.getResponseData()
        if isinstance(data, binary_type):
            mode = 'wb'
        else:
            mode = 'w'
        with open(self.tmppath, mode) as f:
            f.write(data)

        gdal.AllRegister()

        exp_path = os.path.join(self.getExpectedFileDir(),
                                self.getExpectedFileName("raster"))

        try:
            self.res_ds = gdal.Open(self.tmppath, gdal.GA_ReadOnly)
        except RuntimeError as e:
            self.fail("Response could not be opened with GDAL. Error was %s" %
                      e)

        try:
            self.exp_ds = gdal.Open(exp_path, gdal.GA_ReadOnly)
        except RuntimeError:
            self.skipTest("Expected response in '%s' is not present" %
                          exp_path)
Exemplo n.º 2
0
    def setUp(self):
        # TODO check if connection to DB server is possible
        # TODO check if datasets are configured within the DB

        gdal.AllRegister()
        if gdal.GetDriverByName("RASDAMAN") is None:
            self.skipTest("Rasdaman driver is not enabled.")

        if not self.isRequestConfigEnabled("rasdaman_enabled"):
            self.skipTest("Rasdaman tests are not enabled. Use the "
                          "configuration option 'rasdaman_enabled' to allow "
                          "rasdaman tests.")

        super(RasdamanTestCaseMixIn, self).setUp()
Exemplo n.º 3
0
    def _openDatasets(self):
        _, self.tmppath = tempfile.mkstemp("." +
                                           self.getFileExtension("raster"))
        f = open(self.tmppath, "w")
        f.write(self.getResponseData())
        f.close()
        gdal.AllRegister()

        exp_path = os.path.join(self.getExpectedFileDir(),
                                self.getExpectedFileName("raster"))

        try:
            self.res_ds = gdal.Open(self.tmppath, gdal.GA_ReadOnly)
        except RuntimeError, e:
            self.fail("Response could not be opened with GDAL. Error was %s" %
                      e)
Exemplo n.º 4
0
    def __init__(self, fname):

        # get the dataset and its params
        gdal.AllRegister()
        ds = gdal.Open(fname)

        self.fileName = fname
        self.driverName = ds.GetDriver().LongName
        self.size = (ds.RasterYSize, ds.RasterXSize, ds.RasterCount)
        self.GCPCount = ds.GetGCPCount()
        self.GCPProjection = ds.GetGCPProjection()
        self.Projection = ds.GetProjection()
        self.ProjectionRef = ds.GetProjectionRef()
        self.GeoTransform = ds.GetGeoTransform()
        self.GCP = ds.GetGCPs()
        self.isRectified = bool(self.Projection)
        self.isReferenceable = bool(self.GCPProjection) and (self.GCPCount > 0)
Exemplo n.º 5
0
    def testBinaryComparisonRaster(self):

        response_path = os.path.join(self.getResponseFileDir(),
                                     self.getResponseFileName("raster"))
        expected_path = os.path.join(self.getExpectedFileDir(),
                                     self.getExpectedFileName("raster"))
        # creates a response image that contains the encoded text of the response xml file
        doc = etree.fromstring(self.prepareXMLData(self.getXMLData()))

        try:
            encodedText = doc.xpath(
                '//wps:ComplexData',
                namespaces={'wps': 'http://www.opengis.net/wps/1.0.0'})[0].text
        except IndexError:
            self.fail('No complex data found in the XML tree')

        _, self.tmppath = tempfile.mkstemp("." +
                                           self.getFileExtension("raster"))
        with open(self.tmppath, 'wb') as f:
            f.write(b64decode(encodedText))
        gdal.AllRegister()

        exp_path = os.path.join(self.getExpectedFileDir(),
                                self.getExpectedFileName("raster"))

        try:
            self.res_ds = gdal.Open(self.tmppath, gdal.GA_ReadOnly)
        except RuntimeError as e:
            self.fail("Response could not be opened with GDAL. Error was %s" %
                      e)

        try:
            self.exp_ds = gdal.Open(expected_path, gdal.GA_ReadOnly)
        except RuntimeError:
            self.skipTest("Expected response in '%s' is not present" %
                          exp_path)

        # compare the size
        self.assertEqual((self.res_ds.RasterXSize, self.res_ds.RasterYSize),
                         (self.exp_ds.RasterXSize, self.exp_ds.RasterYSize))
        # compare the band count
        self.assertEqual(self.res_ds.RasterCount, self.exp_ds.RasterCount)
Exemplo n.º 6
0
def _open_ds(path_or_ds):
    if isinstance(path_or_ds, basestring):
        gdal.AllRegister()
        return gdal.OpenShared(str(path_or_ds))
    return path_or_ds