KatInterview

Code Review: Geospatial Data Processing Pipeline

SQL & DataModel answer
MediumModel answerSQL & Datacode-reviewgeospatialpython

Last updated

Evaluate a Python module that computes distances and clusters geographic points from CSV/GeoJSON sources, identifying bugs, performance issues, and production risks.

You are given a Python module that ingests geospatial datasets (CSV and GeoJSON), calculates pairwise distances between points, groups nearby points into clusters, and writes summary outputs. Your task is to conduct a thorough code review covering the following dimensions:

  • Correctness bugs and numerical stability problems specific to geospatial computation
  • Edge-case handling: missing or malformed coordinates, CRS mismatches, empty inputs
  • Performance bottlenecks and concrete optimization strategies
  • Code quality: modularity, type annotations, documentation
  • Security and operational concerns: input validation, dependency management, file handling
  • A testing strategy with specific fixture scenarios

For each issue you identify, explain why it matters and propose a concrete fix. Where relevant, estimate time and space complexity of the current approach and your proposed alternative. Discuss library choices (pandas, shapely, pyproj, scikit-learn, geopandas) and their trade-offs.

Hints

Hint 1

GeoJSON uses [lon, lat] ordering while most CSVs use lat, lon — check for coordinate swaps

Hint 2

DBSCAN with haversine metric expects radians, not degrees, and eps must be scaled by Earth's radius

Hint 3

A full n×n distance matrix for 100k points consumes roughly 80 GB of memory — think about spatial indexing

Hint 4

Haversine can produce domain errors for near-antipodal points when the arc-sin argument exceeds 1 due to floating-point drift