A GeoJSON Validation Library
Check JSON objects to see whether or not they are valid GeoJSON. Validation is based off of the GeoJSON Format Specification revision 1.0
const gjv = require("geojson-validation");
Â
const validFeatureCollection = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
            "properties": {"prop0": "value0"}
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
                ]
            },
            "properties": {
                "prop0": "value0",
                "prop1": 0.0
            }
        }
    ]
};
Â
if(gjv.valid(validFeatureCollection)){
    console.log("this is valid GeoJSON!");
}
Â
const invalidFeature =  {
    "type": "feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [
            [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
        ]
    },
    "properties": {
        "prop0": "value0",
        "prop1": 0.0
    }
};
Â
const trace = gjv.isFeature(invalidFeature, true)
console.log(trace)
first install goballynpm install geojson-validation -g
Then you can use gjv
to validate file such asgjv file1 file2..
Or you can stream files to it cat file | gjv
gjv
will either return a list of error or a valid
if the files are indeed valid.
All Function return a boolean
and take a JSON object that will be evalatued to see if it is a GeoJSON object, with the exception of define.
Define a Custom Validation for the give type
. type
can be "Feature", "FeatureCollection", "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Bbox", "Position", "GeoJSON" or "GeometryObject".
The function
is passed the object
being validated and should return a string
or an array
of strings representing errors. If there are no errors then the function should not return anything or an empty array. See the example for more.
const gjv = require("geojson-validation");
Â
gjv.define("Position", (position) => {
   Â
    errors = [];
    if(position[0] < -180 || position[0] > 180){
        errors.push("the x must be between -180 and 180");
    }
    if(position[1] < -90 || position[1] > 90){
        errors.push("the y must be between -90 and 90");
    }
    return errors;
Â
});
Â
const gj = {type: "Point", coordinates: [-200,3]};
gjv.isPoint(gj);
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4