ropenstreetmapigraphosmar

`E<-`(`*tmp*`, value = `*vtmp*`) : invalid indexing, building a subset of an OSM Object. Edit: subset does not create a true subset


Im trying to build a small subset of a bigger osm object:

First i load a bigger osm object into memory:

muc_bbox <- center_bbox(mid_point[1], mid_point[2], dist * 2, dist * 2)
src <- osmsource_osmosis(file = paste(maps_pfad,"streets_bayern.osm",sep = ""))
muc <- get_osm(muc_bbox, src)

then i build a subset based on coordinates of the nodes:

subset_bbox <- center_bbox(mid_point[1], mid_point[2], dist, dist)

maybe i have to use find instead of subset here?

muc_subset_df <- subset(muc$nodes$attrs, lon > subset_bbox[[1]] & lon < subset_bbox[[3]] 
&lat > subset_bbox[[2]] & lat < subset_bbox[[4]])

subset_ids <- muc_subset_df$id
muc_subset <- subset(muc, node_ids = subset_ids)

muc <- muc_subset

so basically i search for all the node ids of nodes that are in the lat&lon value range of bbox.

now i want to build n igraph of this new subset:

gr_muc <- as_igraph(muc)

And get this error:

E<-`(`*tmp*`, value = `*vtmp*`) : invalid indexing

What is the mistake im making?

Before i subset i get this info regarding muc object

    dim(muc)
    nodes      ways relations 
   360451     59490         3 

After Subset i get 0 ways and relations. I think this is probably the mistake... how would i subset everything?

Even after i use find_up function on subset_ids i still dont get any relation_ids.

subset_ids <- muc_subset_df$id
osm_subset_ids <- find_up(muc, node(subset_ids))
muc_subset <- subset(muc,  osm_subset_ids)

What am i missing?

EDIT: After investigating a bit further it seems that

muc_subset <- subset(muc,  osm_subset_ids)

Does not create a true subset of an osm object. It only creates an object containing nodes but no ways or relations. I suspect this to be a problem but still dont know how to solve it.

> muc_subset
osmar object
80165 nodes, 0 ways, 0 relations 
> muc
osmar object
80165 nodes, 14161 ways, 0 relations 

Yet osm_subset_ids contains ids of ways.

Best regards, Andreas.


Solution

  • To say it in German: alter das wirst du nicht glauben!

    So the problam was the way i called the function subset

    It is possble (at least in my working env) to call the function subset with parameter ids and without.. probably because this function is overloaded.

    this is possible:

    muc_subset <- subset(muc,  ids = osm_subset_ids)
    

    as this:

    muc_subset <- subset(muc,  osm_subset_ids)
    

    Both calls will run and produce no error. the difference is the result:

    osmar object
    0 nodes, 0 ways, 0 relations 
    

    VS

    osmar object
    80165 nodes, 14161 ways, 0 relations 
    

    I hope it helps. Cheers.