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.
Project description
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:
pip install GeoModeler
Usage
Creating GeoJSON Objects
Here's an example of how to create a Point
object:
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:
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:
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:
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:
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:
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:
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 file for details.
Keywords
- geojson
- pydantic
- validation
- geospatial
- data-modeling
Author
This project is developed and maintained by jvanegmond.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file geomodeler-0.1.3b0.tar.gz
.
File metadata
- Download URL: geomodeler-0.1.3b0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ce57cc3b9900091b4a76e9f948096ea8fd043135121dbbe7b5dd950d6aadb74 |
|
MD5 | 96080369ba03194999313922597386c4 |
|
BLAKE2b-256 | 83d9191ad428e200974f6f20eb28018dc0cca0b5e00a161655ea4fd3ad4d40c8 |
File details
Details for the file geomodeler-0.1.3b0-py3-none-any.whl
.
File metadata
- Download URL: geomodeler-0.1.3b0-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1030dae349515c59b46a3bb8292b719363dd1020d9b44f495f78280ef89d925c |
|
MD5 | d0befd02e09e0bdb57ae841da22c953f |
|
BLAKE2b-256 | 9e1faefd21bf7fbf212c3bf75aac75571d96f9a5dfbc82ffd25b529beb75a873 |