diff --git a/requirements-test.txt b/requirements-test.txt index 9f67f51..7647525 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -4,7 +4,10 @@ flake8 black isort pytest-cov +codecov mypy>=0.9 gitchangelog +mkdocs pprint +osmium diff --git a/setup.py b/setup.py index 0c9b5a5..49f1f4f 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,33 @@ def read(*paths, **kwargs): content = open_file.read().strip() return content +# mirror of dependencies in setup and requirements.txt +install_requires=[ + "geopandas", + "pandas", + "tqdm", + "requests", + "protobuf>=4.21.1", +] + +extras_require={"test": [ + "pytest", + "coverage", + "flake8", + "black", + "isort", + "pytest-cov", + "codecov", + "mypy>=0.9", + "gitchangelog", + "mkdocs", + "pprint", + "osmium", + ] +} + +assert read("requirements.txt") == "\n".join(install_requires) +assert read("requirements-test.txt") == "\n".join(extras_require["test"]) setup( name="earth_osm", @@ -52,6 +79,7 @@ def read(*paths, **kwargs): "mypy>=0.9", "gitchangelog", "mkdocs", + "osmium", ], }, classifiers=[ diff --git a/tests/test_osmium.py b/tests/test_osmium.py new file mode 100644 index 0000000..a1ba752 --- /dev/null +++ b/tests/test_osmium.py @@ -0,0 +1,61 @@ +import os +import osmium +import pandas as pd +from earth_osm.eo import get_osm_data + +class PowerLineHandler(osmium.SimpleHandler): + def __init__(self): + super().__init__() + self.power_lines = [] + + def way(self, w): + if 'power' in w.tags and w.tags['power'] == 'line': + for node in w.nodes: + location = osmium.osm.Location(node.lon, node.lat) + self.power_lines.append({ + 'id': w.id, + 'version': w.version, + 'visible': w.visible, + 'timestamp': w.timestamp, + 'uid': w.uid, + 'user': w.user, + 'changeset': w.changeset, + 'latitude': location.lat if location else None, + 'longitude': location.lon if location else None, + }) + + def get_dataframe(self): + return pd.DataFrame(self.power_lines) + + +def test_osmium(shared_data_dir): + region = "nigeria" + primary_name = "power" + feature_name = "line" + mp = True + update = False + data_dir = shared_data_dir + + df = get_osm_data( + region, + primary_name, + feature_name, + data_dir=data_dir + ) + + pbf_fp = os.path.join(shared_data_dir, "pbf", f"{region}-latest.osm.pbf") + + omsium_handler = PowerLineHandler() + omsium_handler.apply_file(pbf_fp, locations=True) + + + + df2 = omsium_handler.get_dataframe() + + df2.drop_duplicates(subset='id', inplace=True) + + assert len(df) == len(df2), f"Lengths are not equal: {len(df)} != {len(df2)}" + + +if __name__ == "__main__": + test_osmium('earth_data_test') \ No newline at end of file