Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions pymapgis/io/__init__.py
Original file line number Diff line number Diff line change
@@ -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}")
41 changes: 18 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <nicholaskarlson@gmail.com>"]
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"
17 changes: 17 additions & 0 deletions tests/test_read.py
Original file line number Diff line number Diff line change
@@ -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