Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a BigQuery table with geoJSON files doesn't work #76

Open
Leprechault opened this issue Oct 11, 2021 · 3 comments
Open

Create a BigQuery table with geoJSON files doesn't work #76

Leprechault opened this issue Oct 11, 2021 · 3 comments

Comments

@Leprechault
Copy link

I'd like to create a BigQuery table with geoJSON files, despite the geoJSON is an accepted format in BQ and sourceFormat specification is coercible to (NEWLINE_DELIMITED_JSON) in the function bqr_upload_data() of the bigQueryR package doesn't work. In my example below the output, error is: Error in UseMethod("bqr_do_upload", upload_data) :

library(sf)
library(geojsonsf)
library(bigQueryR)

# get AOI in shapefile
download.file(
  "https://github.com/Leprechault/trash/raw/main/sel_stands_CMPC.zip",
  zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())

# Open the file
setwd(tempdir())
stands_sel <- st_read("sel_stands_CMPC.shp")
# Reading layer `sel_stands_CMPC' from data source `C:\Users\fores\AppData\Local\Temp\Rtmp6l1bGx\sel_stands_CMPC.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 16 fields
# Geometry type: MULTIPOLYGON
# Dimension:     XY
# Bounding box:  xmin: -52.3284 ymin: -30.43305 xmax: -51.21323 ymax: -30.35118
# Geodetic CRS:  GCS_unknown

# Open as geoJSON
geo <- sf_geojson(stands_sel)
str(geo)
# 'geojson' chr "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"CD_USO_SOL\":2433.0,\"ID_"| __truncated__

projectid <-'[my-project]'
datasetid <-'stands_ROI_2021'
tableid <- 'CF_2021'
bqr_upload_data(projectId = projectid, 
datasetId = datasetid, 
tableId = tableid,
geo, 
#writeDisposition = c("WRITE_TRUNCATE", "WRITE_APPEND", "WRITE_EMPTY"), 
sourceFormat = c("NEWLINE_DELIMITED_JSON"))
Error in UseMethod("bqr_do_upload", upload_data) :
  method not applicable for 'upload_bqr' applied to an object of class "c('geojson', 'json')"

Please, any help for fix it?

@MarkEdmondson1234
Copy link
Collaborator

It needs to be an R list, data.frame or a file saved to disk or GoogleCloudStorage. Can you coerce your geojson object to one of those?

@Leprechault
Copy link
Author

Leprechault commented Oct 12, 2021

Thanks @MarkEdmondson1234 my file is like a JSON ({\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"CD_USO_SOL) and I considering as list.

@MarkEdmondson1234
Copy link
Collaborator

The class of the r object should be a list, eg class(x) should include "list" not "json".

Perhaps jsonlite::fromJSON() will convert it to a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants