Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply does not work on GeometryBasics polygons #133

Closed
tiemvanderdeure opened this issue May 6, 2024 · 4 comments · Fixed by #137
Closed

apply does not work on GeometryBasics polygons #133

tiemvanderdeure opened this issue May 6, 2024 · 4 comments · Fixed by #137
Labels
bug Something isn't working

Comments

@tiemvanderdeure
Copy link
Contributor

tiemvanderdeure commented May 6, 2024

MWE:

import GeometryBasics: Point, Polygon
import GeometryOps
poly = Polygon([Point(0,0), Point(1,1), Point(1,2)])
GeometryOps.flip(poly)

This works on an ArchGDAL.polygon:

import ArchGDAL, GeoInterface
agpoly = GeoInterface.convert(ArchGDAL, poly)
GeometryOps.flip(agpoly)

Stacktrace:

ERROR: MethodError: Cannot `convert` an object of type 
  GeometryBasics.LineString{2, Int64, Point{2, Int64}, Base.ReinterpretArray{GeometryBasics.Line{2, Int64}, 1, Tuple{Point{2, Int64}, Point{2, Int64}}, GeometryBasics.TupleView{Tuple{Point{2, Int64}, Point{2, Int64}}, 2, 1, Vector{Point{2, Int64}}}, false}} to an object of type 
  GeoInterface.Wrappers.LineString

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  GeoInterface.Wrappers.LineString(::Any; kw...)
   @ GeoInterface ~/.julia/packages/GeoInterface/pFMQ1/src/wrappers.jl:167

Stacktrace:
  [1] _apply(f::GeometryOps.var"#190#192", target::TraitTarget{…}, trait::GeoInterface.LineStringTrait, geom::GeometryBasics.LineString{…}; crs::Nothing, calc_extent::GeometryOps._False, threaded::GeometryOps._False)
    @ GeometryOps ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:306
  [2] _apply
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:298 [inlined]
  [3] _apply
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:202 [inlined]
  [4] (::GeometryOps.var"#apply_to_geom#13"{})(i::Int64)
    @ GeometryOps ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:304
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] _collect
    @ ./array.jl:854 [inlined]
  [7] collect_similar(cont::UnitRange{Int64}, itr::Base.Generator{UnitRange{…}, GeometryOps.var"#apply_to_geom#13"{…}})
    @ Base ./array.jl:763
  [8] map
    @ ./abstractarray.jl:3285 [inlined]
  [9] _maptasks(f::GeometryOps.var"#apply_to_geom#13"{}, taskrange::UnitRange{…}, threaded::GeometryOps._False)
    @ GeometryOps ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:622
 [10] #_apply#12
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:305 [inlined]
 [11] _apply
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:298 [inlined]
 [12] _apply(f::GeometryOps.var"#190#192", target::TraitTarget{…}, geom::Polygon{…}; kw::@Kwargs{})
    @ GeometryOps ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:202
 [13] _apply
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:202 [inlined]
 [14] #apply#1
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:198 [inlined]
 [15] apply
    @ ~/.julia/packages/GeometryOps/7TsU0/src/primitives.jl:193 [inlined]
 [16] #flip#188
    @ ~/.julia/packages/GeometryOps/7TsU0/src/transformations/flip.jl:23 [inlined]
 [17] flip(geom::Polygon{2, Int64, Point{…}, GeometryBasics.LineString{…}, Vector{…}})
    @ GeometryOps ~/.julia/packages/GeometryOps/7TsU0/src/transformations/flip.jl:17
 [18] top-level scope
@asinghvi17
Copy link
Member

Huh this looks strange. Probably needs fixes on the GeometryBasics end though...

@asinghvi17
Copy link
Member

@rafaqz any idea why this would cut off the error here? I can verify that this gets to rebuild, and that rebuild works, but I have no clue where it's trying to coerce a GB.LineString to a GI.LineString...

@asinghvi17 asinghvi17 added the bug Something isn't working label May 6, 2024
@rafaqz
Copy link
Member

rafaqz commented May 6, 2024

Ah right the closures kind of obscure where anything happens. I'll take a look.

@rafaqz
Copy link
Member

rafaqz commented May 6, 2024

Its probably because we have custom rebuild for GeometryBasics but that doesn't make sense anymore

function rebuild(trait::GI.AbstractTrait, geom::BasicsGeoms, child_geoms; crs=nothing)
GB.geointerface_geomtype(trait)(child_geoms)
end
function rebuild(trait::GI.AbstractTrait, geom::Union{GB.LineString,GB.MultiPoint}, child_geoms; crs=nothing)
GB.geointerface_geomtype(trait)(GI.convert.(GB.Point, child_geoms))
end
function rebuild(trait::GI.PolygonTrait, geom::GB.Polygon, child_geoms; crs=nothing)
Polygon(child_geoms[1], child_geoms[2:end])
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants