{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://www.52north.org/schema/json/Geometry#",
    "type": "object",
    "required": [
        "type"
    ],
    "properties": {
        "type": {
            "type": "string"
        },
        "crs": {
            "$ref": "#/definitions/crs"
        }
    },
    "oneOf": [
        {
            "$ref": "#/definitions/GeometryCollection"
        },
        {
            "$ref": "#/definitions/Point"
        },
        {
            "$ref": "#/definitions/MultiPoint"
        },
        {
            "$ref": "#/definitions/LineString"
        },
        {
            "$ref": "#/definitions/MultiLineString"
        },
        {
            "$ref": "#/definitions/Polygon"
        },
        {
            "$ref": "#/definitions/MultiPolygon"
        }
    ],
    "definitions": {
        "GeometryCollection": {
            "required": [
                "geometries"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "GeometryCollection"
                    ]
                },
                "geometries": {
                    "type": "array",
                    "items": {
                        "$ref": "#"
                    }
                }
            }
        },
        "Point": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "Point"
                    ]
                },
                "coordinates": {
                    "$ref": "#/definitions/position"
                }
            }
        },
        "MultiPoint": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "MultiPoint"
                    ]
                },
                "coordinates": {
                    "$ref": "#/definitions/positionArray"
                }
            }
        },
        "LineString": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "LineString"
                    ]
                },
                "coordinates": {
                    "$ref": "#/definitions/lineString"
                }
            }
        },
        "MultiLineString": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "MultiLineString"
                    ]
                },
                "coordinates": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/lineString"
                    }
                }
            }
        },
        "Polygon": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "Polygon"
                    ]
                },
                "coordinates": {
                    "$ref": "#/definitions/polygonCoordinates"
                }
            }
        },
        "MultiPolygon": {
            "required": [
                "coordinates"
            ],
            "properties": {
                "type": {
                    "enum": [
                        "MultiPolygon"
                    ]
                },
                "coordinates": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/polygonCoordinates"
                    }
                }
            }
        },
        "lineString": {
            "allOf": [
                {
                    "$ref": "#/definitions/positionArray"
                },
                {
                    "minItems": 2
                }
            ]
        },
        "polygonCoordinates": {
            "type": "array",
            "minItems": 1,
            "items": {
                "allOf": [
                    {
                        "$ref": "#/definitions/positionArray"
                    },
                    {
                        "minItems": 4
                    }
                ]
            }
        },
        "position": {
            "type": "array",
            "minItems": 2,
            "maxItems": 3,
            "items": {
                "type": "number"
            }
        },
        "positionArray": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/position"
            }
        },
        "crs": {
            "type": "object",
            "required": [
                "type",
                "properties"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string"
                },
                "properties": {
                    "type": "object"
                }
            },
            "oneOf": [
                {
                    "properties": {
                        "type": {
                            "enum": [
                                "name"
                            ]
                        },
                        "properties": {
                            "required": [
                                "name"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "name": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                {
                    "properties": {
                        "type": {
                            "enum": [
                                "link"
                            ]
                        },
                        "properties": {
                            "required": [
                                "href"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "href": {
                                    "type": "string"
                                },
                                "type": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}