MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / detectEdgeCase

Function detectEdgeCase

src/components/CropPlanningSection.tsx:132–167  ·  view source on GitHub ↗
(field: Field, suitabilityData?: any, ndviData?: any, weatherData?: any, landUseData?: any)

Source from the content-addressed store, hash-verified

130
131// Edge case detection for unsuitable regions
132type RegionEdgeCase = "water" | "desert" | "arctic" | "urban" | null;
133
134function detectEdgeCase(field: Field, suitabilityData?: any, ndviData?: any, weatherData?: any, landUseData?: any): { edgeCase: RegionEdgeCase; confidence: number; message: string } | null {
135 const loc = field.location.toLowerCase();
136
137 // Arctic/Antarctic detection
138 const coords = field.coordinates[0];
139 const avgLat = coords.reduce((s, c) => s + c[1], 0) / coords.length;
140 if (Math.abs(avgLat) > 66) {
141 return { edgeCase: "arctic", confidence: 95, message: "This region is in the Arctic/Antarctic zone where agriculture is not feasible. Permafrost and extreme cold make crop cultivation impossible." };
142 }
143
144 // Antarctic keyword detection
145 if (["antarctica", "antarctic", "south pole", "north pole"].some(k => loc.includes(k))) {
146 return { edgeCase: "arctic", confidence: 98, message: "This region is in a polar zone. Agriculture is not viable in these extreme conditions." };
147 }
148
149 // Desert detection - extreme aridity
150 if (suitabilityData?.raw?.annual_rainfall_mm != null && suitabilityData.raw.annual_rainfall_mm < 50) {
151 return { edgeCase: "desert", confidence: 90, message: `Extreme desert: only ${suitabilityData.raw.annual_rainfall_mm}mm annual rainfall. Agriculture requires major irrigation infrastructure.` };
152 }
153 if (["sahara", "empty quarter", "rub al khali", "gobi desert", "atacama", "death valley", "namib desert"].some(k => loc.includes(k))) {
154 return { edgeCase: "desert", confidence: 92, message: "This region is in an extreme desert. Agriculture is not viable without massive irrigation infrastructure." };
155 }
156
157 // Water body detection: use Regional Land Use "Water" percentage, only block at 80%+
158 const waterPct = landUseData?.["Water"] ?? 0;
159 if (waterPct >= 80) {
160 return { edgeCase: "water", confidence: Math.min(99, Math.round(waterPct)), message: `This region is ${waterPct}% water (ocean, lake, or river) based on satellite land use classification. Crop planning is not applicable.` };
161 }
162
163 // Very high elevation (above treeline)
164 if (suitabilityData?.raw?.elevation_m != null && suitabilityData.raw.elevation_m > 5000) {
165 return { edgeCase: "arctic", confidence: 85, message: `Extreme high altitude (${suitabilityData.raw.elevation_m}m). Above the treeline — agriculture is not feasible at this elevation.` };
166 }
167
168 return null;
169}
170

Callers 1

CropPlanningSectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected