This pull request introduces a new API endpoint (/api/embeddings) to fetch AlphaEarth satellite embeddings from Google Cloud Storage. This enables powerful geospatial analysis by providing 64-dimensional embedding vectors for any given location and year.
- New API Route: Created
/app/api/embeddings/route.tsto handle embedding requests. - GCP Integration: Uses the
@google-cloud/storagelibrary to securely access the "requester pays" GCS bucket. - Efficient Data Fetching: Leverages Cloud Optimized GeoTIFFs (COGs) and the
geotifflibrary to perform range requests, fetching only the specific pixels needed (~500 bytes per request). - Accurate Coordinate Transformation: Uses
proj4for precise WGS84 to UTM coordinate conversion. - Setup Script: Added
download_index.jsto download the requiredaef_index.csvfile. - Configuration: Uses environment variables for GCP configuration (
.env.local). An example file (.env.embeddings.example) is provided. - Documentation: Added a comprehensive setup guide at
docs/ALPHAEARTH_SETUP.md. - Dependencies: Added
@google-cloud/storage,csv-parse,geotiff, andproj4topackage.json. - Gitignore: Updated
.gitignoreto exclude sensitive credentials and the large index file.
-
Install dependencies:
bun install
-
Configure environment variables:
- Copy
.env.embeddings.exampleto.env.local. - Fill in your
GCP_PROJECT_IDandGCP_CREDENTIALS_PATH.
- Copy
-
Download the index file:
node download_index.js
-
Run the development server:
bun run dev
-
Test the API:
curl "http://localhost:3000/api/embeddings?lat=40.7128&lon=-74.0060&year=2023"
- Cost-Effective: Minimizes GCS egress costs by fetching only required pixels.
- Secure: Uses service account credentials and signed URLs.
- Accurate: Precise coordinate transformations with
proj4. - Well-Documented: Includes a detailed setup guide and code comments.
- Production-Ready: Supports environment variables for configuration.
- Review the implementation and documentation.
- Merge the pull request.
- Consider implementing a caching layer for frequently requested embeddings to further optimize performance and cost.
This implementation provides a robust and scalable foundation for integrating powerful geospatial AI capabilities into the QCX platform.