简体   繁体   English

如何在 BigQuery 中加载 shapefile? 有没有更简单的方法在 BigQuery 中上传多边形数据?

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

I have been trying to load polygon data in BigQuery, but it doesnt seem to work.我一直在尝试在 BigQuery 中加载多边形数据,但它似乎不起作用。

I have tried what Michael Entin explained in his " Loading large spatial features to BigQuery geography " article, but it didnt so well for me.我已经尝试过 Michael Entin 在他的“ 将大型空间特征加载到 BigQuery 地理”一文中解释的内容,但对我来说并没有那么好。

I also have tried what Lak Lakshmanan explained in his " How to load geographic data like shapefiles into BigQuery ", but didnt work either.我也尝试过 Lak Lakshmanan 在他的“ 如何将 shapefile 之类的地理数据加载到 BigQuery中”中解释的内容,但也没有用。

I found it rather confusing having to convert the shapefiles and/or geojsons into a csv to load into BigQuery.我发现必须将 shapefile 和/或 geojson 转换为 csv 以加载到 BigQuery 中相当令人困惑。

Is there any simpler way to upload polygon data in BigQuery?有没有更简单的方法在 BigQuery 中上传多边形数据?

Managed to find a simple solution: :)设法找到一个简单的解决方案::)

# 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

That's it!而已! We are ready to go!我们准备好了!

The --autodetect flag should probably handle the schema, but you can also declare it. --autodetect标志可能应该处理模式,但您也可以声明它。

I hope I have helped.我希望我有所帮助。 This took me quite a while to figure out.我花了很长时间才弄清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM