简体   繁体   中英

Converting GeoJSON to a raster image using rasterio

I am hoping for advice as to how I can convert GeoJSON geometry into a tif image using rasterio. I have tried a lot of things, but all of them do not rasterize all the shapes found in the GeoJSON (more like 80% of the file is rasterized). How can I ensure all the geometry is rasterized and is of adequate size? Let me know if my question is unclear.

Your problem stems from the fact that when you rasterize a shape, using gdal_translate for example, you must determine the resolution of the raster, and it must be chosen in accordance to the "size" of your feature vectors if you want your raster to retain enough information.

If you do not want to lose too many details in the rasterization process, I guess a good rule of thumb would be to set the resolution to be lower than the typical size of your individual features. For example, if your features look like squares ~1km large, a "good" resolution would be in the 10-100m range. A way to programmatically get the typical size of your features would be to compute their minimum_rotated_rectangle for example: https://shapely.readthedocs.io/en/stable/manual.html#object.minimum_rotated_rectangle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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