|
26 | 26 |
|
27 | 27 | ## Description
|
28 | 28 |
|
29 |
| -`geojson_pydantic` provides a suite of Pydantic models matching the GeoJSON specification [rfc7946](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1). Those models can be used for creating or validating geojson data. |
| 29 | +`geojson_pydantic` provides a suite of Pydantic models matching the GeoJSON specification [rfc7946](https://datatracker.ietf.org/doc/html/rfc7946). Those models can be used for creating or validating geojson data. |
30 | 30 |
|
31 | 31 | ## Install
|
32 | 32 |
|
@@ -70,7 +70,7 @@ assert feat.type == "Feature"
|
70 | 70 | assert type(feat.geometry) == Point
|
71 | 71 | assert feat.properties["name"] == "jeff"
|
72 | 72 |
|
73 |
| -fc = FeatureCollection(features=[geojson_feature, geojson_feature]) |
| 73 | +fc = FeatureCollection(type="FeatureCollection", features=[geojson_feature, geojson_feature]) |
74 | 74 | assert fc.type == "FeatureCollection"
|
75 | 75 | assert len(fc) == 2
|
76 | 76 | assert type(fc.features[0].geometry) == Point
|
@@ -182,6 +182,44 @@ feat = MyPointFeatureModel(**geojson_feature)
|
182 | 182 | assert feat.properties.name == "drew"
|
183 | 183 | ```
|
184 | 184 |
|
| 185 | +## Enforced Keys |
| 186 | + |
| 187 | +Starting with version `0.6.0`, geojson-pydantic's classes will not define default keys such has `type`, `geometry` or `properties`. |
| 188 | +This is to make sure the library does well its first goal, which is `validating` GeoJSON object based on the [specification](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1) |
| 189 | + |
| 190 | + o A GeoJSON object has a member with the name "type". The value of |
| 191 | + the member MUST be one of the GeoJSON types. |
| 192 | + |
| 193 | + o A Feature object HAS a "type" member with the value "Feature". |
| 194 | + |
| 195 | + o A Feature object HAS a member with the name "geometry". The value |
| 196 | + of the geometry member SHALL be either a Geometry object as |
| 197 | + defined above or, in the case that the Feature is unlocated, a |
| 198 | + JSON null value. |
| 199 | + |
| 200 | + o A Feature object HAS a member with the name "properties". The |
| 201 | + value of the properties member is an object (any JSON object or a |
| 202 | + JSON null value). |
| 203 | + |
| 204 | + |
| 205 | +```python |
| 206 | +from geojson_pydantic import Point |
| 207 | + |
| 208 | +## Before 0.6 |
| 209 | +Point(coordinates=(0,0)) |
| 210 | +>> Point(type='Point', coordinates=(0.0, 0.0), bbox=None) |
| 211 | + |
| 212 | +## After 0.6 |
| 213 | +Point(coordinates=(0,0)) |
| 214 | +>> ValidationError: 1 validation error for Point |
| 215 | + type |
| 216 | + field required (type=value_error.missing) |
| 217 | + |
| 218 | +Point(type="Point", coordinates=(0,0)) |
| 219 | +>> Point(type='Point', coordinates=(0.0, 0.0), bbox=None) |
| 220 | +``` |
| 221 | + |
| 222 | + |
185 | 223 | ## Contributing
|
186 | 224 |
|
187 | 225 | See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
0 commit comments