8000 Add lat and lon columns for `out * center;` queries in `osmdata_data_frame` by jmaspons · Pull Request #316 · ropensci/osmdata · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add lat and lon columns for out * center; queries in osmdata_data_frame #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 8, 2023

Conversation

jmaspons
Copy link
Collaborator
@jmaspons jmaspons commented Mar 3, 2023

For calls to osmdata_data_frame that do not include the query and the results only contain nodes, there is no way to distinguish if center lat & lon columns have to be added or not. The current implementation adds osm_center_lat/lon in these cases

Fix #315

jmaspons added 4 commits March 3, 2023 23:43
When results only contain nodes, there is no way to distinguish if
center lat & long columns have to be included or not
@jmaspons jmaspons requested a review from mpadge March 3, 2023 23:28
Copy link
Member
@mpadge mpadge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another great advance, thanks so much. This review requests just a minor change, but I'm going to put some more major stuff into a separate PR into your local branch, and will comment more there.

jmaspons and others added 3 commits March 7, 2023 17:16
Co-authored-by: mark padgham <mark.padgham@email.com>
have 'tags center' return NA values from C++ code instead of DOUBLE_MAX
@jmaspons
Copy link
Collaborator Author
jmaspons commented Mar 7, 2023

Thanks for the review, @mpadge. Everything addressed, so I'm going to merge

@mpadge
Copy link
Member
mpadge commented Mar 7, 2023

Thanks for the review, @mpadge. Everything addressed, so I'm going to merge

@jmaspons Please don't do so until I have another look through and re-review this. Can you please request another review from me? Thanks

@jmaspons jmaspons requested a review from mpadge March 7, 2023 17:07
Copy link
Member
@mpadge mpadge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be okay once those changes have been implemented, but maybe just check downstream in the general workflow here. One thing i'm not sure about - due to me not understanding it fully 😏 - is these lines (in "get-osmdata-df.R"::xml_to_df()):

    if (any (missing_center)) { # not a "out * center;" query
        center <- lapply (center, function (x) {
            x[, c ("osm_center_lat", "osm_center_lon")] <- NULL
            x
        })
    }

They now don't do anything at all, right? And so can be removed, right?

this <- this [, which (has_data), drop = FALSE]
if (ncol (this) > 0L) {
colnames (this) <- paste0 ("osm_center", colnames (this))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
this <- this [-seq_len (nrow (this)), ]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's necessary because of the rownames. Having those means causes rows to be retained even when all columns are removed, so nrow(this) remains at whatever value it was, and not zero. That line removes all rows any time that the columns are removed, ensuring a null data.frame is returned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we need that nrows match other data.frames, so a nrows x 0 dimensions data.frame is fine and necessary, otherwise the code will fail around

data.frame(

And all the tests pass so I think it's fine as it is

Co-authored-by: mark padgham <mark.padgham@email.com>
@jmaspons
Copy link
Collaborator Author
jmaspons commented Mar 7, 2023

One thing i'm not sure about - due to me not understanding it fully smirk - is these lines (in "get-osmdata-df.R"::xml_to_df()):

    if (any (missing_center)) { # not a "out * center;" query
        center <- lapply (center, function (x) {
            x[, c ("osm_center_lat", "osm_center_lon")] <- NULL
            x
        })
    }

They now don't do anything at all, right? And so can be removed, right?

This part remove osm_center_* columns if in doc exist objects types without center data (checked 3 lines above these lines). The porpo 8000 ise is to identify queries which should not return center columns (no out * center;). I do like this to avoid passing the query to the function. The problematic case is for results that only contain nodes, because nodes always contain lat & lon (relations and ways only when query has out * center;).

Removing the columns like this instead of center <- data.frame() keeps nrow which is necessary as explained above

Copy link
Member
@mpadge mpadge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks Joan!

@mpadge mpadge merged commit 84c3aaf into ropensci:main Mar 8, 2023
@jmaspons jmaspons deleted the center branch March 8, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Parse latitude and longitude in results from out * center; queries
2 participants
0