The Felt SDK provides powerful methods to analyze your geospatial data and transform it into informative visualizations. You can calculate statistics on entire datasets or focus on specific areas using boundaries and filters, allowing you to create custom charts that reveal insights about your spatial data.
Data analysis methods
The SDK offers three complementary approaches to analyze your map data:
1. Aggregates: single statistics
Calculate individual values (count, sum, average, etc.) across your dataset or a filtered subset. If no aggregation method is provided, the count is returned.
// Count all residential buildings
const residentialCount = await felt.getAggregates({
layerId: "buildings",
filters: ["type", "eq", "residential"]
});
// returns { count: 427 }
// Calculate average home value in a specific neighborhood
const avgHomeValue = await felt.getAggregates({
layerId: "buildings",
boundary: [-122.43, 47.60, -122.33, 47.62], // neighborhood boundary
aggregation: {
method: "avg",
attribute: "assessed_value"
}
});
// returns { avg: 652850.32 }
2. Categories: group by values
Group features by unique attribute values and calculate statistics for each group.
Here's how you might integrate these analysis methods with an interactive chart:
// Create a pie chart showing building type distribution
async function createBuildingTypePieChart() {
// Get data for the chart
const data = await felt.getCategoryData({
layerId: "buildings",
attribute: "type"
});
// Render pie chart (using a hypothetical chart library)
const chart = renderPieChart(data, {
valuePath: "count",
labelPath: "value",
onSliceClick: handleSliceClick
});
return chart;
}
// Handle user interaction with the chart
async function handleSliceClick(slice) {
const buildingType = slice.label;
// Apply filter to highlight this building type on the map
await felt.setLayerFilters({
layerId: "buildings",
filters: ["type", "eq", buildingType],
note: `Showing ${buildingType} buildings only`
});
// Get additional statistics for this building type
const stats = await felt.getAggregates({
layerId: "buildings",
filters: ["type", "eq", buildingType],
aggregation: {
method: "avg",
attribute: "year_built"
}
});
// Update the UI with these statistics
updateStatsPanel(`Average ${buildingType} building age: ${2025 - stats.avg}`);
}
// Initialize the chart when the page loads
createBuildingTypePieChart();
This example demonstrates how a user clicking on a pie chart slice could apply a filter to the map, highlighting only the buildings of that type. It also shows how you could fetch additional statistics based on the user's selection to enrich the visualization experience.