diff --git a/poetry.lock b/poetry.lock index 3cc5a88..b6b938a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -4065,4 +4065,4 @@ files = [ [metadata] lock-version = "2.1" python-versions = ">=3.10,<3.13" -content-hash = "18a2f7863ccb1c5fe159a15206a14f392c08bdedfa78efbafbe93feef36552f9" +content-hash = "a50f242afed67be822b9a16c17bab2b1140ee7685f9faf34f43a2a6eeb0fa9b8" diff --git a/pymapgis/io/__init__.py b/pymapgis/io/__init__.py new file mode 100644 index 0000000..834cb07 --- /dev/null +++ b/pymapgis/io/__init__.py @@ -0,0 +1,29 @@ +from pathlib import Path +import geopandas as gpd +import pandas as pd + + +def read(uri: str, *, x="longitude", y="latitude", **kw): + """ + Universal reader (MVP): + + • .shp / .geojson / .gpkg → GeoDataFrame via GeoPandas + • .csv with lon/lat cols → GeoDataFrame; else plain DataFrame + """ + path = Path(uri) + + if path.suffix.lower() in {".shp", ".geojson", ".gpkg"}: + return gpd.read_file(uri, **kw) + + if path.suffix.lower() == ".csv": + df = pd.read_csv(uri, **kw) + if {x, y}.issubset(df.columns): + gdf = gpd.GeoDataFrame( + df, + geometry=gpd.points_from_xy(df[x], df[y]), + crs="EPSG:4326", + ) + return gdf + return df + + raise ValueError(f"Unsupported format: {uri}") diff --git a/pyproject.toml b/pyproject.toml index df8aa54..78023c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,33 +1,28 @@ -[project] +[tool.poetry] name = "pymapgis" version = "0.1.0" description = "Modern GIS toolkit" -authors = [ - {name = "Nicholas Karlson",email = "nicholaskarlson@gmail.com"} -] -license = {text = "MIT"} +authors = ["Nicholas Karlson "] +license = "MIT" readme = "README.md" -requires-python = ">=3.10" -dependencies = [ - "geopandas (>=1.1.0,<2.0.0)", - "fsspec (>=2025.5.1,<2026.0.0)", - "leafmap (>=0.47.2,<0.48.0)", - "pydantic-settings (>=2.9.1,<3.0.0)", -] - - -[build-system] -requires = ["poetry-core>=2.0.0,<3.0.0"] -build-backend = "poetry.core.masonry.api" +packages = [{ include = "pymapgis" }] [tool.poetry.dependencies] python = ">=3.10,<3.13" +geopandas = "^1.1" +fsspec = "^2025.5" +leafmap = "^0.47.2" +pydantic-settings = "^2.9.1" +# (add rasterio later, once the click conflict is solved) [tool.poetry.group.dev.dependencies] -pytest = "^8.4.0" -pytest-cov = "^6.1.1" -ruff = "^0.11.13" -black = "^25.1.0" -mypy = "^1.16.0" -pre-commit = "^4.2.0" +pytest = "^8.4" +pytest-cov = "^6.1" +ruff = "^0.11" +black = "^25.1" +mypy = "^1.16" +pre-commit = "^4.2" +[build-system] +requires = ["poetry-core>=1.9.0"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/tests/test_read.py b/tests/test_read.py new file mode 100644 index 0000000..e065fba --- /dev/null +++ b/tests/test_read.py @@ -0,0 +1,17 @@ +import geopandas as gpd +from pymapgis.io import read + + +def test_read_shp(tmp_path): + gdf = gpd.GeoDataFrame(geometry=gpd.points_from_xy([0], [0]), crs="EPSG:4326") + shp = tmp_path / "pts.shp" + gdf.to_file(shp) + out = read(shp) + assert isinstance(out, gpd.GeoDataFrame) + + +def test_read_csv(tmp_path): + csv = tmp_path / "pts.csv" + csv.write_text("longitude,latitude\n1,1\n") + out = read(csv) + assert out.geometry.iloc[0].x == 1