Snippets

Piotr Szrajber Smart M.App - check whether your GeoJson has acceptable column names

Created by Piotr Szrajber last modified
/**
* Scan the GeoJSON for all the property names and check whether they are valid identifiers
*
* 2017-04-04 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
*/
function examineColumnNames(geojson) {
    Object.keys(geojson.features.reduce(function(p, v) {
        Object.keys(v.properties).forEach(function(attributeName) {
            p[attributeName] = 1;
        });
        return p;
    }, {})).forEach(function(attributeName) {
        console.log(attributeName + " is " + (/^[$A-Z_][0-9A-Z_$]*$/i.test(attributeName) ? "a valid" : "an invalid") + " attribute name.");
    });
}

// Usage:
examineColumnNames(/* your geojson */);

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.