Esempio n. 1
0
    def get_values(self, rectangle):
        """Return an array covering the given rectangle.

        Increasing x/y array indexes correspond to increasing value in the projected space.
        Cell size is the one of the tile.
        """
        assert self.x_delta > 0
        ((x_min, x_max), (y_min, y_max)) = rectangle
        if self.y_delta > 0:
            # get indexes of sub-array
            xi_min, yi_min = self.projected_to_raster((x_min, y_min))
            xi_max, yi_max = self.projected_to_raster((x_max, y_max))
            # returns the subarray
            subarray = self.data[xi_min:xi_max + 1, yi_min:yi_max + 1]
            return GeoData(subarray,
                           *self.raster_to_projected((xi_min, yi_min)),
                           self.x_delta,
                           self.y_delta,
                           projection=self.geoprojection)
        else:  # our internal data structure is inversed on y-axis
            # get indexes of sub-array
            xi_min, yi_min = self.projected_to_raster((x_min, y_max))
            xi_max, yi_max = self.projected_to_raster((x_max, y_min))
            # returns the sub-array, inversed on the y-axis
            subarray = self.data[xi_min:xi_max + 1,
                                 yi_min:yi_max + 1][..., ::-1]
            return GeoData(subarray,
                           *self.raster_to_projected((xi_min, yi_max)),
                           self.x_delta,
                           -self.y_delta,
                           projection=self.geoprojection)
Esempio n. 2
0
 def test_right_append(self):
     gd_right = GeoData(np.array([[31, 32], [41, 42]]), 2, 0, 1, 1)
     res = self.gd.append_right(gd_right)
     self.assertEqual(res.data[0, 0], 11)
     self.assertEqual(res.data[1, 1], 22)
     self.assertEqual(res.data[0, 1], 12)
     self.assertEqual(res.data[1, 0], 21)
     self.assertEqual(res.data[3, 0], 41)
     self.assertEqual(res.data.shape, (4, 2))
Esempio n. 3
0
def geodata_from_raster_msg(msg: Raster, layer: str, invert=False):
    """Deserialize a Raster msg into a GeoData object.

    if layer is "elevation", the raster is inverted
    """
    array = np.fromiter(zip(msg.data), dtype=[(layer, 'float64')])
    array.resize((msg.metadata.x_width, msg.metadata.y_height))
    # FIXME (Workaround) invert elevation rasters as they are shown inverted in the GUI
    if layer == "elevation":
        array = array[..., ::-1]
    if invert:
        array = array[..., ::-1]
    return GeoData(array,
                   msg.metadata.x_offset,
                   msg.metadata.y_offset,
                   msg.metadata.cell_width,
                   msg.metadata.cell_width,
                   projection=msg.metadata.epsg)
Esempio n. 4
0
 def test_bottom_append(self):
     gd_right = GeoData(np.array([[31, 32], [41, 42]]), 0, 2, 1, 1)
     res = self.gd.append_bottom(gd_right)
     self.assertEqual(res.data.shape, (2, 4))
Esempio n. 5
0
 def setUp(self):
     self.gd = GeoData(np.array([[11, 12], [21, 22]]), 0, 0, 1, 1)