rapideditor/country-coder

Regions

Closed this issue · 3 comments

I'd like to be able to also get regions, which would sit at a level higher than countries.
Each country could belong to a single region, and there could be a lookup table or something.

There are many ways to slice up the world, but I'm thinking these 12 (+ Antarctica) would give us a bunch of flexibility:

  • North America
  • Central America
  • South America
  • Western Europe
  • Eastern Europe
  • Middle East
  • North Africa
  • Sub-Saharan Africa
  • Central and South Asia
  • Southeast Asia
  • East Asia
  • Oceania
  • Antarctica

@bhousel I discovered the UN M49 list which seems like a workable standard to support. It's a superset of ISO 3166-1 numeric-3 codes with a bunch of regions, including most of those you listed.

https://en.wikipedia.org/wiki/UN_M49
https://unstats.un.org/unsd/methodology/m49/

@bhousel I discovered the UN M49 list which seems like a workable standard to support. It's a superset of ISO 3166-1 numeric-3 codes with a bunch of regions, including most of those you listed.

whoa good find, that looks perfect! 👍

So I integrated the M49 list. I'm not totally sure how you want to work with this data but right now you can use the features endpoint like this:

const coder = new CountryCoder();
coder.features([-12.3, -37.1]));

The returned array will include the region features, then you can check the m49 property of each one to see if a particular point is in your region of interest.

This is sorta clunky so we should add endpoints for "give me all the features in the region with this code" and "is this point in the region with this code".