[英]How to get GDAL/ogr2ogr to output GeoJSON as feature-per-line instead of a formatted FeatureCollection?
I'm trying to convert some Very Big Shapefiles into GeoJSON so that I can run them through tippecanoe and create a .mbtiles to upload to Mapbox Studio for hosting and styling.我正在尝试将一些非常大的 Shapefile 转换为 GeoJSON,以便我可以通过tippecanoe运行它们并创建一个 .mbtiles 以上传到 Mapbox Studio 以进行托管和样式设置。
I can use ogr2ogr to create my GeoJSON file just fine, however it outputs a FeatureCollection with nice formatting.我可以使用 ogr2ogr 很好地创建我的 GeoJSON 文件,但是它输出的 FeatureCollection 格式很好。 What I want is a .json file with one feature per line, so that I can use the 'Parallel processing of input' feature of Tippecanoe and speed up creation of my .mbtiles.
我想要的是一个每行一个功能的 .json 文件,这样我就可以使用 Tippecanoe 的“并行处理输入”功能并加快我的 .mbtiles 的创建速度。
Question 1: Is there a way to do this simply with ogr2ogr?问题 1:有没有办法简单地用 ogr2ogr 做到这一点? I can't seem to find a relevant option in the GDAL GeoJSON driver docs .
我似乎在GDAL GeoJSON 驱动程序文档中找不到相关选项。
Question 2: Alternatively, could ogr2ogr output a GeoJSON text sequence instead of a FeatureCollection file?问题 2:或者,ogr2ogr 是否可以输出GeoJSON 文本序列而不是 FeatureCollection 文件?
If you make an array of the ids or any other attribute in your Shapefile, you could loop through this list and use the ogr2ogr --where option to export features one by one.如果您在 Shapefile 中创建一个 ids 或任何其他属性的数组,您可以遍历此列表并使用 ogr2ogr --where 选项逐个导出特征。 See also this example https://gis.stackexchange.com/questions/35296/how-to-use-where-sql-in-an-ogr2ogr-loop-in-gdal-ogr-bash#35297
另请参阅此示例https://gis.stackexchange.com/questions/35296/how-to-use-where-sql-in-an-ogr2ogr-loop-in-gdal-ogr-bash#35297
Q1 . Q1 。 Well, you can extract the individual features with the help of a UNIX tool - jq.
好吧,您可以借助 UNIX 工具 - jq 提取各个特征。
jq --compact-output ".features" input_featurecollection.geojson > output_features_only.geojson
This will have each record as a separate geojson feature这会将每条记录作为单独的 geojson 功能
Q2 you can pipe in your input geojson file to this command and echo the output. Q2您可以将输入的 geojson 文件通过管道传输到此命令并回显输出。
您可以按照问题 2 @craigsnyders 中的建议使用ogr2ogr
输出 geojson 序列:
ogr2ogr -f GeoJSONSeq -t_srs EPSG:4326 output.json input.shp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.