I am new to JSON and GeoJSON and would like to start to use this but I am a little confused about some things. Perhaps you can help me out:
1) Is there a GeoJSON validator out there? 2) Is the text below valid GeoJSON? To be a valid GeoJSON file do all the GeoJSON objects have to live in a GeoJSON array or can they be stored willie nellie as below?
The data below is a return from the geocouch example on github:
{
"rows": [
{
"id": "augsburg",
"bbox": [
10.898333,
48.371667,
10.898333,
48.371667
],
"geometry": {
"type": "Point",
"coordinates": [
10.898333,
48.371667
]
},
"value": [
"augsburg",
[
10.898333,
48.371667
]
]
},
{
"id": "oakland",
"bbox": [
-122.270833,
37.804444,
-122.270833,
37.804444
],
"geometry": {
"type": "Point",
"coordinates": [
-122.270833,
37.804444
]
},
"value": [
"oakland",
[
-122.270833,
37.804444
]
]
}
]
}
Answer
GeoJSON is also simply JSON, so I usually run it through the validator at http://jsonlint.com/ to check it passes this first. Unfortunately I don't think there is an online validator specific to GeoJSON.
You can however use the GDAL GeoJSON driver to try and load or get information about the dataset - if it fails it's invalid. You can also use the Python Shapely library to check features as it uses a GeoJSON-like notation for geometry.
Your example seems to be missing some type attributes - features must have a type attribute and can be grouped in collections if needed. The key criteria for GeoJSON objects (from the spec) are:
- GeoJSON always consists of a single object
- The GeoJSON object may have any number of members (name/value pairs).
- The GeoJSON object must have a member with the name "type"
- The value of the type member must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection". The case of the type member values must be as shown here.
- A GeoJSON object may have an optional "crs" member, the value of which must be a coordinate reference system object
- A GeoJSON object may have a "bbox" member, the value of which must be a bounding box array
The GDAL driver also had issues if I did not set a "crs"
value
For more details take a look at the full GeoJSON specification and examples.
I also found the GeoJSON from CloudMade's services very useful for comparison - http://developers.cloudmade.com/projects/geocoding/examples
No comments:
Post a Comment