Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Artsy Engineering 8 min read Case study mediumAdept

Are you using the right Mongo geospatial query?

MongoDB's `$geoWithin` with `$center` computes radius queries in planar longitude/latitude space, so at Los Angeles's latitude a nominal 25km circle becomes an egg that drops points to the east and west. A Santa Monica gallery missing from Artsy's LA show listings was traced to this, and switching to `$centerSphere` with the radius in radians (km / 6378.1) fixed it. The investigation used Placemark to plot query results against a grid of test points and compare them with a geodesic circle. A postscript covers why the distortion happens, using the equirectangular and Mercator projections and Tissot's indicatrix.

Assumes: MongoDB querieslatitude/longitude coordinates

Related posts

  • Geo Queries with PostGIS in Ionic Angular

    Supabase mediumAdept

    PostGIS on Supabase handles geo data for an Ionic Angular app with a Capacitor Google Map. A stores table holds geography(POINT) locations behind a GIST spatial index. Two SQL functions do the geo queries: nearby_stores orders stores by the <-> distance operator and returns st_distance in meters, and stores_in_view filters with && against an ST_MakeBox2D bounding box. The app calls them via Supabase RPC, inserts locations as WKT POINT(long lat) strings, uploads store images to Supabase Storage, and covers the native location permissions and API keys needed for iOS and Android.

  • Visualizing Foursquare places with ClickHouse

    ClickHouse mediumAdept

    The Foursquare open places dataset (about 100 million records) loads straight from S3 Parquet into ClickHouse in 42 seconds and 11 GB. The table stores Web Mercator coordinates as materialized UInt32 columns, is ordered by a Morton (Z-order) space-filling curve, and has minmax indices so map tiles can be queried fast. The existing adsb.exposed air-traffic visualizer was reused with a 48-line change to render pixel-level tiles in the browser. Compared with Foursquare Studio's H3 hexagons, Kepler.gl and DuckDB-based maps, it gives higher resolution and smoother interactivity, but does not correct point density for latitude.

  • Frontend Engineering at Palantir: Polar Scaled Tiles in Zodiac

    Palantir mediumAdept

    Equal-angle lat/long map tiles collapse into tiny slivers near the poles on a 3D globe, so Zodiac, Palantir's Three.js globe library, was generating far too much geometry in polar regions. Polar scaled tiles fix this by using the spherical surface-area formula to merge adjacent tiles in power-of-2 spans until each is roughly as large as an equatorial tile. That breaks the 4-child quadtree assumption and forces client-side texture stitching from standard geodetic and Mercator tiles (Mercator is mapped in strips), heightmap resampling via bilinear interpolation, and blending toward fixed pole elevations. The result is over 90% fewer triangles, draw calls and textures at the poles and more consistent frame times, though texture fetching, up to 16 source tiles per polar tile, is now the bottleneck.

  • Maps with PostgreSQL and PostGIS

    Zalando Engineering mediumAdept

    PostGIS can generate Mapbox vector tiles directly, so a browser map needs only PostgreSQL/PostGIS, a thin tile server (pg_tileserv) and a Leaflet frontend, with no heavy tiling middleware. The stack runs on Kubernetes: Zalando's Postgres Operator provisions an HA cluster with the PostGIS extension, roles and schemas from a short manifest, and pg_tileserv is deployed with a ConfigMap-mounted TOML config behind an OAuth proxy. Beyond serving tables, SQL function layers built on ST_TileEnvelope, ST_HexagonGrid and ST_AsMVT can produce dynamic hexagon heatmaps (here joined against Geostat population data) whose resolution adapts to the zoom level.

  • State of Geospatial in ClickHouse in March 2026

    ClickHouse mediumAdept

    ClickHouse's geospatial support has grown from early distance functions to over 90 functions, grid indexes (geohash, H3, S2), and geometry types (Point, Ring, LineString, MultiLineString, Polygon, MultiPolygon) implemented as aliases over Tuple and Array. The new Geometry type (v25.11) is a Variant that holds mixed geometries in one column, and WKT/WKB import and export enable interchange with PostGIS and GeoParquet. Direct parsing of mixed-geometry GeoParquet arrives in 26.3, and a readWKB workaround covers earlier versions. A recurring pitfall is coordinate order: functions expect (longitude, latitude), and flipCoordinates fixes data supplied as lat/lon.

The quest for software engineering knowledge.

Look:
Layout: