GeoModeler


NameGeoModeler JSON
Version 0.1.dev0 PyPI version JSON
download
home_page
SummaryGeoModeler 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.
upload_time2024-01-19 08:36:40
maintainer
docs_urlNone
author
requires_python>=3.10
licenseMIT
keywords geojson pydantic validation geospatial data-modeling
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # GeoJSON Models

This project provides a set of Python models for GeoJSON objects conforming to RFC 7946. It includes models for all the basic GeoJSON types:

- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
- Feature
- FeatureCollection

These models are implemented using the Pydantic library, which provides runtime data validation and settings management using Python type annotations.

## Installation

This project requires Python 3.10 or higher. You can install it using pip:

```bash
pip install geo-modeler
```

## Usage

Here is an example of how to create a Point object:

```python
from src import Point

point = Point(type='Point', coordinates=[1.0, 2.0])
```

You can also validate a GeoJSON string:

```python
point = Point.validate_json('{"type":"Point","coordinates":[1.0,2.0]}')
```

And convert a model to a GeoJSON string:

```python
json_string = point.model_dump_json()
```
### Initializing and Validating
To initialize a `FeatureCollection` or a `Point` using their corresponding JSON representations, you can use the `validate_json` method provided by the `geojson_models` library. This method will take care of all subtypes and validate the structure of the GeoJSON.

If the GeoJSON does not follow the right-hand rule, a warning will be issued, but it won't break the execution. 

When dumping the model to a GeoJSON string using the `model_dump_json` method, you can use the `unset` option to exclude empty defaults.

Here is an example of how to use these features:

```python
from src import FeatureCollection, Point

# Initialize a FeatureCollection with data Point from a JSON string.
feature_collection_json = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":"1","name":"Litter Bin","description":"Litter Bin","type":"Litter Bin","colour":"Green","location":"Leeds","location_type":"Street","location_subtype":"Road","location_name":"Leeds","latitude":"53.71583","longitude":"-1.74448","easting":"429000","northing":"433000","northing":"433000","postcode_sector":"LS1","postcode_district":"LS","postcode_area":"LS","uprn":"100335","organisation":"Leeds City Council","organisation_uri":"http://opendatacommunities.org/id/leeds-city-council","organisation_label":"Leeds City Council","uri":"http://opendatacommunities.org/id/litter-bin/leeds/1","label":"Litter Bin","notation":"1","notation_uri":"http://opendatacommunities.org/id/litter-bin/leeds/1","notation_label":"1","notation_type":"http://opendatacommunities.org/def/litter-bin/leeds/notation","notation_type_label":"Notation"},"geometry":{"type":"Point","coordinates":[-1.74448,53.71583]}}]}'
feature_collection = FeatureCollection.model_validate_json(feature_collection_json)

# Initialize a single Point with a JSON string
point_json = '{"type":"Point","coordinates":[1.0,2.0]}'
point = Point.model_validate_json(point_json)


# Dump the models to GeoJSON strings, excluding empty defaults
print(feature_collection.model_dump_json(exclude_unset=True))
# {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"id":"1","name":"Litter Bin","description":"Litter Bin","type":"Litter Bin","colour":"Green","location":"Leeds","location_type":"Street","location_subtype":"Road","location_name":"Leeds","latitude":"53.71583","longitude":"-1.74448","easting":"429000","northing":"433000","postcode_sector":"LS1","postcode_district":"LS","postcode_area":"LS","uprn":"100335","organisation":"Leeds City Council","organisation_uri":"http://opendatacommunities.org/id/leeds-city-council","organisation_label":"Leeds City Council","uri":"http://opendatacommunities.org/id/litter-bin/leeds/1","label":"Litter Bin","notation":"1","notation_uri":"http://opendatacommunities.org/id/litter-bin/leeds/1","notation_label":"1","notation_type":"http://opendatacommunities.org/def/litter-bin/leeds/notation","notation_type_label":"Notation"},"geometry":{"type":"Point","coordinates":[-1.74448,53.71583]}}]}
print(point.model_dump_json())
# {"type":"Point","coordinates":[1.0,2.0]}
```

This will output valid GeoJSON, although it may contain warnings for direction. The `model_validate_json` method also validates lengths and required fields according to the GeoJSON specification.
## Testing

This project includes a suite of tests that you can run using pytest:

```bash
pytest
```

## Contributing

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

## License

This project is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "GeoModeler",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "geojson,pydantic,validation,geospatial,data-modeling",
    "author": "",
    "author_email": "jvanegmond <jvanegmond@silverbirchgeospatial.com>",
    "download_url": "https://files.pythonhosted.org/packages/41/a4/8456992227ea0708ff0860fda4ad2715d35ebfa1d9d82f614d21460555e6/GeoModeler-0.1.dev0.tar.gz",
    "platform": null,
    "description": "# GeoJSON Models\n\nThis project provides a set of Python models for GeoJSON objects conforming to RFC 7946. It includes models for all the basic GeoJSON types:\n\n- Point\n- MultiPoint\n- LineString\n- MultiLineString\n- Polygon\n- MultiPolygon\n- GeometryCollection\n- Feature\n- FeatureCollection\n\nThese models are implemented using the Pydantic library, which provides runtime data validation and settings management using Python type annotations.\n\n## Installation\n\nThis project requires Python 3.10 or higher. You can install it using pip:\n\n```bash\npip install geo-modeler\n```\n\n## Usage\n\nHere is an example of how to create a Point object:\n\n```python\nfrom src import Point\n\npoint = Point(type='Point', coordinates=[1.0, 2.0])\n```\n\nYou can also validate a GeoJSON string:\n\n```python\npoint = Point.validate_json('{\"type\":\"Point\",\"coordinates\":[1.0,2.0]}')\n```\n\nAnd convert a model to a GeoJSON string:\n\n```python\njson_string = point.model_dump_json()\n```\n### Initializing and Validating\nTo initialize a `FeatureCollection` or a `Point` using their corresponding JSON representations, you can use the `validate_json` method provided by the `geojson_models` library. This method will take care of all subtypes and validate the structure of the GeoJSON.\n\nIf the GeoJSON does not follow the right-hand rule, a warning will be issued, but it won't break the execution. \n\nWhen dumping the model to a GeoJSON string using the `model_dump_json` method, you can use the `unset` option to exclude empty defaults.\n\nHere is an example of how to use these features:\n\n```python\nfrom src import FeatureCollection, Point\n\n# Initialize a FeatureCollection with data Point from a JSON string.\nfeature_collection_json = '{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"id\":\"1\",\"name\":\"Litter Bin\",\"description\":\"Litter Bin\",\"type\":\"Litter Bin\",\"colour\":\"Green\",\"location\":\"Leeds\",\"location_type\":\"Street\",\"location_subtype\":\"Road\",\"location_name\":\"Leeds\",\"latitude\":\"53.71583\",\"longitude\":\"-1.74448\",\"easting\":\"429000\",\"northing\":\"433000\",\"northing\":\"433000\",\"postcode_sector\":\"LS1\",\"postcode_district\":\"LS\",\"postcode_area\":\"LS\",\"uprn\":\"100335\",\"organisation\":\"Leeds City Council\",\"organisation_uri\":\"http://opendatacommunities.org/id/leeds-city-council\",\"organisation_label\":\"Leeds City Council\",\"uri\":\"http://opendatacommunities.org/id/litter-bin/leeds/1\",\"label\":\"Litter Bin\",\"notation\":\"1\",\"notation_uri\":\"http://opendatacommunities.org/id/litter-bin/leeds/1\",\"notation_label\":\"1\",\"notation_type\":\"http://opendatacommunities.org/def/litter-bin/leeds/notation\",\"notation_type_label\":\"Notation\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.74448,53.71583]}}]}'\nfeature_collection = FeatureCollection.model_validate_json(feature_collection_json)\n\n# Initialize a single Point with a JSON string\npoint_json = '{\"type\":\"Point\",\"coordinates\":[1.0,2.0]}'\npoint = Point.model_validate_json(point_json)\n\n\n# Dump the models to GeoJSON strings, excluding empty defaults\nprint(feature_collection.model_dump_json(exclude_unset=True))\n# {\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"id\":\"1\",\"name\":\"Litter Bin\",\"description\":\"Litter Bin\",\"type\":\"Litter Bin\",\"colour\":\"Green\",\"location\":\"Leeds\",\"location_type\":\"Street\",\"location_subtype\":\"Road\",\"location_name\":\"Leeds\",\"latitude\":\"53.71583\",\"longitude\":\"-1.74448\",\"easting\":\"429000\",\"northing\":\"433000\",\"postcode_sector\":\"LS1\",\"postcode_district\":\"LS\",\"postcode_area\":\"LS\",\"uprn\":\"100335\",\"organisation\":\"Leeds City Council\",\"organisation_uri\":\"http://opendatacommunities.org/id/leeds-city-council\",\"organisation_label\":\"Leeds City Council\",\"uri\":\"http://opendatacommunities.org/id/litter-bin/leeds/1\",\"label\":\"Litter Bin\",\"notation\":\"1\",\"notation_uri\":\"http://opendatacommunities.org/id/litter-bin/leeds/1\",\"notation_label\":\"1\",\"notation_type\":\"http://opendatacommunities.org/def/litter-bin/leeds/notation\",\"notation_type_label\":\"Notation\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-1.74448,53.71583]}}]}\nprint(point.model_dump_json())\n# {\"type\":\"Point\",\"coordinates\":[1.0,2.0]}\n```\n\nThis will output valid GeoJSON, although it may contain warnings for direction. The `model_validate_json` method also validates lengths and required fields according to the GeoJSON specification.\n## Testing\n\nThis project includes a suite of tests that you can run using pytest:\n\n```bash\npytest\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request.\n\n## License\n\nThis project is licensed under the terms of the MIT license.\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.dev0",
    "project_urls": {
        "homepage": "https://github.com/jvanegmond93/geo_modeler"
    },
    "split_keywords": [
        "geojson",
        "pydantic",
        "validation",
        "geospatial",
        "data-modeling"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd983720d4fb60e28fd874108993ae0bc4977fb7885c537626bc1348d2f47958",
                "md5": "e8e03f6e3c3aaba43f114fff4da05d6b",
                "sha256": "8d4f5cb0caf7830f72a1b5a91e522f49c90fffb557814f92528b06af1ed9853f"
            },
            "downloads": -1,
            "filename": "GeoModeler-0.1.dev0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8e03f6e3c3aaba43f114fff4da05d6b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 15422,
            "upload_time": "2024-01-19T08:36:38",
            "upload_time_iso_8601": "2024-01-19T08:36:38.897884Z",
            "url": "https://files.pythonhosted.org/packages/bd/98/3720d4fb60e28fd874108993ae0bc4977fb7885c537626bc1348d2f47958/GeoModeler-0.1.dev0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41a48456992227ea0708ff0860fda4ad2715d35ebfa1d9d82f614d21460555e6",
                "md5": "2ab59dce67bdf78c738ca4029b958a1d",
                "sha256": "6a7fab6dff925db39012af518d1d7fecb25cf531f321690626c495ea18e3591e"
            },
            "downloads": -1,
            "filename": "GeoModeler-0.1.dev0.tar.gz",
            "has_sig": false,
            "md5_digest": "2ab59dce67bdf78c738ca4029b958a1d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 13349,
            "upload_time": "2024-01-19T08:36:40",
            "upload_time_iso_8601": "2024-01-19T08:36:40.539420Z",
            "url": "https://files.pythonhosted.org/packages/41/a4/8456992227ea0708ff0860fda4ad2715d35ebfa1d9d82f614d21460555e6/GeoModeler-0.1.dev0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-19 08:36:40",
    "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"
}
        
Elapsed time: 0.16679s