diff --git a/src/gdal_extensions.jl b/src/gdal_extensions.jl index 5ff3938f0..3ff679167 100644 --- a/src/gdal_extensions.jl +++ b/src/gdal_extensions.jl @@ -72,7 +72,7 @@ end centroid(geom; gdataset=false) ### Parameters -* `geom`: the geometry. This can either be a GDAL AbstractGeometry or a GMTdataset (or vector of it), or a Matrix +* `geom`: the geometry. This can either be a GDAL AbstractGeometry or a GMTdataset (or vector of them), or a Matrix * `gdataset`: Returns a GDAL IGeometry even when input is a GMTdataset or Matrix Compute the geometry centroid. @@ -544,9 +544,23 @@ function helper_geoms_run_fun(f::Function, D1, D2, retds::Bool=true; gdataset=fa return (retds) ? gd2gmt(ig) : ig end function helper_geoms_run_fun(f::Function, D, retds::Bool=true; gdataset=false) + (gdataset) && (retds = false) + if (isa(D, Vector{<:GMTdataset}) && (f == centroid)) + # Don't know if due to bad implementation or it's the way it is, the centroid function only Computes + # that of first polygon, so we have to loop over D[k]. Restrictred so far to the centroid function. + mat = Array{Float64,2}(undef, length(D), 2) + for k = 1:GMT.numel(D) + geom = helper_1geom(D[k]) + ig = f(geom) + mat[k,1], mat[k,2] = Gdal.getx(ig, 0), Gdal.gety(ig, 0) + end + Dc = mat2ds(mat, geom=1, proj4=D[1].proj4, wkt=D[1].wkt, epsg=D[1].epsg) + !isempty(D[1].colnames) && (Dc.colnames = D[1].colnames[1:2]) + Dc.comment = ["Centroids"] + return (retds) ? Dc : gmt2gd(Dc) + end geom = helper_1geom(D) ig = f(geom) - (gdataset) && (retds = false) return (retds) ? gd2gmt(ig) : ig end function helper_geoms_run_fun(f::Function, D, ratio::Float64, holes::Bool=true; gdataset=false) diff --git a/src/gmtspatial.jl b/src/gmtspatial.jl index 1c56ffb65..ea2c46de6 100644 --- a/src/gmtspatial.jl +++ b/src/gmtspatial.jl @@ -33,7 +33,7 @@ Parameters Determine if one (or all, with +a) points of each feature in the input data are inside any of the polygons given in the pfile. -- **Q** | **area** or **length** :: [Type => Str] `Arg = [[-|+]unit][+cmin[/max]][+h][+l][+p][+s[a|d]]` +- **Q** | **centroid** or **area** or **length** :: [Type => Str] `Arg = [[unit][+cmin[/max]][+h][+l][+p][+s[a|d]]` Measure the area of all polygons or length of line segments. - $(GMT._opt_R) @@ -67,7 +67,7 @@ function gmtspatial(cmd0::String="", arg1=nothing, arg2 = nothing; kwargs...) cmd, = parse_common_opts(d, "", [:R :V_params :b :d :e :f :g :h :i :o :yx]) cmd = parse_these_opts(cmd, d, [[:A :nn :nearest_neighbor], [:C :clip], [:E :handedness], [:F :force_polygons], - [:I :intersections], [:Q :area :length], [:W :extend]]) + [:I :intersections], [:Q :centroid :area :length], [:W :extend]]) cmd = add_opt(d, cmd, "S", [:S :polygons :polyg_process], (buffer="b", holes="_h", dateline="_s")) cmd, args, n, = add_opt(d, cmd, "D", [:D :duplicates], :data, Array{Any,1}([arg1, arg2]), (amax="+a", dmax="+d", cmax="+c", Cmax="+c", fact="+s", ortho="_+p")) @@ -86,6 +86,7 @@ function gmtspatial(cmd0::String="", arg1=nothing, arg2 = nothing; kwargs...) D = common_grd(d, cmd0, cmd, "gmtspatial ", arg1..., arg2, arg3, arg4) # Finish build cmd and run it arg = arg1[end] else + isa(arg1, GDtype) && isgeog(arg1) && !contains(cmd, " -f") && (cmd *= " -fg") D = common_grd(d, cmd0, cmd, "gmtspatial ", arg1, arg2, arg3, arg4) arg = arg2 end diff --git a/src/show_pretty_datasets.jl b/src/show_pretty_datasets.jl index 041198029..f122568d6 100644 --- a/src/show_pretty_datasets.jl +++ b/src/show_pretty_datasets.jl @@ -115,6 +115,7 @@ function _show(io::IO, (D.proj4 != "") && println("PROJ: ", D.proj4) (D.wkt != "") && println("WKT: ", D.wkt) (D.header != "") && println("Header:\t", D.header) + (!isempty(D.comment)) && println("Comment:\t", D.comment) println("") end @@ -167,7 +168,7 @@ function _show(io::IO, alignment_anchor_regex = alignment_anchor_regex, compact_printing = compact_printing, crop = crop, - crop_num_lines_at_beginning = 2, + reserved_display_lines = 2, ellipsis_line_skip = 3, formatters = (_pretty_tables_general_formatter,), header = (names_str, types_str), @@ -176,11 +177,11 @@ function _show(io::IO, highlighters = (_PRETTY_TABLES_HIGHLIGHTER,), maximum_columns_width = maximum_columns_width, newline_at_end = false, - nosubheader = !eltypes, - row_name_alignment = :r, - row_name_crayon = Crayon(), - row_name_column_title = string(rowlabel), - row_names = row_names, + show_subheader = !eltypes, + row_label_alignment = :r, + row_label_crayon = Crayon(), + row_label_column_title = string(rowlabel), + row_labels = row_names, row_number_alignment = :r, row_number_column_title = string(rowlabel), show_row_number = show_row_number, diff --git a/src/utils_project.jl b/src/utils_project.jl index e838bac97..d619acd9b 100644 --- a/src/utils_project.jl +++ b/src/utils_project.jl @@ -518,3 +518,13 @@ function sideplot(; plane=:xz, vsize=8, depth=NaN, kw...) _W, _H = (p == 'x') ? (H, zsize) : (p == 'y') ? (W, zsize) : (W, H) @sprintf(" -Dg%.12g/%.12g+w%.12g/%.12g -p%c%.0f/%.0f %s %s", lims[1], lims[3], _W, _H, p, azim, elev, opt_X, opt_Y) end + +""" + isgeog(in)::Bool + +Find if the input (a GMTgrid, GMTimage, GMTdadaset or string), if referenced, is in geographical coordinates. +""" +function isgeog(in)::Bool + prj = getproj(in, proj4=true) + (prj != "" && contains(prj, "=long") || contains(prj, "=lat")) +end \ No newline at end of file diff --git a/test/test_common_opts.jl b/test/test_common_opts.jl index 6ce449eee..203fd218a 100644 --- a/test/test_common_opts.jl +++ b/test/test_common_opts.jl @@ -269,6 +269,7 @@ mat2ds(rand(3,3), segnan=true) @test mat2ds([1. NaN 3; NaN 3 4; 5 6 NaN]).ds_bbox == [1.0, 5.0, 3.0, 6.0, 3.0, 4.0] D[1].attrib = Dict("nome" => "a", "nome2" => "b"); + info(D, attribs=true); GMT.polygonlevels(D, ["a", "b"], [1,2], att="nome"); GMT.polygonlevels(D, ["a", "b"], [1,2], att="nome", nocase=1); GMT.polygonlevels(D, ["a" "aa"; "b" "bb"], [1,2], att=["nome", "nome2"]); diff --git a/test/test_gd_ext.jl b/test/test_gd_ext.jl index 177b1a5a5..18229410f 100644 --- a/test/test_gd_ext.jl +++ b/test/test_gd_ext.jl @@ -10,6 +10,8 @@ bf = buffer([0 0], 1) @test bf.geom == Gdal.wkbPolygon c = centroid(bf) + D = [mat2ds([0. 0; 1 1; 2 0; 0 0], geom=UInt32(3)), mat2ds([0. 0; 1 1; 2 0; 0 0], geom=UInt32(3))]; + centroid(D); # Test multipolygons #@test c.data ≈ [0. 0.] bf2 = buffer([0.5 0], 1); polyunion(bf, bf2); diff --git a/test/test_misc.jl b/test/test_misc.jl index 7e28c5934..87af87979 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -242,7 +242,7 @@ grdcontour(G, axis="a", color=cpt, pen="+c", fmt=:png, savefig="lixo") D = grdcontour(G, cont=[-2,0,5], dump=true); - info(makecpt(C=:rainbow)) + info(makecpt(C=:rainbow)); add2PSfile("Bla") add2PSfile(["Bla", "Bla"])