koppen-climate-lookup
v2.0.0
Published
Look up Koppen climate classifications by latitude and longitude
Maintainers
Readme
koppen-climate-lookup
A TypeScript package for looking up Köppen climate classifications by latitude and longitude coordinates. Includes a comprehensive global dataset of Köppen climate classifications at 0.5° (30 arc minute) resolution.
Installation
pnpm add koppen-climate-lookupUsage
import KoppenLookup from 'koppen-climate-lookup';
// getInstance() is synchronous; the dataset is inlined at build time.
const lookup = KoppenLookup.getInstance();
// Look up a location
const result = lookup.findNearest(51.5074, -0.1278, 100);
console.log(result);
// Output:
// {
// latitude: 51.75,
// longitude: -0.25,
// koppenClass: 'Cfb',
// distance: 28.3
// }API
KoppenLookup
Main class for performing Köppen climate classification lookups. Uses a singleton pattern.
static getInstance(): KoppenLookup
Returns the shared KoppenLookup instance, initializing it on first call. This is synchronous because the dataset is bundled into the package.
findNearest(latitude: number, longitude: number, maxDistance: number = 100): NearestPoint | null
latitude: Latitude to look up (-90 to 90)longitude: Longitude to look up (-180 to 180)maxDistance: Maximum search radius in kilometers (default: 100)- Returns:
NearestPointobject ornullif none found - Throws: Error if coordinates or
maxDistanceare not finite valid numbers
Returns the nearest Köppen classification within the specified radius, or null if none found. Longitude wraps across the antimeridian, so points near ±180° are handled correctly.
Types
interface KoppenPoint {
latitude: number; // Latitude of the matched point
longitude: number; // Longitude of the matched point
koppenClass: string; // Köppen classification code
}
interface NearestPoint extends KoppenPoint {
distance: number; // Distance in kilometers from input coordinates
}Dataset
- Source: World Maps of Köppen-Geiger climate classification
- Period: 1986–2010 (re-analyzed March 2017 dataset, downscaled after Rubel et al. 2017)
- Resolution: 0.5° (30 arc minutes), 92,416 land grid cells
- Coverage: Land only; ocean cells are omitted, so
findNearestreturnsnullwhen no land is withinmaxDistance
The 0.5° grid is derived from the source's 5 arc minute raster by assigning each cell the majority class of its constituent high-resolution cells. Cells the source raster marks as ocean but that the original 0.5° product classified as land (small islands, ice shelves) retain their original classification.
If you use this data, please cite:
Kottek, M., J. Grieser, C. Beck, B. Rudolf, and F. Rubel, 2006: World Map of the Köppen-Geiger climate classification updated. Meteorol. Z., 15, 259-263. DOI: 10.1127/0941-2948/2006/0130.
Rubel, F., K. Brugger, K. Haslinger, and I. Auer, 2017: The climate of the European Alps: Shift of very high resolution Köppen-Geiger climate zones 1800-2100. Meteorol. Z., DOI: 10.1127/metz/2016/0816.
Köppen Classification Codes
The package uses standard Köppen climate classification codes. The dataset contains all of the following classes:
Af: Tropical rainforestAm: Tropical monsoonAs: Tropical savanna (dry summer)Aw: Tropical savanna (dry winter)BSh: Hot semi-aridBSk: Cold semi-aridBWh: Hot desertBWk: Cold desertCfa: Humid subtropicalCfb: OceanicCfc: Subpolar oceanicCsa: Mediterranean hot summerCsb: Mediterranean warm summerCsc: Mediterranean cold summerCwa: Monsoon-influenced humid subtropicalCwb: Subtropical highlandCwc: Cold subtropical highlandDfa: Hot summer continentalDfb: Warm summer continentalDfc: SubarcticDfd: Extremely cold subarcticDsa: Mediterranean-influenced hot summer continentalDsb: Mediterranean-influenced warm summer continentalDsc: Mediterranean-influenced subarcticDsd: Mediterranean-influenced extremely cold subarcticDwa: Monsoon-influenced hot summer continentalDwb: Monsoon-influenced warm summer continentalDwc: Monsoon-influenced subarcticDwd: Monsoon-influenced extremely cold subarcticEF: Ice capET: Tundra
Development
# Install dependencies
pnpm install
# Type-check, test and build
pnpm run type-check
pnpm test
pnpm run buildLicense
ISC
