LogoLogo
Sign upDeveloper DocsContactSocial
  • Getting Started
    • Welcome
    • What is Felt?
    • Create your first map
    • Tour the interface
    • Your workspace
    • Keyboard shortcuts
  • upload anything
    • Files
    • URLs
    • Spreadsheets
    • Raster and imagery
    • Cloud sources
      • BigQuery
      • Databricks
      • Esri Feature Service
      • Microsoft SQL Server
      • PostGIS
      • Redshift
      • Snowflake
      • Web Feature Service (WFS)
      • WMS/WMTS
    • Raster infrastructure
      • Organizing your raster data
      • Cloud Optimized GeoTiffs
      • Cloud storage
        • Amazon S3
        • Google Cloud Storage
        • Azure Blob Storage
      • STAC
    • SQL queries
    • Refreshing data
    • QGIS plugin
    • Troubleshooting
  • Layers
    • Viewing data
    • Filters
    • Styling
      • Vector layers
      • Raster layers
      • Backgrounds
    • Formatting
    • Interactions
    • List
    • Group
    • Spatial analysis
  • Elements
    • Creating data
    • Annotations
    • Styling & grouping
    • Extract
    • Converting Elements ↔ Layers
  • Dashboards & Apps
    • Components
    • Layer slider
    • Map settings
    • For developers
  • Sharing & Collaboration
    • Sharing a map
    • Commenting
    • Embedding
    • Integrations
    • Duplicating a map
    • Exporting
      • Exporting Data
      • PDF & images
  • Administration
    • Workspaces and projects
    • Managing members
    • Layer library
    • For classrooms
    • Single sign-on (SSO)
    • Regional hosting
    • Billing
    • Security and privacy
  • Terms & policy
    • Privacy policy
    • Terms of service
    • Attribution policy
Powered by GitBook
On this page
  • Set up
  • Writing SQL Queries
  • Debugging SQL Queries
  • Other Key Features
  • Supported Spatial Operations
  • Example Operations

Was this helpful?

Export as PDF
  1. upload anything

SQL queries

Create dynamic map layers in Felt using SQL queries.

PreviousSTACNextRefreshing data

Last updated 3 months ago

Was this helpful?

Felt’s custom SQL query feature lets you write and execute SQL queries directly against your database, enabling you to filter and manipulate your spatial data before visualizing it on your map. It gives you full control over how your data is displayed, ensuring your maps are tailored to meet your specific analysis needs. Whether you're refining data or creating complex visualizations, Felt makes it easy to seamlessly integrate your custom queries with your mapping workflow.

This feature is only available to customers on the . To upgrade, .

Set up

Writing SQL Queries

  1. Go to your Library and find your data source in the left column under the Sources heading.

  2. Select the source you want to use for your SQL query.

  3. After selecting the source, click the SQL icon in the top-right corner of the Library window to open the query editor.

  4. The SQL query window will open, allowing you to write SQL statements in the code editor. The editor also provides suggestions for table and column names based on your database schema.

  5. Click Run Preview to execute your query. Felt will display a preview of the resulting data in the Preview window.

  6. Click Create Layer in the bottom-right corner of the Preview window to add your data to the map.

  7. A new layer will be added to your map and you can start browsing your data and styling your map.

Debugging SQL Queries

  1. If your query isn’t valid, the Run Preview button will display a ! to indicate an error.

  2. Hover over the Run Preview button to see a popup with helpful hints about potential issues in your query.

  3. Fixing the syntax error in your query will remove the !.

  4. If your query doesn’t generate a preview, an error message will appear in the Preview window with details to help you debug the issue. Adjust your query and try again.

Other Key Features

See a layer’s query

To view the query used to generate a layer, click the Data heading in the layer window. Then, click the Source name to open a SQL query window showing the query.

Build off of an existing query

To create another layer using a similar query, click the Source name to open a SQL query window, then select Copy to new query.

Skip layer preview

If you want to create a layer without generating a preview, click the ˅ beside the Run Preview button and select Create layer without previewing.

Supported Spatial Operations

Different SQL platforms offer varying levels of support for spatial operations, with some providing extensive libraries of geospatial functions and others offering more basic capabilities. While some focus on advanced geographic and geometric queries, others prioritize scalability and integration with broader data processing workflows. The specific capabilities and limitations depend on the platform, so refer to the relevant documentation linked below for more details.

The SQL query feature supports only SELECT statements, ensuring read-only access to your database.

Example Operations

Spatial Operation
Definition
Code Example

ST_Intersects

Tests whether two geometries share any space in common. Returns true if geometries intersect, false otherwise. Used for identifying overlapping areas.

SELECT a.*, b.* FROM service_areas a JOIN market_zones b ON ST_Intersects(a.geometry, b.geometry);

ST_Within

Tests whether one geometry is completely inside another. Returns true if the first geometry is completely within the second geometry.

SELECT a.name, b.name FROM points a JOIN polygons b ON ST_Within(a.geometry, b.geometry);

ST_Buffer

Creates a new geometry that represents all points within a given distance from the input geometry. Useful for creating service areas or zones of influence.

SELECT location_id, ST_Buffer(geometry, 5000) as service_area FROM distribution_centers;

ST_Centroid

Computes the geometric center (centroid) of a geometry. Returns a point that represents the average position of all points in the geometry.

SELECT region_name, ST_Centroid(geometry) as center_point FROM service_regions;

ST_Distance

Calculates the shortest distance between two geometries. Returns the minimum distance between any two points in the two geometries.

SELECT a.id, b.id, ST_Distance(a.geometry, b.geometry) as distance FROM points a CROSS JOIN points b WHERE a.id != b.id;

ST_Area

Calculates the area of a polygon geometry. Returns the area in the units of the spatial reference system.

SELECT territory_id, ST_Area(geometry::geography) as area_sqm FROM market_territories;

ST_Length

Calculates the length of a linear geometry (linestring). Returns the length in the units of the spatial reference system.

SELECT route_id, ST_Length(geometry::geography) as length_meters FROM delivery_routes;

ST_Union

Combines multiple geometries into a single geometry. Dissolves overlapping boundaries and creates a single continuous geometry.

SELECT region_id, ST_Union(geometry) as combined_geometry FROM parcels GROUP BY region_id;

ST_Intersection

Returns the geometry representing the shared portions of two geometries. Creates a new geometry containing only the overlapping areas.

SELECT ST_Intersection(a.geometry, b.geometry) as overlap FROM zone_a a CROSS JOIN zone_b b;

ST_Transform

Transforms a geometry from one coordinate system to another. Used to convert between different spatial reference systems (SRS).

SELECT id, ST_Transform(geometry, 4326) as wgs84_geom FROM locations;

ST_Envelope

Computes the minimum bounding rectangle that contains a geometry. Returns a rectangular polygon that completely encloses the input geometry.

SELECT region_id, ST_Envelope(ST_Collect(geometry)) as bbox FROM market_regions GROUP BY region_id;

ST_ConvexHull

Computes the smallest convex polygon that contains all points in a geometry. Creates a shape that represents the outer boundary of a set of points.

SELECT cluster_id, ST_ConvexHull(ST_Collect(geometry)) as boundary FROM points GROUP BY cluster_id;

ST_Contains

Tests whether one geometry completely contains another. Returns true if the second geometry is completely contained within the first geometry.

SELECT points.* FROM customer_points points JOIN service_areas areas ON ST_Contains(areas.geometry, points.geometry);

First, connect the data source of your choice. Not sure how? No worries—. Once you're connected, you’re good to go and can start writing your custom SQL queries.

Postgres ()

check out the detailed instructions here
Databricks
BigQuery
MS SQL Server
Redshift
Snowflake
PostGIS
Enterprise plan
contact sales