Geomaster

Geomaster automation and integration for advanced geospatial data management

Geomaster is a community skill for geospatial data analysis and visualization, covering coordinate operations, distance calculations, geocoding, spatial queries, and map generation for location-based application development.

What Is This?

Overview

Geomaster provides patterns for working with geographic data in Python applications. It covers coordinate system conversions between latitude/longitude and projected systems, distance and area calculations using geodesic and Haversine formulas, geocoding that converts addresses to coordinates and reverse lookups, spatial queries including point in polygon testing and nearest neighbor search, and map visualization with markers, polygons, and heatmaps. The skill enables developers to build location-aware applications that process and display geographic information accurately.

Who Should Use This

This skill serves developers building location-based services that require spatial calculations, data analysts working with geographic datasets for regional analysis, and GIS professionals automating spatial workflows in Python.

Why Use It?

Problems It Solves

Calculating distances on the curved Earth surface requires geodesic formulas rather than simple Euclidean math. Coordinate system conversions between geographic and projected systems involve complex datum transformations. Spatial queries like point in polygon need efficient algorithms to handle large datasets. Generating map visualizations from geographic data requires integrating with mapping libraries.

Core Highlights

Distance calculator implements Haversine and Vincenty formulas for accurate geographic distance. Coordinate converter transforms between common spatial reference systems. Spatial query engine performs point in polygon, bounding box, and nearest neighbor searches. Map generator creates interactive visualizations with folium integration.

How to Use It?

Basic Usage

import math
from dataclasses import dataclass

@dataclass
class GeoPoint:
    lat: float
    lon: float
    name: str = ""

def haversine_distance(a: GeoPoint,
                       b: GeoPoint) -> float:
    R = 6371.0
    lat1, lat2 = math.radians(a.lat), math.radians(b.lat)
    dlat = math.radians(b.lat - a.lat)
    dlon = math.radians(b.lon - a.lon)
    h = (math.sin(dlat / 2) ** 2
         + math.cos(lat1) * math.cos(lat2)
         * math.sin(dlon / 2) ** 2)
    return 2 * R * math.asin(math.sqrt(h))

def bounding_box(center: GeoPoint,
                 radius_km: float) -> dict:
    delta_lat = radius_km / 111.32
    delta_lon = radius_km / (
        111.32 * math.cos(
            math.radians(center.lat)))
    return {"min_lat": center.lat - delta_lat,
            "max_lat": center.lat + delta_lat,
            "min_lon": center.lon - delta_lon,
            "max_lon": center.lon + delta_lon}

nyc = GeoPoint(40.7128, -74.0060, "NYC")
la = GeoPoint(33.9425, -118.4081, "LA")
print(f"Distance: {haversine_distance(nyc, la):.0f} km")
print(f"BBox: {bounding_box(nyc, 10)}")

Real-World Examples

from dataclasses import dataclass
import math

class SpatialIndex:
    def __init__(self, points: list[GeoPoint]):
        self.points = points

    def nearest(self, query: GeoPoint,
                k: int = 5) -> list[dict]:
        dists = []
        for p in self.points:
            d = haversine_distance(query, p)
            dists.append({"point": p,
                          "distance_km": round(d, 2)})
        dists.sort(key=lambda x: x["distance_km"])
        return dists[:k]

    def within_radius(self, center: GeoPoint,
                       radius_km: float
                       ) -> list[GeoPoint]:
        return [p for p in self.points
                if haversine_distance(center, p)
                <= radius_km]

    def point_in_polygon(
            self, point: GeoPoint,
            polygon: list[tuple]) -> bool:
        n = len(polygon)
        inside = False
        j = n - 1
        for i in range(n):
            yi, xi = polygon[i]
            yj, xj = polygon[j]
            if ((yi > point.lat) != (yj > point.lat)
                    and point.lon < (xj - xi)
                    * (point.lat - yi)
                    / (yj - yi) + xi):
                inside = not inside
            j = i
        return inside

stores = [GeoPoint(40.71, -74.01, "Store A"),
          GeoPoint(40.75, -73.99, "Store B")]
idx = SpatialIndex(stores)
near = idx.nearest(GeoPoint(40.73, -74.00), k=2)
print(f"Nearest: {near[0]}")

Advanced Tips

Use bounding box pre-filtering before distance calculations to reduce the search space for nearest neighbor queries. Apply projected coordinate systems for area calculations where metric accuracy matters. Index geographic points with spatial data structures like R-trees for efficient queries on large datasets.

When to Use It?

Use Cases

Build a store locator service that finds the nearest locations to a customer address. Create a delivery zone validator that checks whether addresses fall within service areas. Implement a distance matrix calculator for logistics route optimization.

Related Topics

Geospatial computing, coordinate reference systems, spatial indexing, location-based services, and geographic information systems.

Important Notes

Requirements

Python with math library for geodesic calculations. Optional folium or geopandas for visualization and advanced spatial operations. Geographic data in standard formats like GeoJSON or WKT.

Usage Recommendations

Do: use geodesic distance formulas for accuracy over large distances on the Earth surface. Validate coordinate ranges to catch data entry errors. Apply spatial indexing for queries on datasets with thousands of points.

Don't: use Euclidean distance for geographic coordinates, which produces incorrect results especially near poles. Assume flat-Earth approximations for distances exceeding a few kilometers. Mix coordinate reference systems without explicit conversion.

Limitations

Haversine formula assumes a spherical Earth and has slight inaccuracy compared to ellipsoidal methods. Point in polygon tests for very complex polygons may need specialized libraries for performance. Geocoding accuracy depends on the address database quality.