Skip to content

Commit d1fd810

Browse files
authored
Merge pull request #2009 from GenericMappingTools/wkt2epsg
Add wkt2epsg and proj2epsg funtions and uncomment some FFT wrapper funs.
2 parents 683d8cc + 6e3bb8b commit d1fd810

5 files changed

Lines changed: 96 additions & 15 deletions

File tree

src/GMT.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export
162162
psimage, psimage!, pslegend, pslegend!, psmask, psmask!, psrose, psrose!, psscale, psscale!, pssolar, pssolar!,
163163
psternary, psternary!, pstext, pstext!, pswiggle, pswiggle!, psxy, psxy!, psxyz, psxyz!, regress, resetGMT, rose,
164164
rose!, sample1d, scatter, scatter!, scatter3, scatter3!, solar, solar!, analemma, enso, keeling,
165-
sunsetrise, spectrum1d, sphdistance, sphinterpolate,
165+
sunsetrise, spectrum1d, fft1d, sphdistance, sphinterpolate,
166166
sphtriangulate, surface, ternary, ternary!, text, text!, text_record, textrepel, annotate, annotate!, trend1d, trend2d, triangulate, gmtsplit,
167167
decorated, vector_attrib, wiggle, wiggle!, xyz2grd, gmtbegin, gmtend, gmthelp, subplot, gmtfig, inset, showfig,
168168
earthtide, gmt2grd, gravfft, gmtgravmag3d, gravmag3d, grdgravmag3d, gravprisms, grdseamount, parkermag, parkergrav, kovesi,
@@ -187,7 +187,7 @@ export
187187
wkbMultiLineString, wkbMultiPolygon, wkbGeometryCollection, wkbPoint25D, wkbLineString25D, wkbPolygon25D, wkbMultiPoint25D,
188188
wkbMultiLineString25D, wkbMultiPolygon25D, wkbGeometryCollection25D, bezier, buffergeo, circgeo, epsg2proj, epsg2wkt,
189189
geod, invgeod, loxodrome, loxodrome_direct, loxodrome_inverse, montage,
190-
geodesic, orthodrome, proj2wkt, setcoords!, setfld!, setcrs!, setsrs!, settimecol!, vecangles, wkt2proj,
190+
geodesic, orthodrome, proj2wkt, setcoords!, setfld!, setcrs!, setsrs!, settimecol!, vecangles, wkt2proj, wkt2epsg, proj2epsg,
191191
inbbox, randgeo, colorzones!, rasterzones!, rasterzones, lelandshade, texture_img, crop, doy2date, date2doy, choropleth, fourcolors,
192192
getdcw, ISOtime2unix, median, mean, quantile, std, nanmean, nanstd, skipnan, zonal_statistics, zonal_stats,
193193
autocor, autocor!, autocov, autocov!, conv, yeardecimal, xcorr, xcov, add2PSfile, append2fig, isoutlier, linearfitxy,
@@ -336,6 +336,7 @@ include("signalcorr.jl")
336336
include("sealand.jl")
337337
include("spatial_funs.jl")
338338
include("spectrum1d.jl")
339+
include("fft1d.jl")
339340
include("sphdistance.jl")
340341
include("sphinterpolate.jl")
341342
include("sphtriangulate.jl")
@@ -420,6 +421,7 @@ using .Laszip
420421
gmtwrite(t, [0.0 0; 1 1])
421422
gmtread(t)
422423
gmtread(tests("burro_cenora.jpg"))
424+
gmtselect(t, R="0/1/0/1")
423425
basemap(R=:d, proj=:guess)
424426
coast(R=:g, proj=:guess, W=(level=1, pen=(2, :green)), savefig=tempname()*".ps")
425427
rm(t)

src/gdal/gdal.jl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,52 @@ OSRImportFromEPSG(a1, a2) = acare(ccall((:OSRImportFromEPSG, libgdal), Cint, (pV
435435
OSRNewSpatialReference(a1) = acare(ccall((:OSRNewSpatialReference, libgdal), pVoid, (Cstring,), a1))
436436
OSRSetPROJSearchPaths(a1) = acare(ccall((:OSRSetPROJSearchPaths, libgdal), Cvoid, (Ptr{Cstring},), a1))
437437

438+
"""
439+
OSRAutoIdentifyEPSG(OGRSpatialReferenceH hSRS) -> OGRErr
440+
441+
Set EPSG authority info if possible.
442+
"""
443+
OSRAutoIdentifyEPSG(a1) = acare(ccall((:OSRAutoIdentifyEPSG, libgdal), Cint, (pVoid,), a1))
444+
445+
"""
446+
OSRGetAuthorityName(OGRSpatialReferenceH hSRS, const char * pszTargetKey) -> const char *
447+
448+
Get the authority name for a node.
449+
"""
450+
function OSRGetAuthorityName(hSRS, pszTargetKey)
451+
acare(ccall((:OSRGetAuthorityName, libgdal), Cstring, (pVoid, Cstring), hSRS, pszTargetKey), false)
452+
end
453+
454+
"""
455+
OSRGetAuthorityCode(OGRSpatialReferenceH hSRS, const char * pszTargetKey) -> const char *
456+
457+
Get the authority code for a node.
458+
"""
459+
function OSRGetAuthorityCode(hSRS, pszTargetKey)
460+
acare(ccall((:OSRGetAuthorityCode, libgdal), Cstring, (pVoid, Cstring), hSRS, pszTargetKey), false)
461+
end
462+
463+
464+
"""
465+
OSRFindMatches(OGRSpatialReferenceH hSRS, char **papszOptions, int *pnEntries,
466+
int **ppanMatchConfidence) -> OGRSpatialReferenceH *
467+
468+
Try to identify a match between the passed SRS and a related SRS in a catalog.
469+
470+
### Parameters
471+
* **hSRS**: SRS to match
472+
* **papszOptions**: NULL terminated list of options or NULL
473+
* **pnEntries**: Output parameter. Number of values in the returned array.
474+
* **ppanMatchConfidence**: Output parameter (or NULL). *ppanMatchConfidence will be allocated to an array of *pnEntries whose values between 0 and 100 indicate the confidence in the match. 100 is the highest confidence level. The array must be freed with CPLFree().
475+
476+
### Returns
477+
an array of SRS that match the passed SRS, or NULL. Must be freed with OSRFreeSRSArray()
478+
"""
479+
function OSRFindMatches(hSRS, papszOptions, pnEntries, ppanMatchConfidence)
480+
acare(ccall((:OSRFindMatches, libgdal), Ptr{pVoid}, (pVoid, Ptr{Cstring}, Ptr{Cint}, Ptr{Ptr{Cint}}), hSRS, papszOptions, pnEntries, ppanMatchConfidence))
481+
end
482+
483+
438484
function OSRSetAxisMappingStrategy(hSRS, strategy)
439485
#(Gdal.GDALVERSION[] < v"3.0.0") && return # This breakes precompile if called from one PrecompileTools call
440486
acare(ccall((:OSRSetAxisMappingStrategy, libgdal), Cvoid, (pVoid, UInt32), hSRS, strategy))
@@ -1886,6 +1932,15 @@ end
18861932
return unsafe_string(projptr[])
18871933
end
18881934

1935+
function toEPSG(spref::AbstractSpatialRef)::Int
1936+
(spref.ptr == C_NULL) && return 0
1937+
(OSRAutoIdentifyEPSG(spref.ptr) != OGRERR_NONE) && error("Failed to identify EPSG code for this SRS")
1938+
result = OSRGetAuthorityCode(spref.ptr, C_NULL)
1939+
(result === "") && error("Failed to get EPSG code")
1940+
return parse(Int, result)
1941+
end
1942+
1943+
18891944
toKML(geom::AbstractGeometry, altitudemode=C_NULL) = OGR_G_ExportToKML(geom.ptr, altitudemode)
18901945

18911946
function importWKT!(spref::AbstractSpatialRef, wktstr::AbstractString)
@@ -2653,7 +2708,7 @@ end
26532708
# ---------------------------------
26542709

26552710
export
2656-
bwareaopen, getband, getdriver, getlayer, getproj, getgeom, getgeotransform, toPROJ4, toWKT, importPROJ4,
2711+
bwareaopen, getband, getdriver, getlayer, getproj, getgeom, getgeotransform, toPROJ4, toWKT, toEPSG, importPROJ4,
26572712
importWKT, importEPSG, gdalinfo, gdalwarp, gdaldem, gdaltranslate, gdalgrid, ogr2ogr, gdalvectortranslate,
26582713
gdalrasterize, gdalbuildvrt, readraster, setgeotransform!, setproj!, destroy, arcellipse, arccircle,
26592714
delaunay, dither, buffer, centroid, intersection, intersects, polyunion, fromWKT, fillnodata!, fillnodata,

src/laszip/lazread.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function lazread(fname::String, out::String, type::DataType, class::Int, startst
107107
end
108108
xyz = zeros(fType, totalNP, n_col)
109109
(occursin('i', argout)) && (intens = zeros(UInt16, totalNP, 1))
110-
(occursin('c', argout)) && (class = zeros(Int8, totalNP, 1))
110+
(occursin('c', argout)) && (_class = zeros(UInt8, totalNP, 1))
111111
(occursin('n', argout)) && (n_ret = zeros(Int8, totalNP, 1))
112112
if (n_upper > 0)
113113
RGB = zeros(UInt16, totalNP, n_upper)
@@ -179,9 +179,9 @@ function lazread(fname::String, out::String, type::DataType, class::Int, startst
179179
xyz[k,1] = pt.X; xyz[k,2] = pt.Y; xyz[k,3] = pt.Z
180180
intens[k] = pt.intensity
181181
if (header.point_data_format > 5)
182-
class[k] = (pt.extended_classification != 0) ? pt.extended_classification : pt.classification
182+
_class[k] = (pt.extended_classification != 0) ? pt.extended_classification : pt.classification
183183
else
184-
class[k] = pt.classification
184+
_class[k] = pt.classification
185185
end
186186
end
187187
elseif (argout == "xyzc")
@@ -190,9 +190,9 @@ function lazread(fname::String, out::String, type::DataType, class::Int, startst
190190
pt = unsafe_load(point[])
191191
xyz[k,1] = pt.X; xyz[k,2] = pt.Y; xyz[k,3] = pt.Z
192192
if (header.point_data_format > 5)
193-
class[k] = (pt.extended_classification != 0) ? pt.extended_classification : pt.classification
193+
_class[k] = (pt.extended_classification != 0) ? pt.extended_classification : pt.classification
194194
else
195-
class[k] = pt.classification
195+
_class[k] = pt.classification
196196
end
197197
end
198198
elseif ((startswith(argout, "xyz") || startswith(argout, "xy")) && occursin(r"[RGBI]", argout))
@@ -249,7 +249,7 @@ function lazread(fname::String, out::String, type::DataType, class::Int, startst
249249
elseif (argout == "xyzi")
250250
lasout_types(dsv = [mat2ds(xyz), mat2ds(intens)])
251251
elseif (argout == "xyzc")
252-
lasout_types(dsv = [mat2ds(xyz), mat2ds(class)])
252+
lasout_types(dsv = [mat2ds(xyz), mat2ds(_class)])
253253
elseif (argout == "xyzti")
254254
lasout_types(dsv = [mat2ds(xyz), mat2ds(intens)])
255255
elseif ((startswith(argout, "xyz") || startswith(argout, "xy")) && occursin(r"[RGBI]", argout))

src/libgmt.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ function GMT_Parse_Common(API::Ptr{Cvoid}, given_options::Ptr{UInt8}, options::P
190190
ccall( (:GMT_Parse_Common, libgmt), Cint, (Ptr{Cvoid}, Ptr{UInt8}, Ptr{GMT_OPTION}), API, given_options, options)
191191
end
192192
193+
function GMT_Report(API, vlevel::Integer, txt)
194+
ccall((:GMT_Report, libgmt), Cvoid, (Cstring, Cint, Ptr{UInt8}), API, vlevel, txt)
195+
end
196+
=#
197+
193198
function GMT_FFT_Option(API::Ptr{Cvoid}, option::UInt8, dim::UInt32, string::Ptr{UInt8})
194199
ccall( (:GMT_FFT_Option, libgmt), UInt32, (Ptr{Cvoid}, UInt8, UInt32, Ptr{UInt8}), API, option, dim, string)
195200
end
@@ -208,17 +213,13 @@ end
208213
function GMT_FFT_Destroy(API::Ptr{Cvoid}, K::Ptr{Cvoid})
209214
ccall( (:GMT_FFT_Destroy, libgmt), Cint, (Ptr{Cvoid}, Ptr{Cvoid}), API, K)
210215
end
211-
function GMT_FFT_1D(API::Ptr{Cvoid}, data::Ptr{Cfloat}, n::UInt16, direction::Cint, mode::UInt32)
212-
ccall( (:GMT_FFT_1D, libgmt), Cint, (Ptr{Cvoid}, Ptr{Cfloat}, UInt16, Cint, UInt32), API, data, n, direction, mode)
216+
function GMT_FFT_1D(API::Ptr{Cvoid}, data::Ptr{Cfloat}, n::Integer, direction::Cint, mode::UInt32)
217+
ccall( (:GMT_FFT_1D, libgmt), Cint, (Ptr{Cvoid}, Ptr{Cfloat}, UInt64, Cint, UInt32), API, data, UInt64(n), direction, mode)
213218
end
214219
function GMT_FFT_2D(API::Ptr{Cvoid}, data::Ptr{Cfloat}, nx::UInt32, ny::UInt32, direction::Cint, mode::UInt32)
215220
ccall( (:GMT_FFT_2D, libgmt), Cint, (Ptr{Cvoid}, Ptr{Cfloat}, UInt32, UInt32, Cint, UInt32), API, data, nx, ny, direction, mode)
216221
end
217222

218-
function GMT_Report(API, vlevel::Integer, txt)
219-
ccall((:GMT_Report, libgmt), Cvoid, (Cstring, Cint, Ptr{UInt8}), API, vlevel, txt)
220-
end =#
221-
222223
function GMT_Encode_Options(V_API::Ptr{Cvoid}, _module, n_argin::Int, head::Ref{Ptr{GMT_OPTION}}, n)
223224
ccall((:GMT_Encode_Options, libgmt), Ptr{GMT_RESOURCE}, (Cstring, Ptr{UInt8}, Int32, Ref{Ptr{GMT_OPTION}},
224225
Ptr{UInt32}), V_API, _module, n_argin, head, n)

src/proj_utils.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ function proj_ellipsoid_get_parameters(ellipsoid::Ptr{Cvoid}=NULL, proj_ptr::Ptr
792792
semi_major[], inv_flattening[], semi_minor[]
793793
end
794794

795+
# -----------------------------------------------------------------------------------------
795796
"""
796797
proj2wkt(proj4_str::String, pretty::Bool=false)
797798
@@ -802,20 +803,42 @@ function proj2wkt(proj4_str::String; pretty::Bool=false)
802803
toWKT(importPROJ4(proj4_str), pretty)
803804
end
804805

806+
# -----------------------------------------------------------------------------------------
807+
"""
808+
proj2epsg(proj4_str::String)
809+
810+
Convert a PROJ4 string into the corresponding EPSG code (if it exists).
811+
"""
812+
function proj2epsg(proj4_str::String)
813+
!startswith(proj4_str, "+proj=") && error("$(proj4_str) is not a valid proj4 string")
814+
toEPSG(importWKT(proj2wkt(proj4_str)))
815+
end
816+
817+
# -----------------------------------------------------------------------------------------
818+
"""
819+
wkt2epsg(wkt_str::String)
820+
821+
Convert a WKT SRS string into the corresponding EPSG code (if it exists).
822+
"""
823+
wkt2epsg(wkt_str::String) = toEPSG(importWKT(wkt_str))
824+
825+
# -----------------------------------------------------------------------------------------
805826
"""
806827
wkt2proj(wkt_str::String)
807828
808829
Convert a WKT SRS string into the PROJ4 form.
809830
"""
810831
wkt2proj(wkt_str::String) = toPROJ4(importWKT(wkt_str))
811832

833+
# -----------------------------------------------------------------------------------------
812834
"""
813835
epsg2proj(code::Integer)
814836
815837
Convert a EPSG code into the PROJ4 form.
816838
"""
817839
epsg2proj(code::Integer) = toPROJ4(importEPSG(code))
818840

841+
# -----------------------------------------------------------------------------------------
819842
"""
820843
epsg2wkt(code::Integer, pretty::Bool=false)
821844

0 commit comments

Comments
 (0)