GeoPandas AI is an extension of GeoPandas allowing you to interact with your spatial data in natural language.
Project description
GeoPandas AI
GeoPandas AI is a powerful Python library that brings natural language processing capabilities to your geospatial data analysis workflow. It allows you to interact with GeoDataFrames using natural language queries, making geospatial analysis more accessible and intuitive.
Features
- Natural language interaction with GeoDataFrames
- Support for multiple LLM providers through LiteLLM
- Various output types including:
- GeoDataFrames
- DataFrames
- Text responses
- Plots
- Interactive maps
- Lists
- Dictionaries
- Numeric values (integers, floats)
- Boolean values
Installation
pip install geopandas-ai
Quick Start
import geopandasai as gpdai
# Configure your LLM provider (example using Google's Vertex AI)
gpdai.set_active_lite_llm_config({
"model": "vertex_ai/gemini-2.0-flash",
"vertex_credentials": json.dumps(json.load(open("google-credentials.json", "r")))
})
# Load your geospatial data
gdfai = gpdai.read_file("your_data.geojson")
# Ask questions about your data
result = gdfai.chat("how many points are in this dataset?")
print(result)
# Get specific types of results
count = gdfai.chat("how many points?", result_type=gpdai.ResultType.INTEGER)
points_only = gdfai.chat("Keep only geometry of type point", result_type=gpdai.ResultType.GEODATAFRAME)
map_view = gdfai.chat("Plot the points", result_type=gpdai.ResultType.MAP)
Configuration
GeoPandas AI uses LiteLLM to support multiple LLM providers. You can configure your preferred provider in two ways:
- Using the
set_active_lite_llm_configfunction:
from geopandasai.config import set_active_lite_llm_config
set_active_lite_llm_config({
"model": "your_model_name",
# Add provider-specific configuration
})
- Using environment variables:
export LITELLM_CONFIG='{"model": "your_model_name", ...}'
Please refer to https://docs.litellm.ai/docs/providers for more details on configuring LiteLLM.
Adding Custom Libraries
GeoPandas AI allows you to extend its capabilities by adding custom libraries that can be used in the generated code. There are two ways to add libraries:
- Globally using
set_libraries:
from geopandasai.config import set_libraries
# Add libraries that will be available for all chat queries
set_libraries(['numpy', 'scipy', 'shapely'])
- Per-query using the
user_provided_librariesparameter:
# Add libraries for a specific query
result = gdfai.chat(
"calculate the convex hull using scipy",
result_type=ResultType.GEODATAFRAME,
user_provided_libraries=['scipy', 'numpy']
)
By default, the following libraries are always available:
- pandas
- matplotlib.pyplot
- folium
- geopandas
Note: Make sure any additional libraries you specify are installed in your environment.
Available Result Types
The library supports various result types through the ResultType enum:
DATAFRAME: Returns a pandas DataFrameGEODATAFRAME: Returns a GeoDataFrameTEXT: Returns a text responsePLOT: Returns a matplotlib figureMAP: Returns a folium mapLIST: Returns a listDICT: Returns a dictionaryINTEGER: Returns an integerFLOAT: Returns a floatBOOLEAN: Returns a boolean
Examples
Basic Queries
# Count features
count = gdfai.chat("how many features?", result_type=ResultType.INTEGER)
# Filter data
filtered = gdfai.chat("show only points with population > 1000", result_type=ResultType.GEODATAFRAME)
# Get statistics
stats = gdfai.chat("what's the average population?", result_type=ResultType.FLOAT)
Visualization
# Create a plot
plot = gdfai.chat("create a scatter plot of population vs area", result_type=ResultType.PLOT)
# Generate an interactive map
map = gdfai.chat("show all points colored by population", result_type=ResultType.MAP)
Data Transformation
# Convert to list
list_data = gdfai.chat("convert to list", result_type=ResultType.LIST)
# Convert to dictionary
dict_data = gdfai.chat("convert to json", result_type=ResultType.DICT)
Caching
GeoPandas AI includes a caching system to improve performance and reduce API calls. The library provides two types of caches:
InMemoryResultCache: Stores results in memory (default)FileResultCache: Persists results to disk
Using Caching
from geopandasai import set_cache_instance, FileResultCache, InMemoryResultCache
# Use in-memory cache (default)
set_cache_instance(InMemoryResultCache())
# Or use file-based cache
set_cache_instance(FileResultCache(cache_dir="./.geopandasai_cache"))
The cache automatically stores:
- Query results
- Generated code
- Any intermediate results
This helps in:
- Reducing API calls
- Improving response times for repeated queries
- Saving costs when using paid LLM providers
Accessing Generated Code
After each query, you can access the generated Python code that was used to produce the result:
# Make a query
result = gdfai.chat("how many points are in this dataset?")
# Access the generated code
print(gdfai.last_output.source_code)
This is useful for:
- Understanding how the AI interpreted your query
- Learning from the generated code
- Debugging unexpected results
- Reusing the generated code in your own scripts
Requirements
- Python 3.8+
- GeoPandas
- LiteLLM
- Matplotlib
- Folium
License
MIT + Commercial Platform Restriction (see LICENSE.md)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geopandas_ai-0.0.5.tar.gz.
File metadata
- Download URL: geopandas_ai-0.0.5.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49cc3eaa38a0b185ea438ee2195cbd64479dd5c55384ac17ccab2dfbf028695a
|
|
| MD5 |
e1d765221ed8843dad958b687de149fb
|
|
| BLAKE2b-256 |
de1703db5954cfcda060ab445e8e77f6ec9ac2186954ee0dd4e4ada448b1c164
|
Provenance
The following attestation bundles were made for geopandas_ai-0.0.5.tar.gz:
Publisher:
python-publish.yml on GaspardMerten/geopandas-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
geopandas_ai-0.0.5.tar.gz -
Subject digest:
49cc3eaa38a0b185ea438ee2195cbd64479dd5c55384ac17ccab2dfbf028695a - Sigstore transparency entry: 195383832
- Sigstore integration time:
-
Permalink:
GaspardMerten/geopandas-ai@4a0abfa13f1664577cafb340a6ed2dabfd9f157d -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/GaspardMerten
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4a0abfa13f1664577cafb340a6ed2dabfd9f157d -
Trigger Event:
push
-
Statement type:
File details
Details for the file geopandas_ai-0.0.5-py3-none-any.whl.
File metadata
- Download URL: geopandas_ai-0.0.5-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28836c8594b2aefec1821340442084882cdf9692d50c63b270dacd1d4aa975f
|
|
| MD5 |
4979d6f08e837011e36c302a7c1561c4
|
|
| BLAKE2b-256 |
446ad337f98ca1215a5a2c05f9dd92df3d6201477e7a14f4b79d91f07a20e71e
|
Provenance
The following attestation bundles were made for geopandas_ai-0.0.5-py3-none-any.whl:
Publisher:
python-publish.yml on GaspardMerten/geopandas-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
geopandas_ai-0.0.5-py3-none-any.whl -
Subject digest:
a28836c8594b2aefec1821340442084882cdf9692d50c63b270dacd1d4aa975f - Sigstore transparency entry: 195383838
- Sigstore integration time:
-
Permalink:
GaspardMerten/geopandas-ai@4a0abfa13f1664577cafb340a6ed2dabfd9f157d -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/GaspardMerten
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4a0abfa13f1664577cafb340a6ed2dabfd9f157d -
Trigger Event:
push
-
Statement type: