Utilities¶
Libraries¶
- respysive.download_libraries(names='all')[source]¶
Pre-fill the cache so that offline exports work without network.
- Parameters:
names – Library names or “all” (default).
- Returns:
list – Downloaded or already cached URLs.
- respysive.set_local_js_urls(urls)[source]¶
Override default CDN JavaScript URLs with local paths.
- Parameters:
urls – Dictionary mapping library keys to local file paths. Valid keys: ‘plotly’, ‘d3’, ‘mathjax’, ‘vega’, ‘vega-lite’, ‘vega-embed’, ‘maplibre’.
Example:
set_local_js_urls({'plotly': '/static/plotly.min.js'})
- respysive.set_local_css_urls(urls)[source]¶
Override default CDN CSS URLs with local paths.
- Parameters:
urls – Dictionary mapping library keys to local file paths. Valid keys: ‘theme’, ‘bootstrap’, ‘fontawesome’, ‘maplibre’.
Example:
set_local_css_urls({'fontawesome': '/static/fontawesome.min.css'})
GeoJSON¶
- respysive.filter_geojson(geojson, filter_func=None, properties=None)[source]¶
Filter GeoJSON features based on properties.
This function creates a subset of GeoJSON data by filtering features. Useful for creating regional views or thematic subsets that can be stored in separate hidden divs for optimized HTML size.
- Parameters:
geojson (dict) – GeoJSON FeatureCollection to filter
filter_func (callable, optional) – Function that takes a feature dict and returns True to include it. Example: lambda f: f[‘properties’][‘pop’] > 1000000
properties (dict, optional) – Dictionary of property key-value pairs to match. Features with ALL matching properties will be included. Example: {‘continent’: ‘Europe’} or {‘NAMEen’: ‘France’}
- Returns:
dict – Filtered GeoJSON FeatureCollection with subset of features
Examples
Filter by function:
# Countries with population > 10M populous = filter_geojson(world_data, lambda f: f['properties'].get('pop', 0) > 10000000) # European countries europe = filter_geojson(world_data, lambda f: f['properties'].get('continent') == 'Europe')
Filter by properties:
# France only france = filter_geojson(world_data, properties={'NAMEen': 'France'}) # France and Italy france_italy = filter_geojson(world_data, lambda f: f['properties'].get('NAMEen') in ['France', 'Italy'])
Multiple filters:
# European countries with high GDP rich_europe = filter_geojson(world_data, lambda f: (f['properties'].get('continent') == 'Europe' and f['properties'].get('gdppc', 0) > 30000))
Note
Returns a new FeatureCollection with the same structure
Original data is not modified
If both filter_func and properties are provided, filter_func takes precedence
- respysive.filter_geojson_bbox(geojson, bbox)[source]¶
Filter features by bounding box.
A feature is kept when the extent of its geometry meets the box, whatever the geometry type. Features without geometry are dropped.
- Parameters:
geojson (dict) – GeoJSON FeatureCollection
bbox (list) – Bounding box as [minx, miny, maxx, maxy]
- Returns:
dict – Filtered GeoJSON FeatureCollection
Example
# Europe bounding box (approximate) europe = filter_geojson_bbox(world_data, [-10, 35, 40, 70])
- respysive.get_feature_property_values(geojson, property_name)[source]¶
Get all unique values for a property across all features.
Useful for discovering available values before filtering.
- Parameters:
geojson (dict) – GeoJSON FeatureCollection
property_name (str) – Name of the property to extract
- Returns:
list – Sorted list of unique values for the property
Examples
Find all country names:
countries = get_feature_property_values(world_data, 'NAMEen') # ['Afghanistan', 'Albania', 'Algeria', ...]
Find all continents:
continents = get_feature_property_values(world_data, 'continent') # ['Africa', 'Asia', 'Europe', 'North America', ...]