Extracting Data from Raster and CSV Files with Rasteric
Extracting Data from Raster Files
Rasteric’s extract()
function allows you to retrieve raster values corresponding to spatial points or vector features. By specifying a vector file (e.g., a shapefile or CSV with coordinates), the function extracts the raster data at those locations, enabling detailed analysis such as sampling or data comparison.
Example: Extracting Data from a Raster File Using a Shapefile
from rasteric import raster
# Extract raster values for vector features (e.g., polygons)
output_csv = raster.extract("example.tif", "vector.shp")
This function outputs the extracted raster values into a CSV file, making it easy to further analyze or integrate the data into your workflow.
Example: Extracting Data from a Raster File Using a CSV File
If your spatial points are stored in a CSV file with latitude and longitude coordinates, Rasteric can extract raster values based on these coordinates as well:
from rasteric import raster
# Extract raster values for points in a CSV file
output_csv = raster.extract("example.tif", "points.csv")
In this example, the CSV file should contain columns for latitude and longitude. Rasteric will sample the raster at those coordinates and save the results to a new CSV file.