JuliaGeo / LibGEOS.jl

Julia package for manipulation and analysis of planar geometric objects
MIT License
72 stars 23 forks source link

LibGEOS.create{Point,LineString} still return Ptr{Nothing} #167

Open mattwigway opened 1 year ago

mattwigway commented 1 year ago

In #149 and v0.8.0, LibGEOS geometry operations now work on wrapped geometries. However, the create... functions still return a bare GEOS pointer:

julia> using LibGEOS

julia> LibGEOS.createLineString([[1.1, 2.2], [3.3, 4.4]])
Ptr{Nothing} @0x0000...

julia> LibGEOS.createPoint([[1.1, 2.2]])
Ptr{Nothing} @0x0000....

This makes previously-working code like this stop working with a MethodError:

  MethodError: no method matching geointerface_geomtype(::Nothing)
  Closest candidates are:
    geointerface_geomtype(!Matched::GeoInterface.PointTrait) at ~/.julia/packages/LibGEOS/oez93/src/geo_interface.jl:3
    geointerface_geomtype(!Matched::GeoInterface.MultiPointTrait) at ~/.julia/packages/LibGEOS/oez93/src/geo_interface.jl:4
    geointerface_geomtype(!Matched::GeoInterface.LineStringTrait) at ~/.julia/packages/LibGEOS/oez93/src/geo_interface.jl:5

The PR description for #149 mentions that this error can occur, but implies that removing .ptr should solve the problem. However, in the code linked above, there is no use of .ptr. Switching to use LibGEOS.{Point,LineString} instead of LibGEOS.create{Point,LineString} solves the problem. I'm not sure if this is a bug in LibGEOS.jl or if the create... functions are internal, but as far as I can tell the documentation doesn't say not to use them.

jw3126 commented 1 year ago

I think these are internal. Try

julia> LibGEOS.LineString([[1.1, 2.2], [3.3, 4.4]])
LINESTRING (1.1 2.2, 3.3 4.4)

julia> LibGEOS.Point([1.1, 2.2])
POINT (1.1 2.2)
evetion commented 1 year ago

Might be good to namespace the C API, so there is a better distinction between the public and private methods.