예제 #1
0
 def test_desc(self):
     e = RasterElement(self.rast_data)
     assert e.desc == self.hex_rast_data
     assert e.srid == 4326
     e = RasterElement(self.hex_rast_data)
     assert e.desc == self.hex_rast_data
     assert e.srid == 4326
예제 #2
0
    def test_Raster(self):
        polygon = WKTElement('POLYGON((0 0,1 1,0 1,0 0))', srid=4326)
        o = Ocean(polygon.ST_AsRaster(5, 5))
        session.add(o)
        session.flush()
        session.expire(o)

        assert isinstance(o.rast, RasterElement)

        rast_data = (
            '01000001009A9999999999C93F9A9999999999C9BF0000000000000000000000000000F03'
            'F00000000000000000000000000000000E610000005000500440001010101010101010100'
            '010101000001010000000100000000'
        )

        assert o.rast.data == rast_data

        assert session.execute(
            select([Ocean.rast.ST_Height(), Ocean.rast.ST_Width()])
        ).fetchall() == [(5, 5)]

        # Set rast to None
        o.rast = None

        # Insert in DB
        session.flush()
        session.expire(o)

        # Check what was updated in DB
        assert o.rast is None
        cols = [Ocean.id, Ocean.rast]
        if SQLA_LT_2:
            assert session.execute(select(cols)).fetchall() == [(1, None)]
        else:
            assert session.execute(select(*cols)).fetchall() == [(1, None)]

        # Reset rast to initial value
        o.rast = RasterElement(rast_data)

        # Insert in DB
        session.flush()
        session.expire(o)

        # Check what was updated in DB
        assert o.rast.data == rast_data

        assert session.execute(
            select([Ocean.rast.ST_Height(), Ocean.rast.ST_Width()])
        ).fetchall() == [(5, 5)]
예제 #3
0
 def test_pickle_unpickle(self):
     import pickle
     e = RasterElement(self.rast_data)
     assert e.srid == 4326
     assert e.extended is True
     assert e.data == self.hex_rast_data
     pickled = pickle.dumps(e)
     unpickled = pickle.loads(pickled)
     assert unpickled.srid == 4326
     assert unpickled.extended is True
     assert unpickled.data == self.hex_rast_data
     f = unpickled.ST_Height()
     eq_sql(f, 'ST_Height(raster(:raster_1))')
     assert f.compile().params == {
         u'raster_1': self.hex_rast_data,
     }
예제 #4
0
    def submit(self, session):
        """
        Submit the data to the db using ORM
        """
        # This produces a PSQL command with auto tiling
        cmd = ['raster2pgsql', '-s', str(self.epsg)]

        # Remove any invalid columns
        valid = get_table_attributes(ImageData)
        data = {k: v for k, v in self.data.items() if k in valid}
        data['date_accessed'] = self.date_accessed

        # Add tiling if requested
        if self.tiled == True:
            cmd.append('-t')
            cmd.append('500x500')

        # If nodata applied:
        if self.no_data is not None:
            cmd.append('-N')
            cmd.append(str(self.no_data))

        cmd.append(self.filename)
        self.log.debug('Executing: {}'.format(' '.join(cmd)))
        s = check_output(cmd, stderr=STDOUT).decode('utf-8')

        # Split the SQL command at values (' which is the start of every one
        tiles = s.split("VALUES ('")[1:]
        if len(tiles) > 1:
            # -1 because the first element is not a
            self.log.info(
                'Raster is split into {} tiles for uploading...'.format(
                    len(tiles)))

        # Allow for tiling, the first split is always psql statement we don't
        # need
        for t in tiles:
            v = t.split("'::")[0]
            raster = RasterElement(v)
            data['raster'] = raster
            r = ImageData(**data)
            session.add(r)
            session.commit()
예제 #5
0
 def test_function_call(self):
     e = RasterElement(b'\x01\x02')
     f = e.ST_Height()
     eq_sql(f, 'ST_Height(:raster_1::raster)')
     assert f.compile().params == {u'raster_1': b'\x01\x02'}
예제 #6
0
 def test_desc(self):
     e = RasterElement(b'\x01\x02')
     assert e.desc == b'0102'
예제 #7
0
 def test_function_call(self):
     from geoalchemy2.elements import RasterElement
     e = RasterElement(b'\x01\x02')
     f = e.ST_Height()
     eq_sql(f, 'ST_Height(:raster_1::raster)')
     eq_(f.compile().params, {u'raster_1': b'\x01\x02'})
예제 #8
0
 def test_desc(self):
     from geoalchemy2.elements import RasterElement
     e = RasterElement(b'\x01\x02')
     eq_(e.desc, b'0102')
예제 #9
0
 def test_function_call(self):
     e = RasterElement(self.rast_data)
     f = e.ST_Height()
     eq_sql(f, 'ST_Height(raster(:raster_1))')
     assert f.compile().params == {u'raster_1': self.hex_rast_data}