Using remove_attr to remove geom from csv output

I am trying to use remove_attr to remove the geom from my data before saving to csv but I am getting an error

analysis
-> select({remove_attr(*, {exposure.geom: ''}).*})
-> save(name: 'output', format: 'csv')
  - Problems found with 'model' identified model
    - Got 'geom' on line 35 (column 37), wanted one of [QUOTED_IDENTIFIER, IDENTIFIER]

Thanks

Hi John

remove_attr can only remove child elements but it looks like you want to remove a grandchild attribute.

so would want to change to select({*, exposure: remove_attr(exposure, {geom: ''})})

Glenn

1 Like

Thanks Glenn, came across the same problem again and this answer works perfectly.

Hi,

I’ve tried both approaches for my project but I am getting error messages either way:

event_impact_table
 -> select({*}) as "report_event-impact"
 -> select({remove_attr(*, {exposure.geom: ''}).*})

leads to

  - Got 'geom' on line 20 (column 38), wanted one of [IDENTIFIER, QUOTED_IDENTIFIER]

as expected.

But

event_impact_table
 -> select({*}) as "report_event-impact"
 -> select({*, exposure: remove_attr(exposure, {geom: ''})})

leads to

Failed to validate model for execution
  - Failed to validate `select` step on line 19 for execution
    - Failed to validate expression '{*, exposure: remove_attr(exposure, {geom: ''})}' against input type {exposedRatioThreshold=>Floating, floorHeight=>Floating, exposure=>{geom=>MultiPolygon[crs=EPSG:2193], OBJECTID=>Integer, ...}
      - Could not find function with id remove_attr

Any ideas what’s going on here?

Hi Luisa

The remove_attr function is part of the beta plugin which I don’t think you have enabled. You can check by running riskscape --versionand checking for an beta entry. The beta plugin link has instructions for how to enable it.

Glenn

Sweet, yup, that solved the issue and explains why the function could not be found! Thanks, Glenn!