rafaqz / Rasters.jl

Raster manipulation for the Julia language
MIT License
197 stars 34 forks source link

Can't rasterize a `GI.FeatureCollection` #648

Closed asinghvi17 closed 2 months ago

asinghvi17 commented 2 months ago

MWE:

import GeoInterface as GI, GeometryOps as GO
using Rasters

p1 = GI.Polygon([[[-55965.680060140774, -31588.16072168928], [-55956.50771556479, -31478.09258677756], [-31577.548550575284, -6897.015828572996], [-15286.184961223798, -15386.952072224134], [-9074.387601621409, -27468.20712382156], [-8183.4538916097845, -31040.003969070774], [-27011.85123029944, -38229.02388009402], [-54954.72822634951, -32258.9734800704], [-55965.680060140774, -31588.16072168928]]])
p2 = GI.Polygon([[[-80000.0, -80000.0], [-80000.0, 80000.0], [-60000.0, 80000.0], [-50000.0, 40000.0], [-60000.0, -80000.0], [-80000.0, -80000.0]]])

fc = GI.FeatureCollection([GI.Feature(p1, properties = (;val=1)), GI.Feature(p2, properties = (;val=2))])

r1 = rasterize(fc; size = (1000, 1000), fill = :val)

Error:

ERROR: UndefKeywordError: keyword argument `name` not assigned
Stacktrace:
 [1] Rasters.Rasterizer(data::GeoInterface.Wrappers.FeatureCollection{…}; fill::Symbol, geomcolumn::Nothing, kw::@Kwargs{…})
   @ Rasters ~/.julia/dev/Rasters/src/methods/rasterize.jl:171
 [2] rasterize(data::GeoInterface.Wrappers.FeatureCollection{…}; to::Nothing, fill::Symbol, threaded::Bool, kw::@Kwargs{…})
   @ Rasters ~/.julia/dev/Rasters/src/methods/rasterize.jl:452
 [3] top-level scope
   @ ~/.julia/dev/AreaInterpolation/docs/src/tutorials/pycnophylactic.jl:173
Some type information was truncated. Use `show(err)` to see complete types.
rafaqz commented 2 months ago

I'll PR the fix now. But FYI you always need to specify a reducing function to rasterize a collection

r1 = rasterize(sum, fc; size = (1000, 1000), fill = :val)

So we know what to do when two features overlap.