Skip to content

Commit

Permalink
use Cstring as in GDAL
Browse files Browse the repository at this point in the history
like JuliaGeo/GDAL.jl#47

without this I received errors like:
```
MethodError: no method matching unsafe_convert(::Type{Ptr{Cstring}}, ::Base.RefValue{Ptr{UInt8}})
```
  • Loading branch information
visr committed Aug 1, 2018
1 parent 6e03535 commit 7ce6a4f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ogr/featurelayer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function setattributefilter!(layer::FeatureLayer, query::AbstractString)
end

function clearattributefilter!(layer::FeatureLayer)
result = GDAL.setattributefilter(layer.ptr, Ptr{UInt8}(C_NULL))
result = GDAL.setattributefilter(layer.ptr, C_NULL)
@ogrerr result """OGRErr $result: Failed to clear attribute query."""
layer
end
Expand Down
4 changes: 2 additions & 2 deletions src/ogr/fielddefn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ setnullable!(fielddefn::FieldDefn, nullable::Bool) =

"Get default field value"
function getdefault(fielddefn::FieldDefn)
result = @gdal(OGR_Fld_GetDefault::Ptr{UInt8}, fielddefn.ptr::GDALFieldDefn)
return result == Ptr{UInt8}(C_NULL) ? "" : unsafe_string(result)
result = @gdal(OGR_Fld_GetDefault::Cstring, fielddefn.ptr::GDALFieldDefn)
return result == C_NULL ? "" : unsafe_string(result)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/raster/rasterband.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ end
# nBXSize::Integer,
# nBYSize::Integer,
# eBDataType::GDALDataType,
# papszOptions::Ptr{Ptr{UInt8}}) =
# papszOptions::Ptr{Cstring}) =
# GDALRasterAdviseRead(hRB, nDSXOff, nDSYOff, nDSXSize, nDSYSize, nBXSize,
# nBYSize, eBDataType, papszOptions)::CPLErr

Expand Down
10 changes: 5 additions & 5 deletions src/spatialref.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ importURL(url::AbstractString) = importURL!(newspatialref(), url)

"Convert this SRS into WKT format."
function toWKT(spref::AbstractSpatialRef)
wktptr = Ref{Ptr{UInt8}}()
wktptr = Ref{Cstring}()
result = GDAL.exporttowkt(spref.ptr, wktptr)
@ogrerr result "Failed to convert this SRS into WKT format"
unsafe_string(wktptr[])
Expand All @@ -199,7 +199,7 @@ Convert this SRS into a nicely formatted WKT string for display to a person.
stripped off.
"""
function toWKT(spref::AbstractSpatialRef, simplify::Bool)
wktptr = Ref{Ptr{UInt8}}()
wktptr = Ref{Cstring}()
result = GDAL.exporttoprettywkt(spref.ptr, wktptr, simplify)
@ogrerr result "Failed to convert this SRS into pretty WKT"
unsafe_string(wktptr[])
Expand All @@ -225,15 +225,15 @@ possible. LOCAL_CS coordinate systems are not translatable. An empty string will
be returned along with OGRERR_NONE.
"""
function toXML(spref::AbstractSpatialRef)
xmlptr = Ref{Ptr{UInt8}}()
xmlptr = Ref{Cstring}()
result = GDAL.exporttoxml(spref.ptr, xmlptr, C_NULL)
@ogrerr result "Failed to convert this SRS into XML"
unsafe_string(xmlptr[])
end

"Export coordinate system in Mapinfo style CoordSys format."
function toMICoordSys(spref::AbstractSpatialRef)
ptr = Ref{Ptr{UInt8}}()
ptr = Ref{Cstring}()
result = GDAL.exporttomicoordsys(spref.ptr, ptr)
@ogrerr result "Failed to convert this SRS into XML"
unsafe_string(ptr[])
Expand Down Expand Up @@ -305,7 +305,7 @@ function setattrvalue!(spref::AbstractSpatialRef, path::AbstractString,
end

function setattr!(spref::AbstractSpatialRef, path::AbstractString)
result = GDAL.setattrvalue(spref.ptr, path, Ptr{UInt8}(C_NULL))
result = GDAL.setattrvalue(spref.ptr, path, C_NULL)
@ogrerr result "Failed to set attribute $path"
end

Expand Down
2 changes: 1 addition & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const GDALStyleManager = Ptr{GDAL.OGRStyleMgrH}
const GDALStyleTable = Ptr{GDAL.OGRStyleTableH}
const GDALStyleTool = Ptr{GDAL.OGRStyleToolH}

const StringList = Ptr{Ptr{UInt8}}
const StringList = Ptr{Cstring}

abstract type AbstractGeometry <: GeoInterface.AbstractGeometry end
# needs to have a `ptr::GDALGeometry` attribute
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function unsafe_loadstringlist(pstringlist::Ptr{Cstring})
(pstringlist == C_NULL) && return stringlist
i = 1
item = unsafe_load(pstringlist, i)
while Ptr{UInt8}(item) != C_NULL
while item != C_NULL
push!(stringlist, unsafe_string(item))
i += 1
item = unsafe_load(pstringlist, i)
Expand Down

0 comments on commit 7ce6a4f

Please sign in to comment.