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

geographer

v0.0.5

Published

get terrain data for a set of latitude/longitude coordinates or location name

Downloads

31

Readme

Geographer - Geographic information from place names

NPM

Download with:

npm install -g geographer //installing globally means you set API username once
//or
npm install geographer    //each project gets its own geographer installation

This module lets you get geographic inforamtion about cities and places in the USA easily and conveniently.

There's a command line component which allows you to set your username (tied to your Geonames API key). You can also just add it to the 'config.json' file manually if that's your jam.

Full List of Setup Commands:

geographer -u YOUR_GEONAMES_USERNAME
geographer -l LANGUAGE_CODE             //default set to 'en' for english
geographer -c YOUR_COUNTRY_CODE_OR_NAME //default set to 'US' or united states
//or
geo -u YOUR_USERNAME
geo -l LANGUAGE_CODE
geo -c YOUR_COUNTRY_CODE_OR_NAME

Instad of setting your username this way you can always just edit teh config.json file directly. Your username is how the API links to your API key for the geonames API.

To work with these commands on only the current directory's copy of geographer use:

node_modules/.bin/geographer -u YOUR_GEONAMES_USERNAME
//or
node_modules/.bin/geo -u YOUR_GEONAMES_USERNAME

If you country is more than one word set it like so:

geo -c 'united states'

What do you need for this to work?

A Geonames username setup to work with the API key:

Go to http://www.geonames.org/manageaccount, create an account for free and then click the button right underneath the signup form "enable for free web service." It should take 1 hour for your key to activate for your chosen username. Geonames doesn't give an exact number anywhere, I'd say anywhere around 2000 requests per hour should be fine.

If it's too confusing to set up or you need moral support just hit me up on twitter
handle @yvanscher, or if my module is a pile of donkey dung and you'd like to tell me just how much better it could be tweet at me.

Usage

Setup:

geo -u YOUR_USERNAME

Call format:

//maxresults is optional
geographer('placename', 'statename/statecode', [maxresults], function(results){
  console.log(results)
})

Example:

var geographer = require('geographer')

geographer('Ithaca', 'NY', 2, function(results){
  console.log(results)
})
//or
geographer('Ithaca', 'new york', 2 , function(results){ //new york not case sensitive
  console.log(results)
})  

//returns

{ emptyfields: { 'Ithaca Tompkins Regional Airport': { '0': [Object] } },
  terraindata:
   { potentialresults: 62,
     Ithaca:
      { country: 'United States',
        region: 'New York',
        county: 'Tompkins County',
        locationtype: 'seat of a second-order administrative division',
        terraintype: 'city, village,...',
        elevation: 125,
        latitude: '42.44063',
        longitude: '-76.49661',
        boundingbox: [Object],
        timezone: [Object],
        population: 30014 },
     'Ithaca Tompkins Regional Airport':
      { country: 'United States',
        region: 'New York',
        locationtype: 'airport',
        terraintype: 'spot, building, farm',
        elevation: 335,
        latitude: '42.49083',
        longitude: '-76.45833',
        timezone: [Object]
      }
    }
}

Why does it get an airport as the second result? Clearly we asked for the city. Since we set the finalparameter in our call to geographer('Ithaca', 'NY', 2) to 2, geographer tries to get more places that might fit the description in addition to the most likely result. This final parameter is optional and if left blank or omitted all possible results will be returned. To just get the city of Ithaca set the final parameter to 1.

Any fields that could not be found a location gets cleaned out of the terraindata object and put into the emptyfields object with the location name as an index. If you don't want that info just discard it.

Calling:

geographer('Ithaca', 'NY', function(results){})

Returns 62 results for locations that potentially match the name Ithaca. From most likely desired to least likely desired.

In the Future

In the world of tommorrow I'm hoping to add the ability to create geonames API keys and usernames directly from your code or command line. For now we have to use Geonames functional website for signing up.I'm working on the ability to exclude certain keywords forall queries or just from queries that search for placename "ithaca." IT IS NOT IMPLEMENTED YET.

What is in the 'info' folder?

Magical country codes, language codes, US states. Some are used others are there for any future work on the project.