Skip to main content

geofeatkit

Offline geo features from latitude / longitude for tabular ML: country, nearest and main city, capitals, city types and sizes, distances, density of neighbours, ring / sector / multi-core city structure, grids, and a few urban-economics formulas (Reilly, Huff, Zipf). The city data is bundled, so nothing is downloaded at run time.

pip install geofeatkit

Depends only on numpy, pandas, scipy, scikit-learn. h3 is optional (hex_cell).

Quick start

import geofeatkit as gk

gk.help()                                   # cheat sheet (in Russian)

X, cat = gk.make_X(df, "lat", "lon")        # ready matrix + categorical columns
model = CatBoostRegressor(cat_features=cat).fit(X, y)

feats = gk.get_features(df, lat_col="lat", lon_col="lon")   # reference features only

gk.get_country(55.75, 37.62)                # 'RU'
gk.get_capital("RU")                        # {'name': 'Moscow', 'lat': ..., ...}
gk.get_main_city(lat, lon)                  # biggest city within 60 km
gk.get_city_type(lat, lon)                  # capital / region_center / ... + size class
gk.haversine(lat1, lon1, lat2, lon2)        # km

What is inside

Group Functions
Ready matrix for CatBoost make_X, cat_columns
Everything at once get_features
Cities and countries get_country, get_country_info, get_capital, get_nearest_city, get_main_city, get_city_type, dist_to_capital, load_cities, load_countries
Distances haversine, manhattan, bearing, to_km, travel_minutes
Your own points dist_to_nearest, count_within
Density / neighbours neighbor_features, oof_neighbor_features (leak-free target stats)
City structure find_centers, center_features, multi_center_features, city_shape (ring / sector / multi-core heuristic)
Grids and validation grid_cell, hex_cell, spatial_groups, group_stats
Urban economics city_gravity, huff_probabilities, reilly_breakpoint, zipf_expected

city_type comes from the GeoNames feature code: PPLC capital, PPLA region center, PPLA2 district center, PPLA3/4/5 local center, PPLX city section, everything else settlement. size_class: tiny < 10k, small < 50k, medium < 100k, big < 250k, large < 1M, million.

get_country returns the country of the nearest city, so points right on a border or far out at sea can get the neighbouring country.

Leak-free neighbour target features

tr_f = gk.oof_neighbor_features(train.lat, train.lon, y)                 # train rows
te_f = gk.neighbor_features(test.lat, test.lon, train.lat, train.lon, values=y)

Building from source

The data files are not stored in the repository. Build them once:

python tools/build_data.py      # downloads GeoNames dumps (~12 MB)
python -m pytest tests          # tests use a tiny fake data set
python -m build

Set GEOFEATKIT_DATA_DIR to use your own data directory.

Data and license

Code: MIT. City and country data: GeoNames, licensed under CC BY 4.0.

Metadata

Release files for geofeatkit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geofeatkit 0.1.0
File Size Uploaded Provenance Actions
geofeatkit-0.1.0.tar.gz 5.5 MB Without provenance Details for geofeatkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for geofeatkit 0.1.0
File Interpreter ABI Platform Actions
geofeatkit-0.1.0-py3-none-any.whl Python 3 none any Details for geofeatkit-0.1.0-py3-none-any.whl

Total release size: 11.1 MB

Release files / geofeatkit-0.1.0.tar.gz

Download URL geofeatkit-0.1.0.tar.gz
Size 5.5 MB
Tags Source
SHA-256 checksum
How to use checksums
0d0774bfa87ca16544c0bc2f14bcfc45c354a5ebf3242117f8d9d0ce6115d2e7
BLAKE2b-256 checksum
How to use checksums
726aec514f6d3610bef9840c737fd4e4137b97e50a2ddf6ee83ed3c13d4c0724
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / geofeatkit-0.1.0-py3-none-any.whl

Download URL geofeatkit-0.1.0-py3-none-any.whl
Size 5.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c3efff76019b86c433b26c3af6c511426307bca0820f6f791ed112c05b8eb88b
BLAKE2b-256 checksum
How to use checksums
dbdbbc448236cb43b7e2d16ffa8be27b9348493eff70cba69f016d9a32871239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for geofeatkit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page