簡體   English   中英

如何在 BigQuery 中加載 shapefile? 有沒有更簡單的方法在 BigQuery 中上傳多邊形數據?

[英]How to load a shapefile in BigQuery? Is there a simpler way to upload polygon data in BigQuery?

我一直在嘗試在 BigQuery 中加載多邊形數據,但它似乎不起作用。

我已經嘗試過 Michael Entin 在他的“ 將大型空間特征加載到 BigQuery 地理”一文中解釋的內容,但對我來說並沒有那么好。

我也嘗試過 Lak Lakshmanan 在他的“ 如何將 shapefile 之類的地理數據加載到 BigQuery中”中解釋的內容,但也沒有用。

我發現必須將 shapefile 和/或 geojson 轉換為 csv 以加載到 BigQuery 中相當令人困惑。

有沒有更簡單的方法在 BigQuery 中上傳多邊形數據?

設法找到一個簡單的解決方案::)

# First of all, I have a shapefile ready to go. The command below will return details about it:
ogrinfo -al -so data/pr_setores_censitarios/shapefile.shp

# Secondly, I convert the shapefile to a geojson:
ogr2ogr -f GeoJSON -t_srs crs:84 data/poligonos_setores_censitarios.geojson data/pr_setores_censitarios

# After, since BigQuery demands json and geojson files to be newline delimited, I modify it a bit:
cat data/poligonos_setores_censitarios.geojson | jq -c ".features[]" > data/poligonos_setores_censitarios_newlinedelimited.geojson

# Then, I upload it to Google Cloud Storage:
gsutil cp data/poligonos_setores_censitarios_newlinedelimited.geojson gs://cloud-storage-bucket01/

# And finally, load it in BigQuery:
bq load --source_format=NEWLINE_DELIMITED_JSON --json_extension=GEOJSON --autodetect mydataset.polygons gs://cloud-storage-bucket01/poligonos_setores_censitarios_newlinedelimited.geojson

而已! 我們准備好了!

--autodetect標志可能應該處理模式,但您也可以聲明它。

我希望我有所幫助。 我花了很長時間才弄清楚。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM