Search code examples
node.jsgeojson

filter geojson by date


Is it possible to filter GeoJson data by date, now I only save the position in Mongoose. But I want to make some filters like, show position the last day, the last week, the last month and random dates.

From the documentation of GeoJson I read that date is not possible to add. So any one had done this?


Solution

  • Where does it say in the specifications that that's not possible? According to the specification a GeoJSON feature object must have a properties member which should be an object (or null):

    A feature object must have a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).

    http://geojson.org/geojson-spec.html#feature-objects

    That object can be used to store data relevant to that specific feature. For example:

    {
        "type": "Feature",
        "properties": {
            "myProperty": "myValue"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [0, 0]
        }
    }
    

    In that property object you can store the date(s) you need to work with:

    new Schema({
        'type': {
            type: String,
            default: 'Feature'
        },
        properties: {
            date: {
                type: Date,
                default: Date.now
            }
        },
        geometry: {
            type: {
                type: String,
                default: 'Point'
            },
            coordinates: {
                type: [Number]
            }
        }
    });