G

Geo Fundamentals Smart

Production-ready skill that handles generative, engine, optimization, search. Includes structured workflows, validation checks, and reusable patterns for utilities.

SkillClipticsutilitiesv1.0.0MIT
0 views0 copies

Geo Fundamentals

A geospatial computing skill for working with geographic data, coordinate systems, spatial analysis, and mapping using Python geospatial libraries and GIS tools.

When to Use

Choose Geo Fundamentals when:

  • Processing geographic data (coordinates, shapefiles, GeoJSON)
  • Performing spatial analysis like distance calculations, geocoding, and area computations
  • Building interactive maps with data visualization layers
  • Working with coordinate reference systems and projections

Consider alternatives when:

  • Building a full GIS application — use QGIS or ArcGIS
  • Simple address lookup — use a geocoding API directly
  • Real-time GPS tracking — use specialized IoT platforms

Quick Start

# Install core geospatial packages pip install geopandas shapely folium geopy pyproj
import geopandas as gpd from shapely.geometry import Point, Polygon, LineString from geopy.distance import geodesic from geopy.geocoders import Nominatim import folium # Basic coordinate operations class GeoTools: def __init__(self): self.geolocator = Nominatim(user_agent="geo-fundamentals") def distance_between(self, coord1, coord2): """Calculate distance between two lat/lng points""" return geodesic(coord1, coord2).kilometers def geocode(self, address): """Convert address to coordinates""" location = self.geolocator.geocode(address) if location: return { 'lat': location.latitude, 'lng': location.longitude, 'address': location.address } return None def reverse_geocode(self, lat, lng): """Convert coordinates to address""" location = self.geolocator.reverse(f"{lat}, {lng}") return location.address if location else None def create_buffer(self, lat, lng, radius_km): """Create a circular buffer around a point""" from pyproj import Transformer point = Point(lng, lat) # Project to meters for accurate buffer transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True) projected = transformer.transform(lng, lat) buffer = Point(projected).buffer(radius_km * 1000) # Project back to WGS84 inv_transformer = Transformer.from_crs("EPSG:3857", "EPSG:4326", always_xy=True) return buffer # Simplified def points_in_polygon(self, points, polygon_coords): """Find which points fall within a polygon""" polygon = Polygon(polygon_coords) results = [] for p in points: point = Point(p['lng'], p['lat']) if polygon.contains(point): results.append(p) return results # Create an interactive map def create_map(center_lat, center_lng, markers=None): m = folium.Map(location=[center_lat, center_lng], zoom_start=12) if markers: for marker in markers: folium.Marker( location=[marker['lat'], marker['lng']], popup=marker.get('label', ''), icon=folium.Icon(color=marker.get('color', 'blue')) ).add_to(m) return m

Core Concepts

Coordinate Reference Systems

CRSEPSG CodeUnitUse Case
WGS844326DegreesGPS coordinates, web maps
Web Mercator3857MetersGoogle Maps, Mapbox
UTM Zones326xxMetersAccurate local measurements
NAD834269DegreesNorth American mapping
OSGB3627700MetersBritish national grid

GeoDataFrame Operations

import geopandas as gpd import pandas as pd # Load geographic data cities = gpd.read_file('cities.geojson') boundaries = gpd.read_file('boundaries.shp') # Spatial join — find which boundary each city belongs to cities_with_region = gpd.sjoin(cities, boundaries, how='left', predicate='within') # Calculate areas (convert to projected CRS first) boundaries_proj = boundaries.to_crs(epsg=3857) boundaries_proj['area_km2'] = boundaries_proj.geometry.area / 1e6 # Nearest neighbor analysis from shapely.ops import nearest_points def find_nearest(gdf, point): """Find nearest feature to a point""" distances = gdf.geometry.distance(point) nearest_idx = distances.idxmin() return gdf.loc[nearest_idx], distances[nearest_idx]

Configuration

OptionDescriptionDefault
default_crsDefault coordinate reference system"EPSG:4326"
distance_unitDefault distance unit: km, miles, meters"km"
geocoderGeocoding service: nominatim, google, mapbox"nominatim"
map_tile_providerMap tile source for visualizations"OpenStreetMap"
precisionDecimal places for coordinate output6
cache_geocodingCache geocoding resultstrue
max_geocode_rateRequests per second for geocoding1
default_buffer_crsCRS for buffer operations"EPSG:3857"

Best Practices

  1. Always specify and verify your CRS before performing spatial operations — mixing coordinates in different reference systems produces silently wrong results; use gdf.crs to check and gdf.to_crs() to convert
  2. Project to a local CRS for distance and area calculations because WGS84 degree-based coordinates produce inaccurate measurements; use UTM zones for the region you are working in to get meter-based accuracy
  3. Use spatial indexes with GeoPandas (sindex) for large datasets to avoid O(n²) comparisons; spatial joins on datasets with thousands of features can drop from minutes to seconds with proper indexing
  4. Rate limit geocoding requests to respect service terms — Nominatim allows 1 request per second; batch your geocoding operations and cache results to avoid redundant lookups
  5. Validate geometry before operations using geometry.is_valid and fix invalid geometries with geometry.buffer(0) because invalid polygons (self-intersecting, zero-area) cause spatial operations to fail silently or throw errors

Common Issues

Longitude/latitude order confusion: Some libraries and formats use (longitude, latitude) order while others use (latitude, longitude). GeoJSON and Shapely use (lng, lat), while Folium and Google Maps use (lat, lng). Always check the documentation for each tool and convert consistently at your data boundaries.

Inaccurate distance calculations with WGS84: Computing distances directly from WGS84 degree coordinates treats longitude and latitude as equal units, which they are not. Use the geopy.distance.geodesic function for accurate great-circle distances, or project to a local meter-based CRS before using Euclidean distance formulas.

Large GeoJSON files causing memory issues: Detailed shapefiles with high-resolution boundaries can be hundreds of megabytes. Simplify geometries with geometry.simplify(tolerance) to reduce point count while preserving shape, use spatial filters to load only the area you need, and consider tile-based formats like MBTiles for very large datasets.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!