DOI-USGS / meddle

Tools for metadata creation and data releases
Other
0 stars 10 forks source link

Cannot extract spatial metadata with newer spatial package versions #60

Closed jzwart closed 3 years ago

jzwart commented 3 years ago

This issue came up when trying to build a simple data release pipeline - see here. @jread-usgs and I think it's due to the difference in our spatial packages used. Jordan is using

library(sf) 
Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0

with sf_0.9-6 and I'm using

> library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1

also with sf_0.9-6 Jordan can extract spatial metadata with meddle::extract_feature() but I get the following error:

Error in sp::CRS(SRS_string = from$wkt) : 
  no arguments in initialization list

Might be something with the way the updated packages deal with CRS. Jordan's st_crs of an example shapefile:

sf::st_crs(remake::fetch('sf_spatial_data')) 
Coordinate Reference System:   
User input: 4326   
wkt: GEOGCS["WGS 84",     DATUM["WGS_1984",         SPHEROID["WGS 84",6378137,298.257223563,             AUTHORITY["EPSG","7030"]],         AUTHORITY["EPSG","6326"]],     PRIMEM["Greenwich",0,         AUTHORITY["EPSG","8901"]],     UNIT["degree",0.0174532925199433,         AUTHORITY["EPSG","9122"]],     AUTHORITY["EPSG","4326"]]

and for the same shapefile I get:

> st_crs(remake::fetch('sf_spatial_data'))
Coordinate Reference System:
  User input: WGS 84 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["latitude",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["longitude",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
jordansread commented 3 years ago

I think Jake's issue is related to this

jordansread commented 3 years ago

@jzwart can you try installing from the sf_overhaul branch and see if that works for you? install_github('read-usgs/meddle@sf_overhaul') should work I think.

jzwart commented 3 years ago

worked!

> scmake()
Starting build at 2020-11-18 09:07:02
<  MAKE > all
[    OK ] sbid
[    OK ] sf_spatial_data
[ BUILD ] spatial_metadata     |  spatial_metadata <- extract_feature(sf_spatial_data)
[  READ ]                      |  # loading packages
although coordinates are longitude/latitude, st_intersects assumes that they are planar
[    OK ] out_data/cars.csv
[    OK ] out_data/spatial.zip
[    OK ] sb_data
[ BUILD ] sb_xml               |  sb_xml <- sb_render_post_xml(sbid, "in_text/text_data_release.yml", spatial_metadata, xml_file = "out_xml/fgdc_metadata.xml")
[ ----- ] all
Finished build at 2020-11-18 09:07:11
Build completed in 0.15 minutes

> remake::fetch('spatial_metadata')
$wbbox
[1] -106

$ebbox
[1] -88.5

$nbbox
[1] 44

$sbbox
[1] 31.4

$`feature-ref`
[1] "Vector"

$`feature-type`
[1] "G-polygon"

$`feature-count`
[1] 2

$states
$states[[1]]
$states[[1]]$`state-name`
[1] "Illinois"

$states[[1]]$`state-abbr`
[1] "IL"

$states[[2]]
$states[[2]]$`state-name`
[1] "New Mexico"

$states[[2]]$`state-abbr`
[1] "NM"

$states[[3]]
$states[[3]]$`state-name`
[1] "Texas"

$states[[3]]$`state-abbr`
[1] "TX"

$states[[4]]
$states[[4]]$`state-name`
[1] "Wisconsin"

$states[[4]]$`state-abbr`
[1] "WI"

fyi your github is jread-usgs (you have just read-usgs above)

jordansread commented 3 years ago

nice!