Skip to content

As a data user, I want to export results as CSV with extracted spatial columnsΒ #156

Description

@jordanpadams

Checked for duplicates

Yes - I've already checked

πŸ§‘β€πŸ”¬ User Persona(s)

Data User, GIS Analyst, Spreadsheet User, Data Analyst

πŸ’ͺ Motivation

...so that I can easily import PDS data into GIS tools, spreadsheets, and analytics platforms with spatial metadata in dedicated, flattened columns.

πŸ“– Additional Details

Current Behavior:

  • βœ… Can export DataFrame to CSV via df.to_csv()
  • ❌ Spatial fields remain nested (e.g., orex:Spatial.orex:latitude)
  • ❌ No automatic extraction of spatial metadata
  • ❌ Users must manually flatten nested structures

Proposed Solution:
Export with spatial metadata automatically extracted and flattened:

# Basic CSV export with spatial extraction
products.has_target("Mars").observationals().as_csv(
    "mars_data.csv",
    extract_spatial=True,
    spatial_fields={
        "latitude": "orex:Spatial.orex:latitude",
        "longitude": "orex:Spatial.orex:longitude",
        "range_km": "orex:Spatial.orex:target_range"
    }
)

# Auto-detect common spatial field patterns
products.as_csv(
    "data.csv",
    extract_spatial="auto"
)

# Custom column renaming for readability
products.as_csv(
    "data.csv",
    extract_spatial=True,
    column_mapping={
        "pds:Identification_Area.pds:title": "title",
        "pds:Time_Coordinates.pds:start_date_time": "start_date"
    }
)

Example Output:

Without extraction:

lidvid,title,orex:Spatial
urn:...,Mars Image,"{'orex:latitude': 12.5, 'orex:longitude': -45.2}"

With extraction:

lidvid,title,latitude,longitude,range_km
urn:...,Mars Image,12.5,-45.2,5000.0

Implementation Approach:

  1. Add as_csv() method to QueryBuilder
  2. extract_spatial parameter with bool and "auto" support
  3. Auto-detect common spatial field patterns
  4. flatten option for all nested structures
  5. column_mapping for custom renaming
  6. Default friendly names for common PDS fields

Related:


For Internal Dev Team To Complete

Acceptance Criteria

Given a user wants to export spatial data for GIS tools
When I perform products.as_csv("output.csv", extract_spatial=True, spatial_fields={...})
Then I expect a CSV file with spatial metadata in separate, flattened columns

βš™οΈ Engineering Details

To be filled by Engineering Node Team

πŸŽ‰ I&T

To be filled by Engineering Node Team

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status
ToDo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions