terraproof 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +356 -2
- package/bin/terraproof.js +4 -0
- package/dist/router/apply.js +147 -0
- package/dist/router/classify.js +111 -0
- package/dist/router/explain.js +9 -0
- package/dist/router/index.js +272 -0
- package/dist/router/resolve.js +239 -0
- package/dist/router/score.js +60 -0
- package/dist/router/types.js +1 -0
- package/dist/router/validate.js +81 -0
- package/instructions/engineering.md +14 -0
- package/instructions/security.md +14 -0
- package/instructions/simplicity.md +13 -0
- package/package.json +65 -4
- package/routing/DOMAIN_ROUTING.md +161 -0
- package/routing/ROUTER_DESIGN.md +173 -0
- package/routing/SKILL_MANIFEST.md +86 -0
- package/routing/checks.json +121 -0
- package/routing/collections.json +47 -0
- package/routing/registry.json +2211 -0
- package/routing/rules.json +64 -0
- package/skills/accuracy-assessment/SKILL.md +213 -0
- package/skills/accuracy-assessment/UPSTREAM.md +7 -0
- package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
- package/skills/accuracy-assessment/skill.json +103 -0
- package/skills/brainstorming/SKILL.md +250 -0
- package/skills/brainstorming/UPSTREAM.md +29 -0
- package/skills/brainstorming/scripts/frame-template.html +213 -0
- package/skills/brainstorming/scripts/helper.js +167 -0
- package/skills/brainstorming/scripts/server.cjs +723 -0
- package/skills/brainstorming/scripts/start-server.sh +209 -0
- package/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/skills/brainstorming/skill.json +73 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +299 -0
- package/skills/crs-and-units/SKILL.md +200 -0
- package/skills/crs-and-units/UPSTREAM.md +7 -0
- package/skills/crs-and-units/skill.json +74 -0
- package/skills/design-postgis-tables/SKILL.md +494 -0
- package/skills/design-postgis-tables/UPSTREAM.md +21 -0
- package/skills/design-postgis-tables/skill.json +90 -0
- package/skills/gdal/SKILL.md +125 -0
- package/skills/gdal/UPSTREAM.md +22 -0
- package/skills/gdal/references/gdal-recipes.md +103 -0
- package/skills/gdal/skill.json +66 -0
- package/skills/geomaster/README.md +105 -0
- package/skills/geomaster/SKILL.md +366 -0
- package/skills/geomaster/UPSTREAM.md +21 -0
- package/skills/geomaster/references/advanced-gis.md +376 -0
- package/skills/geomaster/references/big-data.md +363 -0
- package/skills/geomaster/references/code-examples.md +531 -0
- package/skills/geomaster/references/coordinate-systems.md +364 -0
- package/skills/geomaster/references/core-libraries.md +273 -0
- package/skills/geomaster/references/data-sources.md +330 -0
- package/skills/geomaster/references/gis-software.md +369 -0
- package/skills/geomaster/references/industry-applications.md +420 -0
- package/skills/geomaster/references/machine-learning.md +462 -0
- package/skills/geomaster/references/programming-languages.md +456 -0
- package/skills/geomaster/references/remote-sensing.md +370 -0
- package/skills/geomaster/references/scientific-domains.md +416 -0
- package/skills/geomaster/references/specialized-topics.md +428 -0
- package/skills/geomaster/references/troubleshooting.md +439 -0
- package/skills/geomaster/skill.json +157 -0
- package/skills/geopandas/SKILL.md +250 -0
- package/skills/geopandas/UPSTREAM.md +22 -0
- package/skills/geopandas/references/crs-management.md +231 -0
- package/skills/geopandas/references/data-io.md +323 -0
- package/skills/geopandas/references/data-structures.md +207 -0
- package/skills/geopandas/references/geometric-operations.md +262 -0
- package/skills/geopandas/references/spatial-analysis.md +294 -0
- package/skills/geopandas/references/visualization.md +230 -0
- package/skills/geopandas/scripts/_common.py +605 -0
- package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
- package/skills/geopandas/scripts/export_plan.py +305 -0
- package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
- package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
- package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
- package/skills/geopandas/scripts/vector_inventory.py +140 -0
- package/skills/geopandas/skill.json +116 -0
- package/skills/geoparquet-validation/SKILL.md +125 -0
- package/skills/geoparquet-validation/UPSTREAM.md +24 -0
- package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
- package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
- package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
- package/skills/geoparquet-validation/skill.json +71 -0
- package/skills/geospatial-data-discovery/SKILL.md +49 -0
- package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
- package/skills/geospatial-data-discovery/skill.json +51 -0
- package/skills/geospatial-frontend/SKILL.md +86 -0
- package/skills/geospatial-frontend/UPSTREAM.md +23 -0
- package/skills/geospatial-frontend/references/design-system.md +283 -0
- package/skills/geospatial-frontend/references/user-preferences.md +96 -0
- package/skills/geospatial-frontend/skill.json +87 -0
- package/skills/geozarr/SKILL.md +244 -0
- package/skills/geozarr/UPSTREAM.md +21 -0
- package/skills/geozarr/skill.json +97 -0
- package/skills/networkx/SKILL.md +440 -0
- package/skills/networkx/UPSTREAM.md +22 -0
- package/skills/networkx/references/algorithms.md +384 -0
- package/skills/networkx/references/generators.md +385 -0
- package/skills/networkx/references/graph-basics.md +284 -0
- package/skills/networkx/references/io.md +457 -0
- package/skills/networkx/references/visualization.md +531 -0
- package/skills/networkx/skill.json +93 -0
- package/skills/raster-processing/SKILL.md +222 -0
- package/skills/raster-processing/UPSTREAM.md +7 -0
- package/skills/raster-processing/skill.json +81 -0
- package/skills/sar-basics/SKILL.md +202 -0
- package/skills/sar-basics/UPSTREAM.md +7 -0
- package/skills/sar-basics/references/calibration-lut.md +98 -0
- package/skills/sar-basics/skill.json +97 -0
- package/skills/satellite-preprocessing/SKILL.md +241 -0
- package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
- package/skills/satellite-preprocessing/skill.json +84 -0
- package/skills/scientific-visualization/SKILL.md +285 -0
- package/skills/scientific-visualization/UPSTREAM.md +25 -0
- package/skills/scientific-visualization/assets/color_palettes.py +263 -0
- package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
- package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
- package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
- package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
- package/skills/scientific-visualization/references/color_palettes.md +227 -0
- package/skills/scientific-visualization/references/journal_requirements.md +169 -0
- package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
- package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
- package/skills/scientific-visualization/references/sources.md +76 -0
- package/skills/scientific-visualization/scripts/_common.py +136 -0
- package/skills/scientific-visualization/scripts/export_plan.py +493 -0
- package/skills/scientific-visualization/scripts/figure_export.py +642 -0
- package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
- package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
- package/skills/scientific-visualization/scripts/style_presets.py +501 -0
- package/skills/scientific-visualization/scripts/style_preview.py +232 -0
- package/skills/scientific-visualization/skill.json +95 -0
- package/skills/spectral-indices/SKILL.md +235 -0
- package/skills/spectral-indices/UPSTREAM.md +7 -0
- package/skills/spectral-indices/skill.json +88 -0
- package/skills/stac-and-cloud-access/SKILL.md +209 -0
- package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
- package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
- package/skills/stac-and-cloud-access/skill.json +98 -0
- package/skills/statistical-analysis/SKILL.md +446 -0
- package/skills/statistical-analysis/UPSTREAM.md +24 -0
- package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
- package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
- package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
- package/skills/statistical-analysis/references/reporting_standards.md +482 -0
- package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
- package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
- package/skills/statistical-analysis/skill.json +127 -0
- package/skills/systematic-debugging/SKILL.md +283 -0
- package/skills/systematic-debugging/UPSTREAM.md +28 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +72 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/skill.json +88 -0
- package/skills/time-series-and-change/SKILL.md +217 -0
- package/skills/time-series-and-change/UPSTREAM.md +7 -0
- package/skills/time-series-and-change/references/change-methods.md +42 -0
- package/skills/time-series-and-change/skill.json +116 -0
- package/skills/vector-quality/SKILL.md +204 -0
- package/skills/vector-quality/UPSTREAM.md +7 -0
- package/skills/vector-quality/skill.json +82 -0
- package/skills/verification/SKILL.md +120 -0
- package/skills/verification/UPSTREAM.md +31 -0
- package/skills/verification/skill.json +67 -0
- package/skills/writing-plans/SKILL.md +171 -0
- package/skills/writing-plans/UPSTREAM.md +23 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/skills/writing-plans/skill.json +80 -0
- package/sources/SOURCES.md +374 -0
- package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
- package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
- package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
- package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
- package/third_party/superpowers/LICENSE +21 -0
- package/third_party/superpowers/NOTICE.md +17 -0
- package/third_party/timescale-pg-aiguide/LICENSE +176 -0
- package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
# Multi-Language Geospatial Programming
|
|
2
|
+
|
|
3
|
+
Geospatial programming across 8 languages: R, Julia, JavaScript, C++, Java, Go, Rust, and Python.
|
|
4
|
+
|
|
5
|
+
## R Geospatial
|
|
6
|
+
|
|
7
|
+
### sf (Simple Features)
|
|
8
|
+
|
|
9
|
+
```r
|
|
10
|
+
library(sf)
|
|
11
|
+
library(dplyr)
|
|
12
|
+
library(ggplot2)
|
|
13
|
+
|
|
14
|
+
# Read spatial data
|
|
15
|
+
roads <- st_read("roads.shp")
|
|
16
|
+
zones <- st_read("zones.geojson")
|
|
17
|
+
|
|
18
|
+
# Basic operations
|
|
19
|
+
st_crs(roads) # Check CRS
|
|
20
|
+
roads_utm <- st_transform(roads, 32610) # Reproject
|
|
21
|
+
|
|
22
|
+
# Geometric operations
|
|
23
|
+
roads_buffer <- st_buffer(roads, dist = 100) # Buffer
|
|
24
|
+
roads_simplify <- st_simplify(roads, tol = 0.0001) # Simplify
|
|
25
|
+
roads_centroid <- st_centroid(roads) # Centroid
|
|
26
|
+
|
|
27
|
+
# Spatial joins
|
|
28
|
+
joined <- st_join(roads, zones, join = st_intersects)
|
|
29
|
+
|
|
30
|
+
# Overlay
|
|
31
|
+
intersection <- st_intersection(roads, zones)
|
|
32
|
+
|
|
33
|
+
# Plot
|
|
34
|
+
ggplot() +
|
|
35
|
+
geom_sf(data = zones, fill = NA) +
|
|
36
|
+
geom_sf(data = roads, color = "blue") +
|
|
37
|
+
theme_minimal()
|
|
38
|
+
|
|
39
|
+
# Calculate area
|
|
40
|
+
zones$area <- st_area(zones) # In CRS units
|
|
41
|
+
zones$area_km2 <- st_area(zones) / 1e6 # Convert to km2
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### terra (Raster Processing)
|
|
45
|
+
|
|
46
|
+
```r
|
|
47
|
+
library(terra)
|
|
48
|
+
|
|
49
|
+
# Load raster
|
|
50
|
+
r <- rast("elevation.tif")
|
|
51
|
+
|
|
52
|
+
# Basic info
|
|
53
|
+
r
|
|
54
|
+
ext(r) # Extent
|
|
55
|
+
crs(r) # CRS
|
|
56
|
+
res(r) # Resolution
|
|
57
|
+
|
|
58
|
+
# Raster calculations
|
|
59
|
+
slope <- terrain(r, v = "slope")
|
|
60
|
+
aspect <- terrain(r, v = "aspect")
|
|
61
|
+
|
|
62
|
+
# Multi-raster operations
|
|
63
|
+
ndvi <- (s2[[8]] - s2[[4]]) / (s2[[8]] + s2[[4]])
|
|
64
|
+
|
|
65
|
+
# Focal operations
|
|
66
|
+
focal_mean <- focal(r, w = matrix(1, 3, 3), fun = mean)
|
|
67
|
+
focal_sd <- focal(r, w = matrix(1, 5, 5), fun = sd)
|
|
68
|
+
|
|
69
|
+
# Zonal statistics
|
|
70
|
+
zones <- vect("zones.shp")
|
|
71
|
+
zonal_mean <- zonal(r, zones, fun = mean)
|
|
72
|
+
|
|
73
|
+
# Extract values at points
|
|
74
|
+
points <- vect("points.shp")
|
|
75
|
+
values <- extract(r, points)
|
|
76
|
+
|
|
77
|
+
# Write output
|
|
78
|
+
writeRaster(slope, "slope.tif", overwrite = TRUE)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### R Workflows
|
|
82
|
+
|
|
83
|
+
```r
|
|
84
|
+
# Complete land cover classification
|
|
85
|
+
library(sf)
|
|
86
|
+
library(terra)
|
|
87
|
+
library(randomForest)
|
|
88
|
+
library(caret)
|
|
89
|
+
|
|
90
|
+
# 1. Load data
|
|
91
|
+
training <- st_read("training.shp")
|
|
92
|
+
s2 <- rast("sentinel2.tif")
|
|
93
|
+
|
|
94
|
+
# 2. Extract training data
|
|
95
|
+
training_points <- st_centroid(training)
|
|
96
|
+
values <- extract(s2, training_points)
|
|
97
|
+
|
|
98
|
+
# 3. Combine with labels
|
|
99
|
+
df <- data.frame(values)
|
|
100
|
+
df$class <- as.factor(training$class_id)
|
|
101
|
+
|
|
102
|
+
# 4. Train model
|
|
103
|
+
set.seed(42)
|
|
104
|
+
train_index <- createDataPartition(df$class, p = 0.7, list = FALSE)
|
|
105
|
+
train_data <- df[train_index, ]
|
|
106
|
+
test_data <- df[-train_index, ]
|
|
107
|
+
|
|
108
|
+
rf_model <- randomForest(class ~ ., data = train_data, ntree = 100)
|
|
109
|
+
|
|
110
|
+
# 5. Predict
|
|
111
|
+
predicted <- predict(s2, model = rf_model)
|
|
112
|
+
|
|
113
|
+
# 6. Accuracy
|
|
114
|
+
conf_matrix <- confusionMatrix(predict(rf_model, test_data), test_data$class)
|
|
115
|
+
print(conf_matrix)
|
|
116
|
+
|
|
117
|
+
# 7. Export
|
|
118
|
+
writeRaster(predicted, "classified.tif", overwrite = TRUE)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Julia Geospatial
|
|
122
|
+
|
|
123
|
+
### ArchGDAL.jl
|
|
124
|
+
|
|
125
|
+
```julia
|
|
126
|
+
using ArchGDAL
|
|
127
|
+
using GeoInterface
|
|
128
|
+
|
|
129
|
+
# Register drivers
|
|
130
|
+
ArchGDAL.registerdrivers() do
|
|
131
|
+
# Read shapefile
|
|
132
|
+
data = ArchGDAL.read("countries.shp") do dataset
|
|
133
|
+
layer = dataset[1]
|
|
134
|
+
features = []
|
|
135
|
+
for feature in layer
|
|
136
|
+
geom = ArchGDAL.getgeom(feature)
|
|
137
|
+
push!(features, geom)
|
|
138
|
+
end
|
|
139
|
+
features
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Create geometries
|
|
144
|
+
using GeoInterface
|
|
145
|
+
|
|
146
|
+
point = GeoInterface.Point(-122.4, 37.7)
|
|
147
|
+
polygon = GeoInterface.Polygon([GeoInterface.LinearRing([
|
|
148
|
+
GeoInterface.Point(-122.5, 37.5),
|
|
149
|
+
GeoInterface.Point(-122.3, 37.5),
|
|
150
|
+
GeoInterface.Point(-122.3, 37.8),
|
|
151
|
+
GeoInterface.Point(-122.5, 37.8),
|
|
152
|
+
GeoInterface.Point(-122.5, 37.5)
|
|
153
|
+
])])
|
|
154
|
+
|
|
155
|
+
# Geometric operations
|
|
156
|
+
buffered = GeoInterface.buffer(point, 1000)
|
|
157
|
+
intersection = GeoInterface.intersection(poly1, poly2)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### GeoStats.jl
|
|
161
|
+
|
|
162
|
+
```julia
|
|
163
|
+
using GeoStats
|
|
164
|
+
using GeoStatsBase
|
|
165
|
+
using Variography
|
|
166
|
+
|
|
167
|
+
# Load point data
|
|
168
|
+
data = georef((value = [1.0, 2.0, 3.0],),
|
|
169
|
+
[Point(0.0, 0.0), Point(1.0, 0.0), Point(0.5, 1.0)])
|
|
170
|
+
|
|
171
|
+
# Experimental variogram
|
|
172
|
+
γ = variogram(EmpiricalVariogram, data, :value, maxlag = 1.0)
|
|
173
|
+
|
|
174
|
+
# Fit theoretical variogram
|
|
175
|
+
γfit = fit(EmpiricalVariogram, γ, SphericalVariogram)
|
|
176
|
+
|
|
177
|
+
# Ordinary kriging
|
|
178
|
+
problem = OrdinaryKriging(data, :value, γfit)
|
|
179
|
+
solution = solve(problem)
|
|
180
|
+
|
|
181
|
+
# Simulate
|
|
182
|
+
simulation = SimulationProblem(data, :value, SphericalVariogram, 100)
|
|
183
|
+
result = solve(simulation)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## JavaScript (Node.js & Browser)
|
|
187
|
+
|
|
188
|
+
### Turf.js (Browser/Node)
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
// npm install @turf/turf
|
|
192
|
+
const turf = require('@turf/turf');
|
|
193
|
+
|
|
194
|
+
// Create features
|
|
195
|
+
const pt1 = turf.point([-122.4, 37.7]);
|
|
196
|
+
const pt2 = turf.point([-122.3, 37.8]);
|
|
197
|
+
|
|
198
|
+
// Distance (in kilometers)
|
|
199
|
+
const distance = turf.distance(pt1, pt2, { units: 'kilometers' });
|
|
200
|
+
|
|
201
|
+
// Buffer
|
|
202
|
+
const buffered = turf.buffer(pt1, 5, { units: 'kilometers' });
|
|
203
|
+
|
|
204
|
+
// Bounding box
|
|
205
|
+
const bbox = turf.bbox(buffered);
|
|
206
|
+
|
|
207
|
+
// Along a line
|
|
208
|
+
const line = turf.lineString([[-122.4, 37.7], [-122.3, 37.8]]);
|
|
209
|
+
const along = turf.along(line, 2, { units: 'kilometers' });
|
|
210
|
+
|
|
211
|
+
// Within
|
|
212
|
+
const points = turf.points([
|
|
213
|
+
[-122.4, 37.7],
|
|
214
|
+
[-122.35, 37.75],
|
|
215
|
+
[-122.3, 37.8]
|
|
216
|
+
]);
|
|
217
|
+
const polygon = turf.polygon([[[-122.4, 37.7], [-122.3, 37.7], [-122.3, 37.8], [-122.4, 37.8], [-122.4, 37.7]]]);
|
|
218
|
+
const ptsWithin = turf.pointsWithinPolygon(points, polygon);
|
|
219
|
+
|
|
220
|
+
// Nearest point
|
|
221
|
+
const nearest = turf.nearestPoint(pt1, points);
|
|
222
|
+
|
|
223
|
+
// Area
|
|
224
|
+
const area = turf.area(polygon); // square meters
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Leaflet (Web Mapping)
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
// Initialize map
|
|
232
|
+
const map = L.map('map').setView([37.7, -122.4], 13);
|
|
233
|
+
|
|
234
|
+
// Add tile layer
|
|
235
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
236
|
+
attribution: '© OpenStreetMap contributors'
|
|
237
|
+
}).addTo(map);
|
|
238
|
+
|
|
239
|
+
// Add GeoJSON layer
|
|
240
|
+
fetch('data.geojson')
|
|
241
|
+
.then(response => response.json())
|
|
242
|
+
.then(data => {
|
|
243
|
+
L.geoJSON(data, {
|
|
244
|
+
style: function(feature) {
|
|
245
|
+
return { color: feature.properties.color };
|
|
246
|
+
},
|
|
247
|
+
onEachFeature: function(feature, layer) {
|
|
248
|
+
layer.bindPopup(feature.properties.name);
|
|
249
|
+
}
|
|
250
|
+
}).addTo(map);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Add markers
|
|
254
|
+
const marker = L.marker([37.7, -122.4]).addTo(map);
|
|
255
|
+
marker.bindPopup("Hello!").openPopup();
|
|
256
|
+
|
|
257
|
+
// Draw circles
|
|
258
|
+
const circle = L.circle([37.7, -122.4], {
|
|
259
|
+
color: 'red',
|
|
260
|
+
fillColor: '#f03',
|
|
261
|
+
fillOpacity: 0.5,
|
|
262
|
+
radius: 500
|
|
263
|
+
}).addTo(map);
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## C++ Geospatial
|
|
267
|
+
|
|
268
|
+
### GDAL C++ API
|
|
269
|
+
|
|
270
|
+
```cpp
|
|
271
|
+
#include "gdal_priv.h"
|
|
272
|
+
#include "ogr_api.h"
|
|
273
|
+
#include "ogr_spatialref.h"
|
|
274
|
+
|
|
275
|
+
// Open raster
|
|
276
|
+
GDALDataset *poDataset = (GDALDataset *) GDALOpen("input.tif", GA_ReadOnly);
|
|
277
|
+
|
|
278
|
+
// Get band
|
|
279
|
+
GDALRasterBand *poBand = poDataset->GetRasterBand(1);
|
|
280
|
+
|
|
281
|
+
// Read data
|
|
282
|
+
int nXSize = poBand->GetXSize();
|
|
283
|
+
int nYSize = poBand->GetYSize();
|
|
284
|
+
float *pafScanline = (float *) CPLMalloc(sizeof(float) * nXSize);
|
|
285
|
+
poBand->RasterIO(GF_Read, 0, 0, nXSize, 1,
|
|
286
|
+
pafScanline, nXSize, 1, GDT_Float32, 0, 0);
|
|
287
|
+
|
|
288
|
+
// Vector data
|
|
289
|
+
GDALDataset *poDS = (GDALDataset *) GDALOpenEx("roads.shp",
|
|
290
|
+
GDAL_OF_VECTOR, NULL, NULL, NULL);
|
|
291
|
+
OGRLayer *poLayer = poDS->GetLayer(0);
|
|
292
|
+
|
|
293
|
+
OGRFeature *poFeature;
|
|
294
|
+
poLayer->ResetReading();
|
|
295
|
+
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
|
|
296
|
+
OGRGeometry *poGeometry = poFeature->GetGeometryRef();
|
|
297
|
+
// Process geometry
|
|
298
|
+
OGRFeature::DestroyFeature(poFeature);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
GDALClose(poDS);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Java Geospatial
|
|
305
|
+
|
|
306
|
+
### GeoTools
|
|
307
|
+
|
|
308
|
+
```java
|
|
309
|
+
import org.geotools.data.FileDataStore;
|
|
310
|
+
import org.geotools.data.FileDataStoreFinder;
|
|
311
|
+
import org.geotools.data.simple.SimpleFeatureCollection;
|
|
312
|
+
import org.geotools.data.simple.SimpleFeatureIterator;
|
|
313
|
+
import org.geotools.data.simple.SimpleFeatureSource;
|
|
314
|
+
import org.geotools.geometry.jts.JTS;
|
|
315
|
+
import org.geotools.referencing.CRS;
|
|
316
|
+
import org.opengis.feature.simple.SimpleFeature;
|
|
317
|
+
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
|
318
|
+
|
|
319
|
+
import org.locationtech.jts.geom.Coordinate;
|
|
320
|
+
import org.locationtech.jts.geom.GeometryFactory;
|
|
321
|
+
import org.locationtech.jts.geom.Point;
|
|
322
|
+
|
|
323
|
+
// Load shapefile
|
|
324
|
+
File file = new File("roads.shp");
|
|
325
|
+
FileDataStore store = FileDataStoreFinder.getDataStore(file);
|
|
326
|
+
SimpleFeatureSource featureSource = store.getFeatureSource();
|
|
327
|
+
|
|
328
|
+
// Read features
|
|
329
|
+
SimpleFeatureCollection collection = featureSource.getFeatures();
|
|
330
|
+
try (SimpleFeatureIterator iterator = collection.features()) {
|
|
331
|
+
while (iterator.hasNext()) {
|
|
332
|
+
SimpleFeature feature = iterator.next();
|
|
333
|
+
Geometry geom = (Geometry) feature.getDefaultGeometryProperty().getValue();
|
|
334
|
+
// Process geometry
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Create point
|
|
339
|
+
GeometryFactory gf = new GeometryFactory();
|
|
340
|
+
Point point = gf.createPoint(new Coordinate(-122.4, 37.7));
|
|
341
|
+
|
|
342
|
+
// Reproject
|
|
343
|
+
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
|
|
344
|
+
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:32633");
|
|
345
|
+
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
|
|
346
|
+
Geometry reprojected = JTS.transform(point, transform);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Go Geospatial
|
|
350
|
+
|
|
351
|
+
### Simple Features Go
|
|
352
|
+
|
|
353
|
+
```go
|
|
354
|
+
package main
|
|
355
|
+
|
|
356
|
+
import (
|
|
357
|
+
"fmt"
|
|
358
|
+
"github.com/paulmach/orb"
|
|
359
|
+
"github.com/paulmach/orb/geojson"
|
|
360
|
+
"github.com/paulmach/orb/planar"
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
func main() {
|
|
364
|
+
// Create point
|
|
365
|
+
point := orb.Point{122.4, 37.7}
|
|
366
|
+
|
|
367
|
+
// Create linestring
|
|
368
|
+
line := orb.LineString{
|
|
369
|
+
{122.4, 37.7},
|
|
370
|
+
{122.3, 37.8},
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Create polygon
|
|
374
|
+
polygon := orb.Polygon{
|
|
375
|
+
{{122.4, 37.7}, {122.3, 37.7}, {122.3, 37.8}, {122.4, 37.8}, {122.4, 37.7}},
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// GeoJSON feature
|
|
379
|
+
feature := geojson.NewFeature(polygon)
|
|
380
|
+
feature.Properties["name"] = "Zone 1"
|
|
381
|
+
|
|
382
|
+
// Distance (planar)
|
|
383
|
+
distance := planar.Distance(point, orb.Point{122.3, 37.8})
|
|
384
|
+
|
|
385
|
+
// Area
|
|
386
|
+
area := planar.Area(polygon)
|
|
387
|
+
|
|
388
|
+
fmt.Printf("Distance: %.2f meters\n", distance)
|
|
389
|
+
fmt.Printf("Area: %.2f square meters\n", area)
|
|
390
|
+
}
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
For more code examples across all languages, see [code-examples.md](code-examples.md).
|
|
394
|
+
|
|
395
|
+
## Rust Geospatial
|
|
396
|
+
|
|
397
|
+
### GeoRust (Geographic Rust)
|
|
398
|
+
|
|
399
|
+
The Rust geospatial ecosystem includes crates for geometry operations, projections, and file I/O.
|
|
400
|
+
|
|
401
|
+
\`\`\`rust
|
|
402
|
+
// Cargo.toml dependencies:
|
|
403
|
+
// geo = "0.28"
|
|
404
|
+
// geo-types = "0.7"
|
|
405
|
+
// proj = "0.27"
|
|
406
|
+
// shapefile = "0.5"
|
|
407
|
+
|
|
408
|
+
use geo::{Coord, Point, LineString, Polygon, Geometry};
|
|
409
|
+
use geo::prelude::*;
|
|
410
|
+
use proj::Proj;
|
|
411
|
+
|
|
412
|
+
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
413
|
+
// Create a point
|
|
414
|
+
let point = Point::new(-122.4_f64, 37.7_f64);
|
|
415
|
+
|
|
416
|
+
// Create a linestring
|
|
417
|
+
let linestring = LineString::new(vec![
|
|
418
|
+
Coord { x: -122.4, y: 37.7 },
|
|
419
|
+
Coord { x: -122.3, y: 37.8 },
|
|
420
|
+
Coord { x: -122.2, y: 37.9 },
|
|
421
|
+
]);
|
|
422
|
+
|
|
423
|
+
// Create a polygon
|
|
424
|
+
let polygon = Polygon::new(
|
|
425
|
+
LineString::new(vec![
|
|
426
|
+
Coord { x: -122.4, y: 37.7 },
|
|
427
|
+
Coord { x: -122.3, y: 37.7 },
|
|
428
|
+
Coord { x: -122.3, y: 37.8 },
|
|
429
|
+
Coord { x: -122.4, y: 37.8 },
|
|
430
|
+
Coord { x: -2.4, y: 37.7 }, // Close the ring
|
|
431
|
+
]),
|
|
432
|
+
vec![], // No interior rings
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
// Geometric operations
|
|
436
|
+
let buffered = polygon.buffer(1000.0); // Buffer in CRS units
|
|
437
|
+
let centroid = polygon.centroid();
|
|
438
|
+
let convex_hull = polygon.convex_hull();
|
|
439
|
+
let simplified = polygon.simplify(&1.0); // Tolerance
|
|
440
|
+
|
|
441
|
+
// Spatial relationships
|
|
442
|
+
let point_within = point.within(&polygon);
|
|
443
|
+
let line_intersects = linestring.intersects(&polygon);
|
|
444
|
+
|
|
445
|
+
// Coordinate transformation
|
|
446
|
+
let from = "EPSG:4326";
|
|
447
|
+
let to = "EPSG:32610";
|
|
448
|
+
let proj = Proj::new_known_crs(from, to, None)?;
|
|
449
|
+
let transformed = proj.convert(point)?;
|
|
450
|
+
|
|
451
|
+
println!("Point: {:?}", point);
|
|
452
|
+
println!("Within polygon: {}", point_within);
|
|
453
|
+
|
|
454
|
+
Ok(())
|
|
455
|
+
}
|
|
456
|
+
\`\`\`
|