I have some issues with this script (different package versions ??)
countries = GeoDataFrames.read("adm_boundaries/geoBoundariesCGAZ_ADM0.shp")
countries = reproject(countries, EPSG(4326), EPSG(6933))
This returns me an error ERROR: GDALError (CE_Failure, code 1): PROJ: cea: Invalid latitude
Strange enough, it works if I apply it in a loop:
countries = GeoDataFrames.read("adm_boundaries/geoBoundariesCGAZ_ADM0.shp")
countries.geometry = [reproject(countries[i,"geometry"], EPSG(4326), EPSG(6933)) for i in 1:size(countries,1)]
For the data file, I have the issue that reproject leaves the Geometry field as a (unchanged) text field, likely related to the fact that I have the wkt field with a different name. I solved similarly with a loop and using ArcGDAL.
import ArchGDAL
polygons = GeoDataFrames.read("test.csv")
polygons.geometry = [reproject(ArchGDAL.fromWKT(polygons[i,"Geometry"]), EPSG(4326), EPSG(6933)) for i in 1:size(polygons,1)]
So now I have both countries and polygons geometries as vector of reprojected polygons Vector{GeoInterface.Wrappers.WrapperGeometry{false, false, T, EPSG{1}} where T}
Still, the intersects call fail with error:
julia> polygons.countries_area_km2 = map(polygons.geometry) do geom
# Find intersecting countries (faster than calculating intersection)
icountries = countries.geometry[GI.intersects.(countries.geometry, (geom,))]
# For intersecting countries, calculate the actual intersection
intersections = GI.intersection.(icountries, (geom,))
sum(GI.area.(intersections) / 1e6) # in km²
end
ERROR: MethodError: no method matching intersects(::PolygonTrait, ::MultiPolygonTrait, ::GeoInterface.Wrappers.Polygon{…}, ::GeoInterface.Wrappers.MultiPolygon{…})
The function `intersects` exists, but no method is defined for this combination of argument types.
Closest candidates are:
intersects(::Any, ::Any)
@ GeoInterface ~/.julia/packages/GeoInterface/X1jn3/src/interface.jl:501
intersects(::Union{CircularStringTrait, CompoundCurveTrait, CurvePolygonTrait, GeometryCollectionTrait, LineStringTrait, LinearRingTrait, MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, MultiSurfaceTrait, PointTrait, PolygonTrait, PolyhedralSurfaceTrait, TINTrait, TriangleTrait}, ::Union{CircularStringTrait, CompoundCurveTrait, CurvePolygonTrait, GeometryCollectionTrait, LineStringTrait, LinearRingTrait, MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, MultiSurfaceTrait, PointTrait, PolygonTrait, PolyhedralSurfaceTrait, TINTrait, TriangleTrait}, ::ArchGDAL.AbstractGeometry, ::ArchGDAL.AbstractGeometry)
@ ArchGDAL ~/.julia/packages/ArchGDAL/N2rQ4/src/geointerface.jl:198
Stacktrace:
[1] intersects(a::GeoInterface.Wrappers.Polygon{…}, b::GeoInterface.Wrappers.MultiPolygon{…})
@ GeoInterface ~/.julia/packages/GeoInterface/X1jn3/src/interface.jl:501
[2] _broadcast_getindex_evalf
@ ./broadcast.jl:678 [inlined]
[3] _broadcast_getindex
@ ./broadcast.jl:651 [inlined]
[4] getindex
@ ./broadcast.jl:610 [inlined]
[5] copy
@ ./broadcast.jl:911 [inlined]
[6] materialize(bc::Base.Broadcast.Broadcasted{…})
@ Base.Broadcast ./broadcast.jl:872
[7] (::var"#23#24")(geom::GeoInterface.Wrappers.MultiPolygon{false, false, Vector{…}, Nothing, EPSG{…}})
@ Main ./REPL[6]:3
[8] iterate
@ ./generator.jl:48 [inlined]
[9] _collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
@ Base ./array.jl:811
[10] collect_similar(cont::Vector{…}, itr::Base.Generator{…})
@ Base ./array.jl:720
[11] map(f::Function, A::Vector{GeoInterface.Wrappers.WrapperGeometry{false, false, T, EPSG{1}} where T})
@ Base ./abstractarray.jl:3371
[12] top-level scope
@ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types.