Name | geojsonchemy JSON |
Version |
0.1.3
JSON |
| download |
home_page | |
Summary | |
upload_time | 2024-02-07 13:41:59 |
maintainer | |
docs_url | None |
author | Nutchanon Ninyawee |
requires_python | >=3.11,<4.0 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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/).

## 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 sqlalchemy.orm import Mapped, mapped_column
from geojsonchemy import GeomJSON, Geomdantic
from geojson_pydantic.geometries import Geometry, Point, MultiPlolygon
Base = declarative_base()
class FooModel(Base):
__tablename__ = 'foo'
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[Geometry] = 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__ = "bar"
id: int = Field(primary_key=True)
name: str
geom: dict = Field(
sa_type=GeomJSON(geometry_type="GEOMETRY", srid=4326),
nullable=False,
)
geom2: Point = Field(
sa_type=Geomdantic(geometry_type="POINT", 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.
Raw data
{
"_id": null,
"home_page": "",
"name": "geojsonchemy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Nutchanon Ninyawee",
"author_email": "nutchanon@codustry.com",
"download_url": "https://files.pythonhosted.org/packages/46/e9/4cf01813396a6cc9c07c675a8a9f0aea8641029320bbf7d315d5ed1fe8f1/geojsonchemy-0.1.3.tar.gz",
"platform": null,
"description": "# GeoJSONchemy [Under Development] \ud83c\udf0d\ud83e\uddea\nGeoJSONchemy 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/).\n\n\n\n## Installation \ud83d\udce6\nYou can install GeoJSONchemy using pip:\n```bash\npip install geojsonchemy\n\n```\n## Usage \ud83d\ude80\nSQLAlchemy\nIn SQLAlchemy, you can use the `GeomJSON` and `Geomdantic` classes from GeoJSONchemy as types for your model fields. Both are subclasses from `geoalchemy2.types.Geometry` \nHere's an example:\n\n```python\nfrom sqlalchemy import Column, Integer\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import Mapped, mapped_column\nfrom geojsonchemy import GeomJSON, Geomdantic\nfrom geojson_pydantic.geometries import Geometry, Point, MultiPlolygon\n\nBase = declarative_base()\n\nclass FooModel(Base):\n __tablename__ = 'foo'\n\n id: Mapped[int] = Column(Integer, primary_key=True)\n geom: Mapped[dict] = mapped_column(GeomJSON(geometry_type=\"POINT\", srid=4326), nullable=False, index=True)\n geom2: Mapped[Geometry] = mapped_column(Geomdantic(geometry_type=\"GEOMETRY\", srid=4326), nullable=False, index=True)\n```\n\n## SQLModel\nIn [SQLModel](https://github.com/tiangolo/sqlmodel), you can use the `GeomJSON` and `Geomdantic` classes in a similar way:\n \n```python \nfrom sqlmodel import Field, SQLModel\n\nclass GeomTable(SQLModel, table=True):\n __tablename__ = \"bar\"\n\n id: int = Field(primary_key=True)\n name: str\n geom: dict = Field(\n sa_type=GeomJSON(geometry_type=\"GEOMETRY\", srid=4326),\n nullable=False,\n )\n geom2: Point = Field(\n sa_type=Geomdantic(geometry_type=\"POINT\", srid=4326),\n nullable=False,\n )\n\n```\n\n\n## Note \ud83d\udcdd\nPlease note that GeoJSONchemy currently only supports PostgreSQL. If you try to use it with a different database, it will raise a NotImplementedError.\n\n## Contributing \ud83e\udd1d\nContributions are welcome! Please feel free to submit a pull request.\n\n### TODO\n- [ ] Add support for MutableDict\n\n\n## License \ud83d\udcc4\nGeoJSONchemy is licensed under the MIT license. See the LICENSE file for more details.",
"bugtrack_url": null,
"license": "",
"summary": "",
"version": "0.1.3",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "16eddc500f9d4e6c360b235d98228d17460d2b62fc07b44926547ec6b5fb2d7c",
"md5": "9a0e7b17131b25385c462a83d8591149",
"sha256": "a950ccfe22b5c3220372229e8a93961da1030a06d572360785aeb8f4608faf7d"
},
"downloads": -1,
"filename": "geojsonchemy-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a0e7b17131b25385c462a83d8591149",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11,<4.0",
"size": 3775,
"upload_time": "2024-02-07T13:41:57",
"upload_time_iso_8601": "2024-02-07T13:41:57.611728Z",
"url": "https://files.pythonhosted.org/packages/16/ed/dc500f9d4e6c360b235d98228d17460d2b62fc07b44926547ec6b5fb2d7c/geojsonchemy-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "46e94cf01813396a6cc9c07c675a8a9f0aea8641029320bbf7d315d5ed1fe8f1",
"md5": "25dee8450255636f942c6694eac72340",
"sha256": "8741cd29b545760909ddb79c1867efad4951bc2e1fc97844b5f0061924f37383"
},
"downloads": -1,
"filename": "geojsonchemy-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "25dee8450255636f942c6694eac72340",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11,<4.0",
"size": 3069,
"upload_time": "2024-02-07T13:41:59",
"upload_time_iso_8601": "2024-02-07T13:41:59.711068Z",
"url": "https://files.pythonhosted.org/packages/46/e9/4cf01813396a6cc9c07c675a8a9f0aea8641029320bbf7d315d5ed1fe8f1/geojsonchemy-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-07 13:41:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "geojsonchemy"
}