npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extend-geojson-properties

v0.1.2

Published

Extende properties/attributes of geojson (array of features or FeatureCollction) from separate dataset of jsons.

Downloads

4

Readme

extend-geojson-properties

Extend properties of geojson (array of features or FeatureCollection) 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, dataSet, joinMap);
  • geojsons array of features or FeatureCollection
  • dataSet array of json objects from which properties need to be picked
  • joinMap joining rules

joinMap structure must be like:

var joinMap = { 
  geoKey: ... , 
  dataKey: ... ,
  popertyMap: ...
}
  • geoKey property key or feature id in geojson features that can be used as join key
  • dataKey key name in json data that will be used as join key i.e. has same value as of geoKey
  • propertyMap [optional] if not given extend all the keys of dataSet object (except dataKey) to geojson properties. If you want selective keys to be extended then provide array of objects of mapping among the items that need to be extend to geojson as properties
   {
     geoProperty: // string,  key path in geojson feature property name 
     dataProperty: // string, key path in dataSet object property/attributes name 
   }

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}
      }];

Case 1 joinMap does not contain the propertyMap

var joinMap = {
  geoKey:'properties.name', //here geoKey can be feature 'id' also 
  dataKey: 'attr1'};
extentGeoJSON(geojsons,dataSet,joinMap);

Output of case 1 Now geojsons contains the extended properties like this:

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

Case 2 joinMap contains the propertyMap

    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'
        }]
    };

extentGeoJSON(geojsons,dataSet,joinMap);

** Output of case 2** Now geojsons contains the extended properties like this:
```jsvascript 
    [{
      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.