Пример #1
0
    def __init__(self, core, name, xll, yll):
        """
        Initialises a Tile().

        Parameters
        ----------
        core : TPSCoreProperty
            defines core parameters of the tile
        name : str
            name of the tile
        llx : int
            lower-left x (right) coordinate of the tile
        lly : int
            lower-left y (up) coordinate of the tile
        """

        self.core = core

        self.name = name
        self.typename = core.tiletype
        self.llx = xll
        self.lly = yll
        self.x_size_px = int(self.core.tile_xsize_m / self.core.sampling)
        self.y_size_px = int(self.core.tile_ysize_m / self.core.sampling)
        self._subset_px = (0, 0, self.x_size_px, self.y_size_px)

        self.polygon_proj = self.get_extent_geometry_proj()
        self.polygon_geog = self.get_extent_geometry_geog()
        self.bbox_proj = ptpgeometry.get_geometry_envelope(
            self.polygon_proj, rounding=self.core.sampling)
        self.bbox_geog = ptpgeometry.get_geometry_envelope(self.polygon_geog,
                                                           rounding=0.000001)
Пример #2
0
    def __init__(self, core, polygon_geog, x0, y0):
        """
        Initialises an TilingSystem class for a specified subgrid.

        Parameters
        ----------
        core : TPSCoreProperty
            defines core parameters of the (sub-) grid
        polygon_geog : OGRGeometry
            geometry defining the extent/outline of the subgrid
        x0 : int
            lower-left x (right) coordinates of the subgrid
        y0 : int
            lower-left y (up) coordinates of the subgrid
        """

        self.core = core
        self.x0 = x0
        self.y0 = y0
        self.xstep = self.core.tile_xsize_m
        self.ystep = self.core.tile_ysize_m
        self.polygon_proj = ptpgeometry.transform_geometry(
            polygon_geog, self.core.projection.osr_spref)
        self.bbox_proj = ptpgeometry.get_geometry_envelope(
            self.polygon_proj, rounding=self.core.sampling)
Пример #3
0
    def __init__(self, core, polygon_geog, tilingsystem=None):
        """
        Initialises a TiledProjection().

        Parameters
        ----------
        core : TPSCoreProperty
            defines core parameters of the (sub-) grid
        polygon_geog : OGRGeometry
            geometry defining the extent/outline of the subgrid.
            if not given, a single global subgrid is assigned to the grid.
        tilingsystem : TilingSystem
            optional; an instance of TilingSystem()
            if not given, a single global tile is assigned to the grid.
        """

        self.core = core
        self.polygon_geog = ptpgeometry.segmentize_geometry(polygon_geog,
                                                            segment=0.5)
        self.polygon_proj = ptpgeometry.transform_geometry(
            self.polygon_geog, self.core.projection.osr_spref)
        self.bbox_proj = ptpgeometry.get_geometry_envelope(
            self.polygon_proj, rounding=self.core.sampling)

        # does this use anybody? its justs makes problems with the antimeridian!
        # self.bbox_geog = ptpgeometry.get_geometry_envelope(
        #     self.polygon_geog, rounding=self.core.sampling / 1000000.0)

        if tilingsystem is None:
            tilingsystem = GlobalTile(self.core, 'TG', self.get_bbox_proj())
        self.tilesys = tilingsystem
Пример #4
0
    def get_bbox_geog(self):
        """
        Returns the limits of the subgrid in the lon-lat-space.

        Returns
        -------
        tuple
            bounding box of subgrid
            as (lonmin, latmin, lonmax, latmax)

        """
        return ptpgeometry.get_geometry_envelope(self.polygon_geog,
                                                 rounding=0.0001)
Пример #5
0
    def search_tiles_over_geometry(self, geometry, coverland=True):
        """
        Search tiles of the subgrid that are overlapping with the geometry.

        Parameters
        ----------
        geometry : OGRGeometry
            A point or polygon geometry representing the region of interest.
        coverland : Boolean
            option to search for tiles covering land at any point in the tile

        Returns
        -------
        overlapped_tiles : list
            Return a list of the overlapped tiles' name.
            If not found, return empty list.

        """
        overlapped_tiles = list()

        if geometry.GetGeometryName() in ['MULTIPOINT', 'POINT']:
            if geometry.Intersects(self.polygon_geog):
                # get intersect area with subgrid in latlon
                intersect_geometry = geometry.Intersection(self.polygon_geog)
                intersect_geometry = ptpgeometry.transform_geometry(
                    intersect_geometry, self.projection.osr_spref)
            else:
                return overlapped_tiles

        if geometry.GetGeometryName() in ['POLYGON', 'MULTIPOLYGON']:

            # get intersect area with subgrid in latlon
            intersect = ptpgeometry.get_lonlat_intersection(
                geometry, self.polygon_geog)

            # check if geom intersects subgrid
            if intersect.Area() == 0.0:
                return overlapped_tiles

            # transform intersection geometry back to the spatial ref system of the subgrid.
            # segmentise for high precision during reprojection.
            projected = intersect.GetSpatialReference().IsProjected()
            if projected == 0:
                max_segment = 0.5
            elif projected == 1:
                max_segment = 50000
            else:
                raise Warning(
                    'Please check unit of geometry before reprojection!')

            intersect_geometry = ptpgeometry.transform_geometry(
                intersect, self.projection.osr_spref, segment=max_segment)

        # get envelope of the geometry
        envelope = ptpgeometry.get_geometry_envelope(intersect_geometry)

        # get overlapped tiles
        tiles = self.tilesys.identify_tiles_overlapping_xybbox(envelope)

        for tile in tiles:

            # get tile object
            t = self.tilesys.create_tile(tile)

            # get only tile that overlaps with intersect_geometry
            if t.polygon_proj.Intersects(intersect_geometry):

                # get only tile if coverland is satisfied
                if not coverland or self.tilesys.check_tile_covers_land(
                        t.name):
                    overlapped_tiles.append(t.name)

        return overlapped_tiles