Beispiel #1
0
    def test_and(self):
        """ Tests AND operation, which is an intersection between both raster geometries. """

        raster_geom_a = self.raster_geom
        raster_geom_b = RasterGeometry.from_geometry(self.ogr_geom, self.x_pixel_size, self.y_pixel_size)

        self.assertEqual(raster_geom_a & raster_geom_b, raster_geom_b & raster_geom_a)
Beispiel #2
0
    def setUp(self):
        """ Creates a normal and a rotated raster geometry with a random coordinate extent. """

        # set up spatial reference system
        self.sref = SpatialRef(4326)

        # define region of interest/extent
        ll_x = random.randrange(-50., 50., 10.)
        ll_y = random.randrange(-50., 50., 10.)
        ur_x = ll_x + random.randrange(10., 50., 10.)
        ur_y = ll_y + random.randrange(10., 50., 10.)
        self.sh_geom = Polygon(((ll_x, ll_y), (ll_x, ur_y), (ur_x, ur_y),
                                (ur_x, ll_y)))  # Polygon in clock-wise order
        self.ogr_geom = ogr.CreateGeometryFromWkt(self.sh_geom.wkt)
        self.ogr_geom.AssignSpatialReference(self.sref.osr_sref)

        self.extent = tuple(map(float, (ll_x, ll_y, ur_x, ur_y)))
        self.x_pixel_size = 0.5
        self.y_pixel_size = 0.5
        self.raster_geom = RasterGeometry.from_extent(self.extent, self.sref,
                                                      self.x_pixel_size,
                                                      self.y_pixel_size)

        # create rotated raster geometry
        geom_nap = affinity.rotate(
            shapely.wkt.loads(self.ogr_geom.ExportToWkt()), 45, 'center')
        geom_nap = ogr.CreateGeometryFromWkt(geom_nap.wkt)
        geom_nap.AssignSpatialReference(self.sref.osr_sref)
        self.raster_geom_rot = RasterGeometry.from_geometry(
            geom_nap, self.x_pixel_size, self.y_pixel_size)
Beispiel #3
0
    def test_equal(self):
        """ Tests if two raster geometries are equal (one created from an extent, one from a geometry). """

        raster_geom_a = self.raster_geom
        raster_geom_b = RasterGeometry.from_geometry(self.ogr_geom, self.x_pixel_size, self.y_pixel_size)

        assert raster_geom_a == raster_geom_b
Beispiel #4
0
    def test_from_geom(self):
        """ Tests setting up a raster geometry from a given geometry. """

        raster_geom = RasterGeometry.from_geometry(self.ogr_geom,
                                                   self.x_pixel_size,
                                                   self.y_pixel_size)

        self.assertListEqual(raster_geom.outer_boundary_corners,
                             list(self.sh_geom.exterior.coords)[:-1])