Metadata-Version: 2.1
Name: geojsonchemy
Version: 0.1.2
Summary: 
Author: Nutchanon Ninyawee
Author-email: nutchanon@codustry.com
Requires-Python: >=3.11,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: geoalchemy2 (>=0.14.3,<0.15.0)
Requires-Dist: geojson-pydantic (>=1.0.2,<2.0.0)
Requires-Dist: orjson (>=3.9.13,<4.0.0)
Description-Content-Type: text/markdown

# GeoJSONchemy [Under Development] 🌍🧪
GeoJSONchemy is a Python library that provides support for GeoJSON spatial data types in SQLAlchemy and SQLModel. It allows you to easily work with GeoJSON data in your database models. It currently supports ONLY PostgreSQL-[PostGIS](https://postgis.net/).

![Cover Image Gen via MS Copilot Pro, a globe with map creator tools](cover.jpeg)

## Installation 📦
You can install GeoJSONchemy using pip:
```bash
pip install geojsonchemy

```
## Usage 🚀
SQLAlchemy
In SQLAlchemy, you can use the `GeomJSON` and `Geomdantic` classes from GeoJSONchemy as types for your model fields. Both are subclasses from `geoalchemy2.types.Geometry` 
Here's an example:

```python
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from geojsonchemy import GeomJSON, Geomdantic
from geojson-pydantic import FeatureCollection

Base = declarative_base()

class FooModel(Base):
    __tablename__ = 'table_name'

    id: Mapped[int] = Column(Integer, primary_key=True)
    geom: Mapped[dict] = mapped_column(GeomJSON(geometry_type="POINT", srid=4326), nullable=False, index=True)
    geom2: Mapped[FeatureCollection] = mapped_column(Geomdantic(geometry_type="GEOMETRY", srid=4326), nullable=False, index=True)
```

## SQLModel
In [SQLModel](https://github.com/tiangolo/sqlmodel), you can use the `GeomJSON` and `Geomdantic` classes in a similar way:
    
```python   
from sqlmodel import Field, SQLModel

class GeomTable(SQLModel, table=True):
    __tablename__ = "table_name"

    id: int = Field(primary_key=True)
    name: str
    geom: dict = Field(
        sa_type=GeomJSON(geometry_type="GEOMETRY", srid=4326),
        nullable=False,
    )
    geom2: FeatureCollection = Field(
        sa_type=Geomdantic(geometry_type="GEOMETRY", srid=4326),
        nullable=False,
    )

```


## Note 📝
Please note that GeoJSONchemy currently only supports PostgreSQL. If you try to use it with a different database, it will raise a NotImplementedError.

## Contributing 🤝
Contributions are welcome! Please feel free to submit a pull request.

### TODO
- [ ] Add support for MutableDict


## License 📄
GeoJSONchemy is licensed under the MIT license. See the LICENSE file for more details.
