GeoMaster
Comprehensive geospatial science skill covering GIS, remote sensing, spatial analysis, and ML for Earth observation across 70+ topics with 500+ code examples in 8 programming languages.
Installation
# Core Python stack (conda recommended)
conda install -c conda-forge gdal rasterio fiona shapely pyproj geopandas
# Remote sensing & ML
uv pip install rsgislib torchgeo earthengine-api
uv pip install scikit-learn xgboost torch-geometric
# Network & visualization
uv pip install osmnx networkx folium keplergl
uv pip install cartopy contextily mapclassify
# Big data & cloud
uv pip install xarray rioxarray dask-geopandas
uv pip install pystac-client planetary-computer
# Point clouds
uv pip install laspy pylas open3d pdal
# Databases
conda install -c conda-forge postgis spatialite
Quick Start
NDVI from Sentinel-2
import rasterio
import numpy as np
with rasterio.open('sentinel2.tif') as src:
red = src.read(4).astype(float) # B04
nir = src.read(8).astype(float) # B08
ndvi = (nir - red) / (nir + red + 1e-8)
ndvi = np.nan_to_num(ndvi, nan=0)
profile = src.profile
profile.update(count=1, dtype=rasterio.float32)
with rasterio.open('ndvi.tif', 'w', **profile) as dst:
dst.write(ndvi.astype(rasterio.float32), 1)
Spatial Analysis with GeoPandas
import geopandas as gpd
# Load and ensure same CRS
zones = gpd.read_file('zones.geojson')
points = gpd.read_file('points.geojson')
if zones.crs != points.crs:
points = points.to_crs(zones.crs)
# Spatial join and statistics
joined = gpd.sjoin(points, zones, how='inner', predicate='within')
stats = joined.groupby('zone_id').agg({
'value': ['count', 'mean', 'std', 'min', 'max']
}).round(2)
Google Earth Engine Time Series
import ee
import pandas as pd
ee.Initialize(project='your-project')
roi = ee.Geometry.Point([-122.4, 37.7]).buffer(10000)
s2 = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
.filterBounds(roi)
.filterDate('2020-01-01', '2023-12-31')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)))
def add_ndvi(img):
return img.addBands(img.normalizedDifference(['B8', 'B4']).rename('NDVI'))
s2_ndvi = s2.map(add_ndvi)
def extract_series(image):
stats = image.reduceRegion(ee.Reducer.mean(), roi.centroid(), scale=10, maxPixels=1e9)
return ee.Feature(None, {'date': image.date().format('YYYY-MM-dd'), 'ndvi': stats.get('NDVI')})
series = s2_ndvi.map(extract_series).getInfo()
df = pd.DataFrame([f['properties'] for f in series['features']])
df['date'] = pd.to_datetime(df['date'])
Core Concepts
Data Types
| Type |
Examples |
Libraries |
| Vector |
Shapefile, GeoJSON, GeoPackage |
GeoPandas, Fiona, GDAL |
| Raster |
GeoTIFF, NetCDF, COG |
Rasterio, Xarray, GDAL |
| Point Cloud |
LAS, LAZ |
Laspy, PDAL, Open3D |
Coordinate Systems
- EPSG:4326 (WGS 84) - Geographic, lat/lon, use for storage
- EPSG:3857 (Web Mercator) - Web maps only (don't use for area/distance!)
- EPSG:326xx/327xx (UTM) - Metric calculations, <1% distortion per zone
- Use
gdf.estimate_utm_crs() for automatic UTM detection
# Always check CRS before operations
assert gdf1.crs == gdf2.crs, "CRS mismatch!"
# For area/distance calculations, use projected CRS
gdf_metric = gdf.to_crs(gdf.estimate_utm_crs())
area_sqm = gdf_metric.geometry.area
OGC Standards
- WMS: Web Map Service - raster maps
- WFS: Web Feature Service - vector data
- WCS: Web Coverage Service - raster coverage
- STAC: Spatiotemporal Asset Catalog - modern metadata
Common Operations
Spectral Indices
def calculate_indices(image_path):
"""NDVI, EVI, SAVI, NDWI from Sentinel-2."""
with rasterio.open(image_path) as src:
B02, B03, B04, B08, B11 = [src.read(i).astype(float) for i in [1,2,3,4,5]]
ndvi = (B08 - B04) / (B08 + B04 + 1e-8)
evi = 2.5 * (B08 - B04) / (B08 + 6*B04 - 7.5*B02 + 1)
savi = ((B08 - B04) / (B08 + B04 + 0.5)) * 1.5
ndwi = (B03 - B08) / (B03 + B08 + 1e-8)
return {'NDVI': ndvi, 'EVI': evi, 'SAVI': savi, 'NDWI': ndwi}
Vector Operations
# Buffer (use projected CRS!)
gdf_proj = gdf.to_crs(gdf.estimate_utm_crs())
gdf['buffer_1km'] = gdf_proj.geometry.buffer(1000)
# Spatial relationships
intersects = gdf[gdf.geometry.intersects(other_geometry)]
contains = gdf[gdf.geometry.contains(point_geometry)]
# Geometric operations
gdf['centroid'] = gdf.geometry.centroid
gdf['simplified'] = gdf.geometry.simplify(tolerance=0.001)
# Overlay operations
intersection = gpd.overlay(gdf1, gdf2, how='intersection')
union = gpd.overlay(gdf1, gdf2, how='union')
Terrain Analysis
def terrain_metrics(dem_path):
"""Calculate slope, aspect, hillshade from DEM."""
with rasterio.open(dem_path) as src:
dem = src.read(1)
dy, dx = np.gradient(dem)
slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi
aspect = (90 - np.arctan2(-dy, dx) * 180 / np.pi) % 360
# Hillshade
az_rad, alt_rad = np.radians(315), np.radians(45)
hillshade = (np.sin(alt_rad) * np.sin(np.radians(slope)) +
np.cos(alt_rad) * np.cos(np.radians(slope)) *
np.cos(np.radians(aspect) - az_rad))
return slope, aspect, hillshade
Network Analysis
import osmnx as ox
import networkx as nx
# Download and analyze street network
G = ox.graph_from_place('San Francisco, CA', network_type='drive')
G = ox.add_edge_speeds(G).add_edge_travel_times(G)
# Shortest path
orig = ox.distance.nearest_nodes(G, -122.4, 37.7)
dest = ox.distance.nearest_nodes(G, -122.3, 37.8)
route = nx.shortest_path(G, orig, dest, weight='travel_time')
Image Classification
from sklearn.ensemble import RandomForestClassifier
import rasterio
from rasterio.features import rasterize
def classify_imagery(raster_path, training_gdf, output_path):
"""Train RF and classify imagery."""
with rasterio.open(raster_path) as src:
image = src.read()
profile = src.profile
transform = src.transform
# Extract training data
X_train, y_train = [], []
for _, row in training_gdf.iterrows():
mask = rasterize([(row.geometry, 1)],
out_shape=(profile['height'], profile['width']),
transform=transform, fill=0, dtype=np.uint8)
pixels = image[:, mask > 0].T
X_train.extend(pixels)
y_train.extend([row['class_id']] * len(pixels))
# Train and predict
rf = RandomForestClassifier(n_estimators=100, max_depth=20, n_jobs=-1)
rf.fit(X_train, y_train)
prediction = rf.predict(image.reshape(image.shape[0], -1).T)
prediction = prediction.reshape(profile['height'], profile['width'])
profile.update(dtype=rasterio.uint8, count=1)
with rasterio.open(output_path, 'w', **profile) as dst:
dst.write(prediction.astype(rasterio.uint8), 1)
return rf
Modern Cloud-Native Workflows
STAC + Planetary Computer
import pystac_client
import planetary_computer
import odc.stac
# Search Sentinel-2 via STAC
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1",
modifier=planetary_computer.sign_inplace,
)
search = catalog.search(
collections=["sentinel-2-l2a"],
bbox=[-122.5, 37.7, -122.3, 37.9],
datetime="2023-01-01/2023-12-31",
query={"eo:cloud_cover": {"lt": 20}},
)
# Load as xarray (cloud-native!)
data = odc.stac.load(
list(search.get_items())[:5],
bands=["B02", "B03", "B04", "B08"],
crs="EPSG:32610",
resolution=10,
)
# Calculate NDVI on xarray
ndvi = (data.B08 - data.B04) / (data.B08 + data.B04)
Cloud-Optimized GeoTIFF (COG)
import rasterio
from rasterio.session import AWSSession
# Read COG directly from cloud (partial reads)
session = AWSSession(aws_access_key_id=..., aws_secret_access_key=...)
with rasterio.open('s3://bucket/path.tif', session=session) as src:
# Read only window of interest
window = ((1000, 2000), (1000, 2000))
subset = src.read(1, window=window)
# Write COG
with rasterio.open('output.tif', 'w', **profile,
tiled=True, blockxsize=256, blockysize=256,
compress='DEFLATE', predictor=2) as dst:
dst.write(data)
# Validate COG
from rio_cogeo.cogeo import cog_validate
cog_validate('output.tif')
Performance Tips
# 1. Spatial indexing (10-100x faster queries)
gdf.sindex # Auto-created by GeoPandas
# 2. Chunk large rasters
with rasterio.open('large.tif') as src:
for i, window in src.block_windows(1):
block = src.read(1, window=window)
# 3. Dask for big data
import dask.array as da
dask_array = da.from_rasterio('large.tif', chunks=(1, 1024, 1024))
# 4. Use Arrow for I/O
gdf.to_file('output.gpkg', use_arrow=True)
# 5. GDAL caching
from osgeo import gdal
gdal.SetCacheMax(2**30) # 1GB cache
# 6. Parallel processing
rf = RandomForestClassifier(n_jobs=-1) # All cores
Best Practices
- Always check CRS before spatial operations
- Use projected CRS for area/distance calculations
- Validate geometries:
gdf = gdf[gdf.is_valid]
- Handle missing data:
gdf['geometry'] = gdf['geometry'].fillna(None)
- Use efficient formats: GeoPackage > Shapefile, Parquet for large data
- Apply cloud masking to optical imagery
- Preserve lineage for reproducible research
- Use appropriate resolution for your analysis scale
Detailed Documentation
- Coordinate Systems - CRS fundamentals, UTM, transformations
- Core Libraries - GDAL, Rasterio, GeoPandas, Shapely
- Remote Sensing - Satellite missions, spectral indices, SAR
- Machine Learning - Deep learning, CNNs, GNNs for RS
- GIS Software - QGIS, ArcGIS, GRASS integration
- Scientific Domains - Marine, hydrology, agriculture, forestry
- Advanced GIS - 3D GIS, spatiotemporal, topology
- Big Data - Distributed processing, GPU acceleration
- Industry Applications - Urban planning, disaster management
- Programming Languages - Python, R, Julia, JS, C++, Java, Go, Rust
- Data Sources - Satellite catalogs, APIs
- Troubleshooting - Common issues, debugging, error reference
- Code Examples - 500+ examples
GeoMaster covers everything from basic GIS operations to advanced remote sensing and machine learning.
1---2name: geomaster3description: Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains. Supports satellite imagery processing (Sentinel, Landsat, MODIS, SAR, hyperspectral), vector and raster data operations, spatial statistics, point cloud processing, network analysis, cloud-native workflows (STAC, COG, Planetary Computer), and 8 programming languages (Python, R, Julia, JavaScript, C++, Java, Go, Rust) with 500+ code examples. Use for remote sensing workflows, GIS analysis, spatial ML, Earth observation data processing, terrain analysis, hydrological modeling, marine spatial analysis, atmospheric science, and any geospatial computation task.4license: MIT License5metadata:6 source: https://skillmd.com/skills/qhjqhj00/geomaster7 skill-author: K-Dense Inc.8---910# GeoMaster1112Comprehensive geospatial science skill covering GIS, remote sensing, spatial analysis, and ML for Earth observation across 70+ topics with 500+ code examples in 8 programming languages.1314## Installation1516```bash17# Core Python stack (conda recommended)18conda install -c conda-forge gdal rasterio fiona shapely pyproj geopandas1920# Remote sensing & ML21uv pip install rsgislib torchgeo earthengine-api22uv pip install scikit-learn xgboost torch-geometric2324# Network & visualization25uv pip install osmnx networkx folium keplergl26uv pip install cartopy contextily mapclassify2728# Big data & cloud29uv pip install xarray rioxarray dask-geopandas30uv pip install pystac-client planetary-computer3132# Point clouds33uv pip install laspy pylas open3d pdal3435# Databases36conda install -c conda-forge postgis spatialite37```3839## Quick Start4041### NDVI from Sentinel-24243```python44import rasterio45import numpy as np4647with rasterio.open('sentinel2.tif') as src:48 red = src.read(4).astype(float) # B0449 nir = src.read(8).astype(float) # B0850 ndvi = (nir - red) / (nir + red + 1e-8)51 ndvi = np.nan_to_num(ndvi, nan=0)5253 profile = src.profile54 profile.update(count=1, dtype=rasterio.float32)5556 with rasterio.open('ndvi.tif', 'w', **profile) as dst:57 dst.write(ndvi.astype(rasterio.float32), 1)58```5960### Spatial Analysis with GeoPandas6162```python63import geopandas as gpd6465# Load and ensure same CRS66zones = gpd.read_file('zones.geojson')67points = gpd.read_file('points.geojson')6869if zones.crs != points.crs:70 points = points.to_crs(zones.crs)7172# Spatial join and statistics73joined = gpd.sjoin(points, zones, how='inner', predicate='within')74stats = joined.groupby('zone_id').agg({75 'value': ['count', 'mean', 'std', 'min', 'max']76}).round(2)77```7879### Google Earth Engine Time Series8081```python82import ee83import pandas as pd8485ee.Initialize(project='your-project')86roi = ee.Geometry.Point([-122.4, 37.7]).buffer(10000)8788s2 = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')89 .filterBounds(roi)90 .filterDate('2020-01-01', '2023-12-31')91 .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20)))9293def add_ndvi(img):94 return img.addBands(img.normalizedDifference(['B8', 'B4']).rename('NDVI'))9596s2_ndvi = s2.map(add_ndvi)9798def extract_series(image):99 stats = image.reduceRegion(ee.Reducer.mean(), roi.centroid(), scale=10, maxPixels=1e9)100 return ee.Feature(None, {'date': image.date().format('YYYY-MM-dd'), 'ndvi': stats.get('NDVI')})101102series = s2_ndvi.map(extract_series).getInfo()103df = pd.DataFrame([f['properties'] for f in series['features']])104df['date'] = pd.to_datetime(df['date'])105```106107## Core Concepts108109### Data Types110111| Type | Examples | Libraries |112|------|----------|-----------|113| Vector | Shapefile, GeoJSON, GeoPackage | GeoPandas, Fiona, GDAL |114| Raster | GeoTIFF, NetCDF, COG | Rasterio, Xarray, GDAL |115| Point Cloud | LAS, LAZ | Laspy, PDAL, Open3D |116117### Coordinate Systems118119- **EPSG:4326** (WGS 84) - Geographic, lat/lon, use for storage120- **EPSG:3857** (Web Mercator) - Web maps only (don't use for area/distance!)121- **EPSG:326xx/327xx** (UTM) - Metric calculations, <1% distortion per zone122- Use `gdf.estimate_utm_crs()` for automatic UTM detection123124```python125# Always check CRS before operations126assert gdf1.crs == gdf2.crs, "CRS mismatch!"127128# For area/distance calculations, use projected CRS129gdf_metric = gdf.to_crs(gdf.estimate_utm_crs())130area_sqm = gdf_metric.geometry.area131```132133### OGC Standards134135- **WMS**: Web Map Service - raster maps136- **WFS**: Web Feature Service - vector data137- **WCS**: Web Coverage Service - raster coverage138- **STAC**: Spatiotemporal Asset Catalog - modern metadata139140## Common Operations141142### Spectral Indices143144```python145def calculate_indices(image_path):146 """NDVI, EVI, SAVI, NDWI from Sentinel-2."""147 with rasterio.open(image_path) as src:148 B02, B03, B04, B08, B11 = [src.read(i).astype(float) for i in [1,2,3,4,5]]149150 ndvi = (B08 - B04) / (B08 + B04 + 1e-8)151 evi = 2.5 * (B08 - B04) / (B08 + 6*B04 - 7.5*B02 + 1)152 savi = ((B08 - B04) / (B08 + B04 + 0.5)) * 1.5153 ndwi = (B03 - B08) / (B03 + B08 + 1e-8)154155 return {'NDVI': ndvi, 'EVI': evi, 'SAVI': savi, 'NDWI': ndwi}156```157158### Vector Operations159160```python161# Buffer (use projected CRS!)162gdf_proj = gdf.to_crs(gdf.estimate_utm_crs())163gdf['buffer_1km'] = gdf_proj.geometry.buffer(1000)164165# Spatial relationships166intersects = gdf[gdf.geometry.intersects(other_geometry)]167contains = gdf[gdf.geometry.contains(point_geometry)]168169# Geometric operations170gdf['centroid'] = gdf.geometry.centroid171gdf['simplified'] = gdf.geometry.simplify(tolerance=0.001)172173# Overlay operations174intersection = gpd.overlay(gdf1, gdf2, how='intersection')175union = gpd.overlay(gdf1, gdf2, how='union')176```177178### Terrain Analysis179180```python181def terrain_metrics(dem_path):182 """Calculate slope, aspect, hillshade from DEM."""183 with rasterio.open(dem_path) as src:184 dem = src.read(1)185186 dy, dx = np.gradient(dem)187 slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi188 aspect = (90 - np.arctan2(-dy, dx) * 180 / np.pi) % 360189190 # Hillshade191 az_rad, alt_rad = np.radians(315), np.radians(45)192 hillshade = (np.sin(alt_rad) * np.sin(np.radians(slope)) +193 np.cos(alt_rad) * np.cos(np.radians(slope)) *194 np.cos(np.radians(aspect) - az_rad))195196 return slope, aspect, hillshade197```198199### Network Analysis200201```python202import osmnx as ox203import networkx as nx204205# Download and analyze street network206G = ox.graph_from_place('San Francisco, CA', network_type='drive')207G = ox.add_edge_speeds(G).add_edge_travel_times(G)208209# Shortest path210orig = ox.distance.nearest_nodes(G, -122.4, 37.7)211dest = ox.distance.nearest_nodes(G, -122.3, 37.8)212route = nx.shortest_path(G, orig, dest, weight='travel_time')213```214215## Image Classification216217```python218from sklearn.ensemble import RandomForestClassifier219import rasterio220from rasterio.features import rasterize221222def classify_imagery(raster_path, training_gdf, output_path):223 """Train RF and classify imagery."""224 with rasterio.open(raster_path) as src:225 image = src.read()226 profile = src.profile227 transform = src.transform228229 # Extract training data230 X_train, y_train = [], []231 for _, row in training_gdf.iterrows():232 mask = rasterize([(row.geometry, 1)],233 out_shape=(profile['height'], profile['width']),234 transform=transform, fill=0, dtype=np.uint8)235 pixels = image[:, mask > 0].T236 X_train.extend(pixels)237 y_train.extend([row['class_id']] * len(pixels))238239 # Train and predict240 rf = RandomForestClassifier(n_estimators=100, max_depth=20, n_jobs=-1)241 rf.fit(X_train, y_train)242243 prediction = rf.predict(image.reshape(image.shape[0], -1).T)244 prediction = prediction.reshape(profile['height'], profile['width'])245246 profile.update(dtype=rasterio.uint8, count=1)247 with rasterio.open(output_path, 'w', **profile) as dst:248 dst.write(prediction.astype(rasterio.uint8), 1)249250 return rf251```252253## Modern Cloud-Native Workflows254255### STAC + Planetary Computer256257```python258import pystac_client259import planetary_computer260import odc.stac261262# Search Sentinel-2 via STAC263catalog = pystac_client.Client.open(264 "https://planetarycomputer.microsoft.com/api/stac/v1",265 modifier=planetary_computer.sign_inplace,266)267268search = catalog.search(269 collections=["sentinel-2-l2a"],270 bbox=[-122.5, 37.7, -122.3, 37.9],271 datetime="2023-01-01/2023-12-31",272 query={"eo:cloud_cover": {"lt": 20}},273)274275# Load as xarray (cloud-native!)276data = odc.stac.load(277 list(search.get_items())[:5],278 bands=["B02", "B03", "B04", "B08"],279 crs="EPSG:32610",280 resolution=10,281)282283# Calculate NDVI on xarray284ndvi = (data.B08 - data.B04) / (data.B08 + data.B04)285```286287### Cloud-Optimized GeoTIFF (COG)288289```python290import rasterio291from rasterio.session import AWSSession292293# Read COG directly from cloud (partial reads)294session = AWSSession(aws_access_key_id=..., aws_secret_access_key=...)295with rasterio.open('s3://bucket/path.tif', session=session) as src:296 # Read only window of interest297 window = ((1000, 2000), (1000, 2000))298 subset = src.read(1, window=window)299300# Write COG301with rasterio.open('output.tif', 'w', **profile,302 tiled=True, blockxsize=256, blockysize=256,303 compress='DEFLATE', predictor=2) as dst:304 dst.write(data)305306# Validate COG307from rio_cogeo.cogeo import cog_validate308cog_validate('output.tif')309```310311## Performance Tips312313```python314# 1. Spatial indexing (10-100x faster queries)315gdf.sindex # Auto-created by GeoPandas316317# 2. Chunk large rasters318with rasterio.open('large.tif') as src:319 for i, window in src.block_windows(1):320 block = src.read(1, window=window)321322# 3. Dask for big data323import dask.array as da324dask_array = da.from_rasterio('large.tif', chunks=(1, 1024, 1024))325326# 4. Use Arrow for I/O327gdf.to_file('output.gpkg', use_arrow=True)328329# 5. GDAL caching330from osgeo import gdal331gdal.SetCacheMax(2**30) # 1GB cache332333# 6. Parallel processing334rf = RandomForestClassifier(n_jobs=-1) # All cores335```336337## Best Practices3383391. **Always check CRS** before spatial operations3402. **Use projected CRS** for area/distance calculations3413. **Validate geometries**: `gdf = gdf[gdf.is_valid]`3424. **Handle missing data**: `gdf['geometry'] = gdf['geometry'].fillna(None)`3435. **Use efficient formats**: GeoPackage > Shapefile, Parquet for large data3446. **Apply cloud masking** to optical imagery3457. **Preserve lineage** for reproducible research3468. **Use appropriate resolution** for your analysis scale347348## Detailed Documentation349350- **[Coordinate Systems](references/coordinate-systems.md)** - CRS fundamentals, UTM, transformations351- **[Core Libraries](references/core-libraries.md)** - GDAL, Rasterio, GeoPandas, Shapely352- **[Remote Sensing](references/remote-sensing.md)** - Satellite missions, spectral indices, SAR353- **[Machine Learning](references/machine-learning.md)** - Deep learning, CNNs, GNNs for RS354- **[GIS Software](references/gis-software.md)** - QGIS, ArcGIS, GRASS integration355- **[Scientific Domains](references/scientific-domains.md)** - Marine, hydrology, agriculture, forestry356- **[Advanced GIS](references/advanced-gis.md)** - 3D GIS, spatiotemporal, topology357- **[Big Data](references/big-data.md)** - Distributed processing, GPU acceleration358- **[Industry Applications](references/industry-applications.md)** - Urban planning, disaster management359- **[Programming Languages](references/programming-languages.md)** - Python, R, Julia, JS, C++, Java, Go, Rust360- **[Data Sources](references/data-sources.md)** - Satellite catalogs, APIs361- **[Troubleshooting](references/troubleshooting.md)** - Common issues, debugging, error reference362- **[Code Examples](references/code-examples.md)** - 500+ examples363364---365366**GeoMaster covers everything from basic GIS operations to advanced remote sensing and machine learning.**