Skip to content

Help for custom summarise functions #175

Description

@shriv

I have a variant of the following reprex that I want to use to combine multiple spatial linestrings into one. Each linestring is stored in a dataframe as a string. I've tried variants with ArchGDAL operations as well as a basic string concat one (shown below). They all fail when operated inside @summarise which I naively thought would pass in the values of the column to be summarised as a vector. I'd appreciate any help / suggestions as I'm pretty new to Julia and chances are I've messed somewhere obvious!

using TidierData, DataFrames
a = "LINESTRING (174.700802400011 -36.7923053378313,174.70080829999 -36.7925833378168,174.700814000017 -36.7928505378355)"

df = DataFrame(
    group = ["A", "A", "B", "B"],
    text  = vcat(a, a, a, a)
)

function join_linestrings(wkts)
    coords = [wkt[13:end-1] for wkt in wkts]
    "LINESTRING ($(join(coords, ",")))"
end

# Fails
@chain df begin
    @group_by(group)
    @summarise(text_join = Main.join_linestrings(text))
end

# works
df_plot = combine(groupby(df, :group), :text => join_linestrings => :text_join)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions