Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extend-geojson-properties

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extend-geojson-properties

Extende properties/attributes of geojson objects from separate dataset of jsons.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

extend-geojson-properties

Extend properties of geojson objects from separate dataset of jsons.

Installation

For node.js or with browserify

npm install extend-geojson-properties

To include in html page, download file index.js and rename to extend-geojson-properties.js

<script type="text/javascript" src="path/to/extend-geojson-properties.js"></script>

This create global variable extendGeoJSON.

Usage

This module return a function or create global function named extendGeoJSON that extends the geojson properties.

var extendGeoJSON = require('extend-geojson-properties');
extentGeoJSON(
  geojsons,   //array of features
  dataSet,    // array of json objects
  joinMap     // joining rules
);

joinMap structure must be like:

var joinMap = {
  geoKey:  // property key or feature id that can be used as join key  
  dataKey:  // key name json data that will be used as join key 
            // i.e. has same values as of geoKey
  propertyMap:[  // array of mapping among the  items that need to be extend 
                 // to geojson as properties
    {
      geoProperty: 'prop1' // output geojson will have property by 'prop1' name 
      dataProperty:'attr2' // json property that needs to be extended to geojson 
        // in this case property name 'attr2'    
    }, 
    //many more rules can be added
    {
      geoProperty: ,
      dataProperty: 
    },  
    ... 
  ]
};

Example

Here is the sample data set that I use for test also.

Original geojsons:

    var geojsons = [{
        type:'Feature',
        id: 'id1',
        geometry: {type: 'Point', coordinates: [34,50]},
        properties: { name: 'name1' }
      }, {
        type:'Feature',
        id: 'id3',
        geometry: {type: 'Point', coordinates: [10,35]},
        properties: { name: 'name3'}
      }, {
        type:'Feature',
        id: 'id2',
        geometry: {type: 'Point', coordinates: [-30,-50]},
        properties: { name: 'name2'}
      }];

Dataset containing the attributes that we want to extend to geojsons:

    var joinDataSet = [{
        attr1: 'name1',
        attr2: 'val1-2',
        attr3: {field : 'val1-3',count:23}
      }, {
        attr1: 'name2',
        attr2: 'val2-2',
        attr3: {field : 'val2-3',count:2}
      }, {
        attr1: 'name3',
        attr2: 'val3-2',
        attr3: {field : 'val3-3',count:105}
      }];

Joining rules or joinMap:

    var joinMap = {
      geoKey:'properties.name', //here geoKey can be feature 'id' also 
      dataKey: 'attr1',
      propertyMap:[{
          geoProperty: 'prop1',
          dataProperty:'attr2'
        }, {
          geoProperty: 'prop2',
          dataProperty: 'attr3.field'
        }, {
          geoProperty: 'count',
          dataProperty: 'attr3.count'
        }]
    };

Once we have set properly the joinMap the function is very simple :

extentGeoJSON(geojsons,dataSet,joinMap);

Now geojsons contains the extended properties:

    [{
      type:'Feature',
      id: 'id1',
      geometry: {type: 'Point', coordinates: [34,50]},
      properties: {
        name: 'name1',
        prop1: 'val1-2',
        prop2: 'val1-3',
        count: 23
      }
    }, {
      type:'Feature',
      id: 'id3',
      geometry: {type: 'Point', coordinates: [10,35]},
      properties: {
        name: 'name3',
        prop1: 'val3-2',
        prop2: 'val3-3',
        count: 105
      }
    }, {
      type:'Feature',
      id: 'id2',
      geometry: {type: 'Point', coordinates: [-30,-50]},
      properties: {
        name: 'name2',
        prop1: 'val2-2',
        prop2: 'val2-3',
        count:2
      }
    }]

##License This project is licensed under the terms of the MIT license.

Keywords

FAQs

Package last updated on 20 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc