AI summary by TwinMind
Introduction to GIS, Part V: Extract Information from Maps using Spatial Data Points
MIT OpenCourseWare
19m 19s
Introduction and Context
- Tutorial on gap filling process using maps for research databases
- Common issue: databases with empty slots/NAs that need filling with field data
- Map data less accurate than field experiments but good proxy to maximize available data
- Process: transform lat/long coordinates to spatial data points, extract map data
Database Setup and Preparation
- Downloaded real nitrogen uptake database from instructor's GitHub
- Database calculates nitrogen optic global scale based on field data
- Missing data gaps in drivers: temperature, precipitation, soil information
- Data gaps due to incomplete collection or unreported values in original papers
- Large database with multiple columns, some complete, some with NAs
- Focus on latitude (3rd column) and longitude (4th column)
- Subset data excluding NAs in lat/long coordinates using
!is.na()function
Spatial Data Transformation Methods
- Two methods for transforming lat/long to spatial explicit points:
spatial.points()- requires specifying resolutionspatial.points.data.frame()- instructor's preferred method
- Both methods specify lat/long location and database source
- Output types: spatial points data frame vs spatial points
- Plotting verification with world map overlay to ensure correct coordinate mapping
- Warning: mismatched lat/long coordinates create twisted/rotated maps (demonstrated 90° rotation)
Data Extraction Process
- Used temperature map as base for extraction
extract()function: takes map source and spatial points for data extraction- Result: vector with 159 data points matching database rows
- Multiple maps (stack/brick) would generate multiple columns
- Single map produces single column output
Hands-on Exercise Setup
Step 1: Map Download and Processing
- Download 10m resolution average temperature map from WorldClim
- Load all monthly temperature maps into R session
- Create stack of all maps
- Calculate yearly average temperature using
calc(mean) - Verification: reasonable min/max values, successful completion
Step 2: Database Preparation
- Download nitrogen uptake data from GitHub (reuse from previous exercise)
- Create subset with columns 3, 4, 18 (lat, long, mean annual temperature)
- Selected mean annual temperature variable due to existing NAs for gap filling demonstration
Step 3: Spatial Points and Extraction
- Created spatial points using coordinates from subsetted data frame
- Extracted mean annual temperature (MAT) from map using created spatial points
- Added extracted data as new vector to original data frame
- Result: 4-column data frame (originally 3 columns)
Data Validation and Comparison
- Compared field measurements vs map-derived data
- Created linear model: 94% agreement (R² ≈ 0.94)
- Near-perfect regression indicating map data as good proxy
- Regression plot showed strong data agreement
Gap Filling Implementation
Method 1: Direct Replacement
- For loop from 1 to 159 (number of rows)
- Conditional logic: if original value is NA, replace with map data
- If not NA, leave original value unchanged
- Destroys original variable with gaps
Method 2: New Variable Creation
- Same for loop logic but creates new column
- Preserves original variable with gaps for comparison
- New column shows: original values where available, map-derived values for NAs
- Efficient gap filling method using map data
Technical Implementation Details
- Used
if(is.na())conditional statements - For loop structure:
for(i in 1:nrows) - Else statement optional (could be omitted)
- Rerunning code advantage in R for iterative development
- Final result: complete dataset without missing values using hybrid field/map data approach
