wkt
wkt makes it easy to grab Well-Known Text strings for countries, states, and cities around the world.
Here's how you can grab the polygon for New York State for example:
import wkt
wkt.us.states.new_york() # => "POLYGON((-79.7624 42.5142,-79.0672 42.7783..."
wkt is interoperable with many Pythonic geospatial tools like Shapely, GeoPandas, Sedona, and Dask!
You can also fetch WKTs from the Overture Maps Foundation tables as follows:
table_name = "wherobots_open_data.overture_maps_foundation.divisions_division_area"
wkt.omf(sedona, table_name).state("US", "US-AZ") # => "POLYGON((..."
Installation
Just run pip install wkt.
This library doesn't have any dependencies, so it's easy to install anywhere.
Shapely + wkt
Let's create a Shapely polygon with wkt:
import wkt
from shapely import from_wkt
alaska = from_wkt(wkt.us.states.alaska())
Check to make sure that a Shapely Polygon is created:
type(alaska) # => shapely.geometry.polygon.Polygon
Compute the area of the polygon:
alaska.area # => 353.4887780300002
GeoPandas + wkt
Create a GeoPandas DataFrame with wkt:
import geopandas as gpd
import pandas as pd
data = {
"state": ["colorado", "new_mexico"],
"geometry": [from_wkt(wkt.us.states.colorado()), from_wkt(wkt.us.states.new_mexico())]
}
df = pd.DataFrame(data)
gdf = gpd.GeoDataFrame(df, geometry="geometry")
Add a column with centroids:
gdf['centroid'] = gdf.geometry.centroid
Look at the results:
state geometry centroid
0 colorado POLYGON ((-109.0448 37.0004, POINT (-105.54643 38.99855)
1 new_mexico POLYGON ((-109.0448 36.9971, POINT (-106.10366 34.42267)
Sedona + wkt
Read the Overture Maps Foundation places dataset:
places = sedona.table("wherobots_open_data.overture_maps_foundation.places_place")
places.createOrReplaceTempView("places")
Find all the barbecue restaurants in the state of Florida:
query = f"""
select * from places
where
categories.primary = 'barbecue_restaurant' and
ST_Contains(ST_GeomFromWKT('{wkt.us.states.florida()}'), geometry)
"""
res = sedona.sql(query)
res.count() # => 1386
WKTs from Overture data
It's easy to get the WKT for countries, states, and cities from the Overture data:
TODO
Contributing
Feel free to submit a pull request with additional WKTs!
You can also create an issue to discuss ideas before writing any code.
You can also check issues with the "help wanted" tag for contribution ideas.
Developing
You can run the test suite with uv run pytest tests.
Metadata
Release files for wkt 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wkt-0.1.4.tar.gz | 33.1 kB | Without provenance | Details for wkt-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wkt-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for wkt-0.1.4-py3-none-any.whl |
Total release size: 64.1 kB
Release files / wkt-0.1.4.tar.gz
| Download URL | wkt-0.1.4.tar.gz |
|---|---|
| Size | 33.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74589a7c14770623e4029763ea0a68c0f78bc0f25e967537e3e24e4e1edee89b
|
|
BLAKE2b-256 checksum How to use checksums |
0e8d6c440ca35536cbe5323ea0907a2143519e0c1ba999afaa1effcda0953499
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.3
|
Release files / wkt-0.1.4-py3-none-any.whl
| Download URL | wkt-0.1.4-py3-none-any.whl |
|---|---|
| Size | 31.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3410f5d529ffe0b94d0471ebbabfd4da109cb74dbb36cf54d36efb4aad9ae8b
|
|
BLAKE2b-256 checksum How to use checksums |
3720e575fe721d7664ad39db8db7f21c56c9e1c630a909f6b4b767293823ca5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.3
|
Security for wkt 0.1.4
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.