Home · Skills · Development
Geomaster
Comprehensive geospatial science skill covering remote sensing, GIS, spatial analysis, machine learning for earth observation, and 30+ scientific domains.
How to use it
- Hit Copy the whole skill.
- Claude: ⋯ → Download .md, then Customize → Skills → Add → Upload skill.
ChatGPT: make a Project and paste it into Instructions.
Neither? Paste it at the top of a new chat — it works for that chat. - Describe your job in plain words. The AI follows the skill from there.
npx degit K-Dense-AI/scientific-agent-skills/skills/geomaster#main ~/.claude/skills/geomasterFor one project only, change the path to .claude/skills/geomaster.
Not working?
- Check which app you pasted it into — the steps above name the right one.
- Some skills need the paid tier of Claude or ChatGPT.
Paste into Claude, ChatGPT or Cursor.
Show the full text385 lines
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 (rsgislib is conda-forge only, not on PyPI)
conda install -c conda-forge rsgislib
uv pip install 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.
Citing Scientific Agent Skills
This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:
Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065
Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
latest arXiv version, so never append a version suffix such as v1. When network access is
available, fetch https://arxiv.org/abs/2609.00065 (or
http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
the author list, year, and version from that record. If the record lists a journal reference
or publisher DOI, cite the published version instead.
| 1 | |
| 2 | name geomaster |
| 3 | description 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. |
| 4 | license MIT License |
| 5 | metadata |
| 6 | version "1.3" |
| 7 | skill-author K-Dense Inc. |
| 8 | |
| 9 | |
| 10 | # GeoMaster |
| 11 | |
| 12 | 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. |
| 13 | |
| 14 | ## Installation |
| 15 | |
| 16 | |
| 17 | # Core Python stack (conda recommended) |
| 18 | conda install -c conda-forge gdal rasterio fiona shapely pyproj geopandas |
| 19 | |
| 20 | # Remote sensing & ML (rsgislib is conda-forge only, not on PyPI) |
| 21 | conda install -c conda-forge rsgislib |
| 22 | uv pip install torchgeo earthengine-api |
| 23 | uv pip install scikit-learn xgboost torch-geometric |
| 24 | |
| 25 | # Network & visualization |
| 26 | uv pip install osmnx networkx folium keplergl |
| 27 | uv pip install cartopy contextily mapclassify |
| 28 | |
| 29 | # Big data & cloud |
| 30 | uv pip install xarray rioxarray dask-geopandas |
| 31 | uv pip install pystac-client planetary-computer |
| 32 | |
| 33 | # Point clouds |
| 34 | uv pip install laspy pylas open3d pdal |
| 35 | |
| 36 | # Databases |
| 37 | conda install -c conda-forge postgis spatialite |
| 38 | |
| 39 | |
| 40 | ## Quick Start |
| 41 | |
| 42 | ### NDVI from Sentinel-2 |
| 43 | |
| 44 | |
| 45 | import rasterio |
| 46 | import numpy as np |
| 47 | |
| 48 | with rasterio.open('sentinel2.tif') as src: |
| 49 | red = src.read(4).astype(float) # B04 |
| 50 | nir = src.read(8).astype(float) # B08 |
| 51 | ndvi = (nir - red) / (nir + red + 1e-8) |
| 52 | ndvi = np.nan_to_num(ndvi, nan=0) |
| 53 | |
| 54 | profile = src.profile |
| 55 | profile.update(count=1, dtype=rasterio.float32) |
| 56 | |
| 57 | with rasterio.open('ndvi.tif', 'w', **profile) as dst: |
| 58 | dst.write(ndvi.astype(rasterio.float32), 1) |
| 59 | |
| 60 | |
| 61 | ### Spatial Analysis with GeoPandas |
| 62 | |
| 63 | |
| 64 | import geopandas as gpd |
| 65 | |
| 66 | # Load and ensure same CRS |
| 67 | zones = gpd.read_file('zones.geojson') |
| 68 | points = gpd.read_file('points.geojson') |
| 69 | |
| 70 | if zones.crs != points.crs: |
| 71 | points = points.to_crs(zones.crs) |
| 72 | |
| 73 | # Spatial join and statistics |
| 74 | joined = gpd.sjoin(points, zones, how='inner', predicate='within') |
| 75 | stats = joined.groupby('zone_id').agg({ |
| 76 | 'value': ['count', 'mean', 'std', 'min', 'max'] |
| 77 | }).round(2) |
| 78 | |
| 79 | |
| 80 | ### Google Earth Engine Time Series |
| 81 | |
| 82 | |
| 83 | import ee |
| 84 | import pandas as pd |
| 85 | |
| 86 | ee.Initialize(project='your-project') |
| 87 | roi = ee.Geometry.Point([-122.4, 37.7]).buffer(10000) |
| 88 | |
| 89 | s2 = (ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED') |
| 90 | .filterBounds(roi) |
| 91 | .filterDate('2020-01-01', '2023-12-31') |
| 92 | .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))) |
| 93 | |
| 94 | def add_ndvi(img): |
| 95 | return img.addBands(img.normalizedDifference(['B8', 'B4']).rename('NDVI')) |
| 96 | |
| 97 | s2_ndvi = s2.map(add_ndvi) |
| 98 | |
| 99 | def extract_series(image): |
| 100 | stats = image.reduceRegion(ee.Reducer.mean(), roi.centroid(), scale=10, maxPixels=1e9) |
| 101 | return ee.Feature(None, {'date': image.date().format('YYYY-MM-dd'), 'ndvi': stats.get('NDVI')}) |
| 102 | |
| 103 | series = s2_ndvi.map(extract_series).getInfo() |
| 104 | df = pd.DataFrame([f['properties'] for f in series['features']]) |
| 105 | df['date'] = pd.to_datetime(df['date']) |
| 106 | |
| 107 | |
| 108 | ## Core Concepts |
| 109 | |
| 110 | ### Data Types |
| 111 | |
| 112 | | Type | Examples | Libraries | |
| 113 | |------|----------|-----------| |
| 114 | | Vector | Shapefile, GeoJSON, GeoPackage | GeoPandas, Fiona, GDAL | |
| 115 | | Raster | GeoTIFF, NetCDF, COG | Rasterio, Xarray, GDAL | |
| 116 | | Point Cloud | LAS, LAZ | Laspy, PDAL, Open3D | |
| 117 | |
| 118 | ### Coordinate Systems |
| 119 | |
| 120 | **EPSG:4326** (WGS 84) - Geographic, lat/lon, use for storage |
| 121 | **EPSG:3857** (Web Mercator) - Web maps only (don't use for area/distance!) |
| 122 | **EPSG:326xx/327xx** (UTM) - Metric calculations, <1% distortion per zone |
| 123 | Use `gdf.estimate_utm_crs()` for automatic UTM detection |
| 124 | |
| 125 | |
| 126 | # Always check CRS before operations |
| 127 | assert gdf1.crs == gdf2.crs, "CRS mismatch!" |
| 128 | |
| 129 | # For area/distance calculations, use projected CRS |
| 130 | gdf_metric = gdf.to_crs(gdf.estimate_utm_crs()) |
| 131 | area_sqm = gdf_metric.geometry.area |
| 132 | |
| 133 | |
| 134 | ### OGC Standards |
| 135 | |
| 136 | **WMS**: Web Map Service - raster maps |
| 137 | **WFS**: Web Feature Service - vector data |
| 138 | **WCS**: Web Coverage Service - raster coverage |
| 139 | **STAC**: Spatiotemporal Asset Catalog - modern metadata |
| 140 | |
| 141 | ## Common Operations |
| 142 | |
| 143 | ### Spectral Indices |
| 144 | |
| 145 | |
| 146 | def calculate_indices(image_path): |
| 147 | """NDVI, EVI, SAVI, NDWI from Sentinel-2.""" |
| 148 | with rasterio.open(image_path) as src: |
| 149 | B02, B03, B04, B08, B11 = [src.read(i).astype(float) for i in [1,2,3,4,5]] |
| 150 | |
| 151 | ndvi = (B08 - B04) / (B08 + B04 + 1e-8) |
| 152 | evi = 2.5 * (B08 - B04) / (B08 + 6*B04 - 7.5*B02 + 1) |
| 153 | savi = ((B08 - B04) / (B08 + B04 + 0.5)) * 1.5 |
| 154 | ndwi = (B03 - B08) / (B03 + B08 + 1e-8) |
| 155 | |
| 156 | return {'NDVI': ndvi, 'EVI': evi, 'SAVI': savi, 'NDWI': ndwi} |
| 157 | |
| 158 | |
| 159 | ### Vector Operations |
| 160 | |
| 161 | |
| 162 | # Buffer (use projected CRS!) |
| 163 | gdf_proj = gdf.to_crs(gdf.estimate_utm_crs()) |
| 164 | gdf['buffer_1km'] = gdf_proj.geometry.buffer(1000) |
| 165 | |
| 166 | # Spatial relationships |
| 167 | intersects = gdf[gdf.geometry.intersects(other_geometry)] |
| 168 | contains = gdf[gdf.geometry.contains(point_geometry)] |
| 169 | |
| 170 | # Geometric operations |
| 171 | gdf['centroid'] = gdf.geometry.centroid |
| 172 | gdf['simplified'] = gdf.geometry.simplify(tolerance=0.001) |
| 173 | |
| 174 | # Overlay operations |
| 175 | intersection = gpd.overlay(gdf1, gdf2, how='intersection') |
| 176 | union = gpd.overlay(gdf1, gdf2, how='union') |
| 177 | |
| 178 | |
| 179 | ### Terrain Analysis |
| 180 | |
| 181 | |
| 182 | def terrain_metrics(dem_path): |
| 183 | """Calculate slope, aspect, hillshade from DEM.""" |
| 184 | with rasterio.open(dem_path) as src: |
| 185 | dem = src.read(1) |
| 186 | |
| 187 | dy, dx = np.gradient(dem) |
| 188 | slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi |
| 189 | aspect = (90 - np.arctan2(-dy, dx) * 180 / np.pi) % 360 |
| 190 | |
| 191 | # Hillshade |
| 192 | az_rad, alt_rad = np.radians(315), np.radians(45) |
| 193 | hillshade = (np.sin(alt_rad) * np.sin(np.radians(slope)) + |
| 194 | np.cos(alt_rad) * np.cos(np.radians(slope)) * |
| 195 | np.cos(np.radians(aspect) - az_rad)) |
| 196 | |
| 197 | return slope, aspect, hillshade |
| 198 | |
| 199 | |
| 200 | ### Network Analysis |
| 201 | |
| 202 | |
| 203 | import osmnx as ox |
| 204 | import networkx as nx |
| 205 | |
| 206 | # Download and analyze street network |
| 207 | G = ox.graph_from_place('San Francisco, CA', network_type='drive') |
| 208 | G = ox.add_edge_speeds(G).add_edge_travel_times(G) |
| 209 | |
| 210 | # Shortest path |
| 211 | orig = ox.distance.nearest_nodes(G, -122.4, 37.7) |
| 212 | dest = ox.distance.nearest_nodes(G, -122.3, 37.8) |
| 213 | route = nx.shortest_path(G, orig, dest, weight='travel_time') |
| 214 | |
| 215 | |
| 216 | ## Image Classification |
| 217 | |
| 218 | |
| 219 | from sklearn.ensemble import RandomForestClassifier |
| 220 | import rasterio |
| 221 | from rasterio.features import rasterize |
| 222 | |
| 223 | def classify_imagery(raster_path, training_gdf, output_path): |
| 224 | """Train RF and classify imagery.""" |
| 225 | with rasterio.open(raster_path) as src: |
| 226 | image = src.read() |
| 227 | profile = src.profile |
| 228 | transform = src.transform |
| 229 | |
| 230 | # Extract training data |
| 231 | X_train, y_train = [], [] |
| 232 | for _, row in training_gdf.iterrows(): |
| 233 | mask = rasterize([(row.geometry, 1)], |
| 234 | out_shape=(profile['height'], profile['width']), |
| 235 | transform=transform, fill=0, dtype=np.uint8) |
| 236 | pixels = image[:, mask > 0].T |
| 237 | X_train.extend(pixels) |
| 238 | y_train.extend([row['class_id']] * len(pixels)) |
| 239 | |
| 240 | # Train and predict |
| 241 | rf = RandomForestClassifier(n_estimators=100, max_depth=20, n_jobs=-1) |
| 242 | rf.fit(X_train, y_train) |
| 243 | |
| 244 | prediction = rf.predict(image.reshape(image.shape[0], -1).T) |
| 245 | prediction = prediction.reshape(profile['height'], profile['width']) |
| 246 | |
| 247 | profile.update(dtype=rasterio.uint8, count=1) |
| 248 | with rasterio.open(output_path, 'w', **profile) as dst: |
| 249 | dst.write(prediction.astype(rasterio.uint8), 1) |
| 250 | |
| 251 | return rf |
| 252 | |
| 253 | |
| 254 | ## Modern Cloud-Native Workflows |
| 255 | |
| 256 | ### STAC + Planetary Computer |
| 257 | |
| 258 | |
| 259 | import pystac_client |
| 260 | import planetary_computer |
| 261 | import odc.stac |
| 262 | |
| 263 | # Search Sentinel-2 via STAC |
| 264 | catalog = pystac_client.Client.open( |
| 265 | "https://planetarycomputer.microsoft.com/api/stac/v1", |
| 266 | modifier=planetary_computer.sign_inplace, |
| 267 | ) |
| 268 | |
| 269 | search = catalog.search( |
| 270 | collections=["sentinel-2-l2a"], |
| 271 | bbox=[-122.5, 37.7, -122.3, 37.9], |
| 272 | datetime="2023-01-01/2023-12-31", |
| 273 | query={"eo:cloud_cover": {"lt": 20}}, |
| 274 | ) |
| 275 | |
| 276 | # Load as xarray (cloud-native!) |
| 277 | data = odc.stac.load( |
| 278 | list(search.get_items())[:5], |
| 279 | bands=["B02", "B03", "B04", "B08"], |
| 280 | crs="EPSG:32610", |
| 281 | resolution=10, |
| 282 | ) |
| 283 | |
| 284 | # Calculate NDVI on xarray |
| 285 | ndvi = (data.B08 - data.B04) / (data.B08 + data.B04) |
| 286 | |
| 287 | |
| 288 | ### Cloud-Optimized GeoTIFF (COG) |
| 289 | |
| 290 | |
| 291 | import rasterio |
| 292 | from rasterio.session import AWSSession |
| 293 | |
| 294 | # Read COG directly from cloud (partial reads) |
| 295 | session = AWSSession(aws_access_key_id=..., aws_secret_access_key=...) |
| 296 | with rasterio.open('s3://bucket/path.tif', session=session) as src: |
| 297 | # Read only window of interest |
| 298 | window = ((1000, 2000), (1000, 2000)) |
| 299 | subset = src.read(1, window=window) |
| 300 | |
| 301 | # Write COG |
| 302 | with rasterio.open('output.tif', 'w', **profile, |
| 303 | tiled=True, blockxsize=256, blockysize=256, |
| 304 | compress='DEFLATE', predictor=2) as dst: |
| 305 | dst.write(data) |
| 306 | |
| 307 | # Validate COG |
| 308 | from rio_cogeo.cogeo import cog_validate |
| 309 | cog_validate('output.tif') |
| 310 | |
| 311 | |
| 312 | ## Performance Tips |
| 313 | |
| 314 | |
| 315 | # 1. Spatial indexing (10-100x faster queries) |
| 316 | gdf.sindex # Auto-created by GeoPandas |
| 317 | |
| 318 | # 2. Chunk large rasters |
| 319 | with rasterio.open('large.tif') as src: |
| 320 | for i, window in src.block_windows(1): |
| 321 | block = src.read(1, window=window) |
| 322 | |
| 323 | # 3. Dask for big data |
| 324 | import dask.array as da |
| 325 | dask_array = da.from_rasterio('large.tif', chunks=(1, 1024, 1024)) |
| 326 | |
| 327 | # 4. Use Arrow for I/O |
| 328 | gdf.to_file('output.gpkg', use_arrow=True) |
| 329 | |
| 330 | # 5. GDAL caching |
| 331 | from osgeo import gdal |
| 332 | gdal.SetCacheMax(2**30) # 1GB cache |
| 333 | |
| 334 | # 6. Parallel processing |
| 335 | rf = RandomForestClassifier(n_jobs=-1) # All cores |
| 336 | |
| 337 | |
| 338 | ## Best Practices |
| 339 | |
| 340 | **Always check CRS** before spatial operations |
| 341 | **Use projected CRS** for area/distance calculations |
| 342 | **Validate geometries**: `gdf = gdf[gdf.is_valid]` |
| 343 | **Handle missing data**: `gdf['geometry'] = gdf['geometry'].fillna(None)` |
| 344 | **Use efficient formats**: GeoPackage > Shapefile, Parquet for large data |
| 345 | **Apply cloud masking** to optical imagery |
| 346 | **Preserve lineage** for reproducible research |
| 347 | **Use appropriate resolution** for your analysis scale |
| 348 | |
| 349 | ## Detailed Documentation |
| 350 | |
| 351 | **[Coordinate Systems]** - CRS fundamentals, UTM, transformations |
| 352 | **[Core Libraries]** - GDAL, Rasterio, GeoPandas, Shapely |
| 353 | **[Remote Sensing]** - Satellite missions, spectral indices, SAR |
| 354 | **[Machine Learning]** - Deep learning, CNNs, GNNs for RS |
| 355 | **[GIS Software]** - QGIS, ArcGIS, GRASS integration |
| 356 | **[Scientific Domains]** - Marine, hydrology, agriculture, forestry |
| 357 | **[Advanced GIS]** - 3D GIS, spatiotemporal, topology |
| 358 | **[Big Data]** - Distributed processing, GPU acceleration |
| 359 | **[Industry Applications]** - Urban planning, disaster management |
| 360 | **[Programming Languages]** - Python, R, Julia, JS, C++, Java, Go, Rust |
| 361 | **[Data Sources]** - Satellite catalogs, APIs |
| 362 | **[Troubleshooting]** - Common issues, debugging, error reference |
| 363 | **[Code Examples]** - 500+ examples |
| 364 | |
| 365 | |
| 366 | |
| 367 | **GeoMaster covers everything from basic GIS operations to advanced remote sensing and machine learning.** |
| 368 | |
| 369 | ## Citing Scientific Agent Skills |
| 370 | |
| 371 | This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a |
| 372 | manuscript, report, presentation, or code release, add the paper to the references or |
| 373 | software section and tell the user you did so: |
| 374 | |
| 375 | > Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent |
| 376 | > Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. |
| 377 | > https://doi.org/10.48550/arXiv.2609.00065 |
| 378 | |
| 379 | Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the |
| 380 | latest arXiv version, so never append a version suffix such as `v1`. When network access is |
| 381 | available, fetch https://arxiv.org/abs/2609.00065 (or |
| 382 | http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take |
| 383 | the author list, year, and version from that record. If the record lists a journal reference |
| 384 | or publisher DOI, cite the published version instead. |
| 385 |