# GeoModeler
GeoModeler is a Python project based on Pydantic, designed to model and validate GeoJSON data structures such as points, lines, and polygons. It provides a set of tools and validators for working with GeoJSON data conforming to RFC 7946.
## Features
- Models for all basic GeoJSON types:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
- Feature
- FeatureCollection
- Runtime data validation using Pydantic
- JSON schema generation and validation
- Easy conversion between Python objects and GeoJSON strings
## Installation
GeoModeler requires Python 3.10 or higher. Install it using pip:
```bash
pip install GeoModeler
```
## Usage
### Creating GeoJSON Objects
Here's an example of how to create a `Point` object:
```python
from GeoModeler import Point
point = Point(type='Point', coordinates=[1.0, 2.0])
```
### Validating GeoJSON Strings
You can validate a GeoJSON string using the `model_validate_json` method:
```python
point = Point.model_validate_json('{"type":"Point","coordinates":[1.0,2.0]}')
```
### Converting Models to GeoJSON Strings
Convert a model to a GeoJSON string with the `model_dump_json` method:
```python
json_string = point.model_dump_json()
```
### Initializing and Validating Complex Structures
To initialize a `FeatureCollection` or other complex GeoJSON objects, use the `model_validate_json` method. This ensures that all subtypes are validated correctly:
```python
from GeoModeler import FeatureCollection
feature_collection_json = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":"1","name":"Litter Bin","description":"Litter Bin","type":"Litter Bin","colour":"Green","location":"Leeds","latitude":"53.71583","longitude":"-1.74448"},"geometry":{"type":"Point","coordinates":[-1.74448,53.71583]}}]}'
feature_collection = FeatureCollection.model_validate_json(feature_collection_json)
```
### Example with Point
You can also initialize a single `Point` from a JSON string:
```python
from GeoModeler import Point
point_json = '{"type":"Point","coordinates":[1.0,2.0]}'
point = Point.model_validate_json(point_json)
```
### Excluding Unset Values
When dumping models to GeoJSON strings, you can exclude unset defaults:
```python
print(feature_collection.model_dump_json(exclude_unset=True))
print(point.model_dump_json(exclude_unset=True))
```
## Testing
This project includes a suite of tests that can be run using pytest:
```bash
pytest
```
## Contributing
Contributions are welcome! Please feel free to submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Keywords
- geojson
- pydantic
- validation
- geospatial
- data-modeling
## Author
This project is developed and maintained by [jvanegmond](mailto:jvanegmond@silverbirchgeospatial.com).
## Links
- [Homepage](https://github.com/jvanegmond93/geo_modeler)
Raw data
{
"_id": null,
"home_page": "https://github.com/jvanegmond93/geo_modeler",
"name": "GeoModeler",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "geojson, pydantic, validation, geospatial, data-modeling",
"author": null,
"author_email": "jvanegmond <jvanegmond@silverbirchgeospatial.com>",
"download_url": "https://files.pythonhosted.org/packages/83/d9/191ad428e200974f6f20eb28018dc0cca0b5e00a161655ea4fd3ad4d40c8/geomodeler-0.1.3b0.tar.gz",
"platform": null,
"description": "# GeoModeler\n\nGeoModeler is a Python project based on Pydantic, designed to model and validate GeoJSON data structures such as points, lines, and polygons. It provides a set of tools and validators for working with GeoJSON data conforming to RFC 7946.\n\n## Features\n\n- Models for all basic GeoJSON types:\n - Point\n - MultiPoint\n - LineString\n - MultiLineString\n - Polygon\n - MultiPolygon\n - GeometryCollection\n - Feature\n - FeatureCollection\n- Runtime data validation using Pydantic\n- JSON schema generation and validation\n- Easy conversion between Python objects and GeoJSON strings\n\n## Installation\n\nGeoModeler requires Python 3.10 or higher. Install it using pip:\n\n```bash\npip install GeoModeler\n```\n\n## Usage\n\n### Creating GeoJSON Objects\n\nHere's an example of how to create a `Point` object:\n\n```python\nfrom GeoModeler import Point\n\npoint = Point(type='Point', coordinates=[1.0, 2.0])\n```\n\n### Validating GeoJSON Strings\n\nYou can validate a GeoJSON string using the `model_validate_json` method:\n\n```python\npoint = Point.model_validate_json('{\"type\":\"Point\",\"coordinates\":[1.0,2.0]}')\n```\n\n### Converting Models to GeoJSON Strings\n\nConvert a model to a GeoJSON string with the `model_dump_json` method:\n\n```python\njson_string = point.model_dump_json()\n```\n\n### Initializing and Validating Complex Structures\n\nTo initialize a `FeatureCollection` or other complex GeoJSON objects, use the `model_validate_json` method. This ensures that all subtypes are validated correctly:\n\n```python\nfrom GeoModeler import FeatureCollection\n\nfeature_collection_json = '{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"id\":\"1\",\"name\":\"Litter Bin\",\"description\":\"Litter Bin\",\"type\":\"Litter Bin\",\"colour\":\"Green\",\"location\":\"Leeds\",\"latitude\":\"53.71583\",\"longitude\":\"-1.74448\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.74448,53.71583]}}]}'\nfeature_collection = FeatureCollection.model_validate_json(feature_collection_json)\n```\n\n### Example with Point\n\nYou can also initialize a single `Point` from a JSON string:\n\n```python\nfrom GeoModeler import Point\n\npoint_json = '{\"type\":\"Point\",\"coordinates\":[1.0,2.0]}'\npoint = Point.model_validate_json(point_json)\n```\n\n### Excluding Unset Values\n\nWhen dumping models to GeoJSON strings, you can exclude unset defaults:\n\n```python\nprint(feature_collection.model_dump_json(exclude_unset=True))\nprint(point.model_dump_json(exclude_unset=True))\n```\n\n## Testing\n\nThis project includes a suite of tests that can be run using pytest:\n\n```bash\npytest\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n\n\n## Keywords\n\n- geojson\n- pydantic\n- validation\n- geospatial\n- data-modeling\n\n## Author\n\nThis project is developed and maintained by [jvanegmond](mailto:jvanegmond@silverbirchgeospatial.com).\n\n## Links\n\n- [Homepage](https://github.com/jvanegmond93/geo_modeler)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "GeoModeler is a Python project based on pydantic, designed to model and validate geojson data structures such as points, lines, and polygons. It provides a set of tools and validators for working with GeoJSON data.",
"version": "0.1.3b0",
"project_urls": {
"Homepage": "https://github.com/jvanegmond93/geo_modeler"
},
"split_keywords": [
"geojson",
" pydantic",
" validation",
" geospatial",
" data-modeling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9e1faefd21bf7fbf212c3bf75aac75571d96f9a5dfbc82ffd25b529beb75a873",
"md5": "d0befd02e09e0bdb57ae841da22c953f",
"sha256": "1030dae349515c59b46a3bb8292b719363dd1020d9b44f495f78280ef89d925c"
},
"downloads": -1,
"filename": "geomodeler-0.1.3b0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d0befd02e09e0bdb57ae841da22c953f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 18792,
"upload_time": "2024-06-04T05:11:51",
"upload_time_iso_8601": "2024-06-04T05:11:51.365375Z",
"url": "https://files.pythonhosted.org/packages/9e/1f/aefd21bf7fbf212c3bf75aac75571d96f9a5dfbc82ffd25b529beb75a873/geomodeler-0.1.3b0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "83d9191ad428e200974f6f20eb28018dc0cca0b5e00a161655ea4fd3ad4d40c8",
"md5": "96080369ba03194999313922597386c4",
"sha256": "8ce57cc3b9900091b4a76e9f948096ea8fd043135121dbbe7b5dd950d6aadb74"
},
"downloads": -1,
"filename": "geomodeler-0.1.3b0.tar.gz",
"has_sig": false,
"md5_digest": "96080369ba03194999313922597386c4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 14412,
"upload_time": "2024-06-04T05:11:52",
"upload_time_iso_8601": "2024-06-04T05:11:52.961984Z",
"url": "https://files.pythonhosted.org/packages/83/d9/191ad428e200974f6f20eb28018dc0cca0b5e00a161655ea4fd3ad4d40c8/geomodeler-0.1.3b0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-04 05:11:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jvanegmond93",
"github_project": "geo_modeler",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "geomodeler"
}