Commit 981cadf4 authored by Nicolas Garcia Ospina's avatar Nicolas Garcia Ospina
Browse files

Introduced the Tile class with test and CI pipeline

parent 19b90b4e
Pipeline #18462 passed with stage
in 2 minutes and 33 seconds
image: python:3-buster
image: debian:bullseye-slim
# Make pip cache the installed dependencies
variables:
......@@ -9,8 +9,11 @@ cache:
- venv/
before_script:
- apt-get update -y
- apt-get install -y python3-pip proj-bin libgeos-dev
- python3 -V
- pip3 install virtualenv
- rm -rf venv
- virtualenv venv
- source venv/bin/activate
- pip3 install .
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
import pyproj
from shapely.ops import transform
from babelgrid import Babel
# Initialize log
logger = logging.getLogger(__name__)
class Tile:
"""The Tile class represents a quadtree tile of any zoom level
containing its basic attributes to describe the tile.
Args:
quadkey (str): Quadkey code associated with a Bing quadtree tile
crs (str): Coordinate system associated with the tile, given as a EPSG code.
Default = "epsg:4326"
Example:
WGS84 = "epsg:4326"
in degrees
(WSF is provided in this coordinate system)
mercator = "epsg:3857"
in meters but not for area calculation
(GHSL is provided in this coordinate system)
google_maps_mercator = "epsg:900913"
in meters but not for area calculation
(OBM is provided in this coordinate system)
Attributes:
self.quadkey (str): Quadkey code associated with a bing quadtree tile
self.crs (str): Coordinate system associated with the tile, given as a EPSG code.
self.geometry (shapely.geometry.polygon.Polygon): Shapely polygon of the tile
"""
def __init__(self, quadkey, crs="epsg:4326"):
self.quadkey = quadkey
self.crs = crs
self.geometry = self.__get_geometry(self.crs)
def __get_geometry(self, crs):
"""Returns a Shapely polygon of the tile based on a given crs,
where the default is the one used to create the object.
Args:
crs (str): Coordinate system of the output geometry.
Returns:
geometry (shapely.geometry.polygon.Polygon): Shapely polygon of the tile
"""
geometry = Babel("bing").id_to_tile(self.quadkey).to_dict()["shapely"]
if crs != "epsg:4326":
project = pyproj.Transformer.from_proj(
pyproj.Proj("epsg:4326"), pyproj.Proj(crs), always_xy=True
)
geometry = transform(project.transform, geometry)
return geometry
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
......@@ -29,7 +29,7 @@ setup(
keywords="OpenBuildingMap, buildings, analysis",
license="AGPLv3+",
author="Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ",
install_requires=["numpy"],
install_requires=["pyproj==3.0.0.post1", "shapely", "babelgrid"],
extras_require={
"tests": tests_require,
"linters": linters_require,
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
......
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
from obmgapanalysis.tile import Tile
def test_Tile_init():
tile = Tile("122100203310222101", "epsg:3857")
polygon_coords = (
"POLYGON (("
"2642428.067818544 4570169.921170688, "
"2642428.067818544 4570322.795227258, "
"2642580.941875115 4570322.795227258, "
"2642580.941875115 4570169.921170688, "
"2642428.067818544 4570169.921170688))"
)
assert tile.crs == "epsg:3857"
assert str(tile.geometry) == polygon_coords
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment