How to use the mapchete.io.vector.reproject_geometry function in mapchete

To help you get started, we’ve selected a few mapchete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ungarj / mapchete / test / test_io.py View on Github external
for feature in src:

            # WGS84 to Spherical Mercator
            out_geom = reproject_geometry(
                shape(feature["geometry"]), CRS(src.crs),
                CRS().from_epsg(3857))
            assert out_geom.is_valid

            # WGS84 to LAEA
            out_geom = reproject_geometry(
                shape(feature["geometry"]), CRS(src.crs),
                CRS().from_epsg(3035))
            assert out_geom.is_valid

            # WGS84 to WGS84
            out_geom = reproject_geometry(
                shape(feature["geometry"]), CRS(src.crs),
                CRS().from_epsg(4326))
            assert out_geom.is_valid

    # WGS84 bounds to Spherical Mercator
    big_box = box(-180, -90, 180, 90)
    reproject_geometry(big_box, CRS().from_epsg(4326), CRS().from_epsg(3857))

    # WGS84 bounds to Spherical Mercator raising clip error
    with pytest.raises(RuntimeError):
        reproject_geometry(
            big_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
            error_on_clip=True
        )
    outside_box = box(-180, 87, 180, 90)
    assert reproject_geometry(
github ungarj / mapchete / test / test_io.py View on Github external
shape(feature["geometry"]), CRS(src.crs),
                CRS().from_epsg(4326))
            assert out_geom.is_valid

    # WGS84 bounds to Spherical Mercator
    big_box = box(-180, -90, 180, 90)
    reproject_geometry(big_box, CRS().from_epsg(4326), CRS().from_epsg(3857))

    # WGS84 bounds to Spherical Mercator raising clip error
    with pytest.raises(RuntimeError):
        reproject_geometry(
            big_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
            error_on_clip=True
        )
    outside_box = box(-180, 87, 180, 90)
    assert reproject_geometry(
        outside_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
    ).is_valid

    # empty geometry
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(3857)).is_empty
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(4326)).is_empty

    # CRS parameter
    big_box = box(-180, -90, 180, 90)
    assert reproject_geometry(
        big_box, 4326, 3857) == reproject_geometry(
        big_box, "4326", "3857")
    with pytest.raises(TypeError):
        reproject_geometry(big_box, 1.0, 1.0)
github ungarj / mapchete / test / test_io.py View on Github external
)
    outside_box = box(-180, 87, 180, 90)
    assert reproject_geometry(
        outside_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
    ).is_valid

    # empty geometry
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(3857)).is_empty
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(4326)).is_empty

    # CRS parameter
    big_box = box(-180, -90, 180, 90)
    assert reproject_geometry(
        big_box, 4326, 3857) == reproject_geometry(
        big_box, "4326", "3857")
    with pytest.raises(TypeError):
        reproject_geometry(big_box, 1.0, 1.0)
github ungarj / mapchete / test / test_io.py View on Github external
error_on_clip=True
        )
    outside_box = box(-180, 87, 180, 90)
    assert reproject_geometry(
        outside_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
    ).is_valid

    # empty geometry
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(3857)).is_empty
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(4326)).is_empty

    # CRS parameter
    big_box = box(-180, -90, 180, 90)
    assert reproject_geometry(
        big_box, 4326, 3857) == reproject_geometry(
        big_box, "4326", "3857")
    with pytest.raises(TypeError):
        reproject_geometry(big_box, 1.0, 1.0)
github ungarj / mapchete / test / test_io.py View on Github external
# WGS84 bounds to Spherical Mercator raising clip error
    with pytest.raises(RuntimeError):
        reproject_geometry(
            big_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
            error_on_clip=True
        )
    outside_box = box(-180, 87, 180, 90)
    assert reproject_geometry(
        outside_box, CRS().from_epsg(4326), CRS().from_epsg(3857),
    ).is_valid

    # empty geometry
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(3857)).is_empty
    assert reproject_geometry(
        Polygon(), CRS().from_epsg(4326), CRS().from_epsg(4326)).is_empty

    # CRS parameter
    big_box = box(-180, -90, 180, 90)
    assert reproject_geometry(
        big_box, 4326, 3857) == reproject_geometry(
        big_box, "4326", "3857")
    with pytest.raises(TypeError):
        reproject_geometry(big_box, 1.0, 1.0)
github ungarj / mapchete / mapchete / cli / default / convert.py View on Github external
def _clip_bbox(clip_geometry, dst_crs=None):
    with fiona.open(clip_geometry) as src:
        return reproject_geometry(box(*src.bounds), src_crs=src.crs, dst_crs=dst_crs)
github ungarj / mapchete / mapchete / formats / default / tile_directory.py View on Github external
def _get_tiles_paths(
        self,
        tile_directory_zoom=None,
        fallback_to_higher_zoom=False,
        matching_method="gdal",
        matching_precision=8,
        matching_max_zoom=None,
    ):
        # determine tile bounds in TileDirectory CRS
        td_bounds = reproject_geometry(
            self.tile.bbox,
            src_crs=self.tile.tp.crs,
            dst_crs=self._td_pyramid.crs
        ).bounds

        # find target zoom level
        if tile_directory_zoom is None:
            zoom = tile_to_zoom_level(
                self.tile,
                dst_pyramid=self._td_pyramid,
                matching_method=matching_method,
                precision=matching_precision
            )
            if matching_max_zoom is not None:
                zoom = min([zoom, matching_max_zoom])
        else:
github ungarj / mapchete / mapchete / formats / default / tile_directory.py View on Github external
def bbox(self, out_crs=None):
        """
        Return data bounding box.

        Parameters
        ----------
        out_crs : ``rasterio.crs.CRS``
            rasterio CRS object (default: CRS of process pyramid)

        Returns
        -------
        bounding box : geometry
            Shapely geometry object
        """
        return reproject_geometry(
            box(*self._bounds),
            src_crs=self.td_pyramid.crs,
            dst_crs=self.pyramid.crs if out_crs is None else out_crs
        )