dingdongdell
dingdongdell

Reputation: 59

Error when importing GeoJson into BigQuery

I'm trying to load GeoJson data [1] into BigQuery via Cloud Shell but I'm getting the following error:

Failed to parse JSON: Top-level GeoJson 'type' member should have value 'Feature', but was 'FeatureCollection'.; ParsedString returned false; Could not parse value; Parser terminated before end of string

It feels like the GeoJson file is not formatted properly for BQ but I have no idea if that's true or how to fix it.

[1] https://github.com/tonywr71/GeoJson-Data/blob/master/australian-suburbs.geojson

Upvotes: 1

Views: 583

Answers (2)

Anjela B
Anjela B

Reputation: 1201

Expounding on @scespinoza's answer, I was able to convert to new-line delimited GeoJSON and load it to Bigquery with the following steps:

  1. geojson2ndjson geodata.txt > geodata_converted.txt

  2. Using this command, I encountered an error: enter image description here

    But was able to create a workaround by splitting the data into 2 tables, applying the same command.

Loaded table in Bigquery:

enter image description here

enter image description here

Upvotes: 2

scespinoza
scespinoza

Reputation: 396

Your file is in standard GeoJSON format, but BigQuery only accepts new-line delimited GeoJSON files and individual GeoJSON objects (see documentation: https://cloud.google.com/bigquery/docs/geospatial-data#geojson-files). So, you should first convert the dataset to the appropiated format. Here is a good and simple explanation on how it works: https://stevage.github.io/ndgeojson/.

Upvotes: 0

Related Questions