Skip to content

ibnjunaid/node-geojson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-geojson

Perform CRUD operations on geoJSON data using node

Installation

For node, use npm: $ npm install node-geojson

Getting Started

    const geoJSON = require('node-geojson');  

    async function main(){
        const geodata = await geoJSON.createUsingFile("path/to/geoJSON/file");
        
        // Optional filePath to manipulate data in memory for front-end applications 
        // without filesystem
        const inMemorygeodata = geoJSON.createFromObject(jsonObject); 
    }

Documentation

Instantiate

createUsingFile function reads a geoJSON file and returns a promise which resolves to an Object of FeatureCollection class.

createFromObject function takes a valid geoJSON Object along with an optional filePath where we may want to save the file, and returns an Object of FeatureCollection class.

FeatureCollection : class

Methods

Instance of FeatureCollection provide following methods to operate on the geojson.

Add
    // Add a new feature of interface feature to features Array
    FeatureCollection.Add(f) 
Find
    // Returns  features that matches the Query q
    FeatureCollection.Find(q?:Query) 

    // When called without any parameter, returns all features in the collection
    FeatureCollection.Find() 
FindByGeometry
    /* 
        Return features matching geometry 
        specified in the parameter 
    */
    const geometry = {type:"Point"}

    FeatureCollection.FindByGeometry(geometry)
FindByProperty
    // Return features matching properties 
    // specified in the parameter 
    const property = {
        name : "pengooX",
        Id : 123
    }
    
    FeatureCollection.FindByProperty(property)
Update
    const update =  {
        properties : {
        color : red,
        category : 'Quarantine zone'
    }};
    const query = {
        properties : {
            locality : "XYZ"
        }
    }
    //  Update features matching query
    // by adding properties from update Object to each feature.
    FeatureCollection.Update(update : Query, query : Query)

    //  Update all features in the FeatureCollection, when only update is passed 
    FeatureCollection.Update(update : Query)
Remove
    //  Remove features matching query
    FeatureCollection.Remove(query : Query)

Methods automatically donot write the data to disk. To write data to disk call Save method, optionally passing the path where you want to save the file. If no path is specified and FeatureCollection was created using createUsingFile function, then data is overwritten to the same file In case of FeatureCollection created using createFromObject, the filePath is mandatory if you want to call Save without path it will fail.

Save
    //Save the file to the specified path
    FeatureCollection.Save("path/where/i/want/to/save")
    
    // for createUsingFile
    // overwrite to same path from which it was created 
    FeatureCollection.Save()
GetAllFeatures

GetAllFeatures return all features in the collection

    FeatureCollection.GetAllFeatures()

Interface

All functions take parameter of the following form satisfying the Query interface

const param = {
    geometry: {
        type: 'Point'
    },
    properties: {
        name : "PengooX",
        color : ' red'
        // ... many more
    }
}

Example Usage

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published