// Needs to prevent infinite recusion using a reference id exclusion listS public static IEnumerable <OsmGeo> WithChildren(this OsmGeo parent, IOsmGeoSource possibleChilden) { if (parent is Node) { return new[] { parent } } ; else if (parent is Way way) { return(way.Nodes.Select(n => possibleChilden.Get(OsmGeoType.Node, n)) .Append(parent)); } else if (parent is Relation relation) { return(relation.Members .SelectMany(m => { var child = possibleChilden.Get(m.Type, m.Id); return child != null ? WithChildren(child, possibleChilden) : Enumerable.Empty <OsmGeo>(); }) .Where(m => m != null) .Append(parent)); } throw new Exception("OsmGeo wasn't a Node, Way or Relation."); }
private static IEnumerable <OsmGeo> WithChildren(OsmGeo parent, IOsmGeoSource possibleChilden) { if (parent is Node) { return new[] { parent } } ; else if (parent is Way way) { return(way.Nodes.Select(n => possibleChilden.Get(OsmGeoType.Node, n)) .Append(parent)); } else if (parent is Relation relation) { return(relation.Members .SelectMany(m => { var child = possibleChilden.Get(m.Type, m.Id); return child != null ? WithChildren(child, possibleChilden) // warning, infinite recursion if references have circular members : Enumerable.Empty <OsmGeo>(); }) .Where(m => m != null) .Append(parent)); } throw new Exception("OsmGeo wasn't a Node, Way or Relation."); }
/// <summary> /// Gets the way with the given id. /// </summary> public static Way GetWay(this IOsmGeoSource db, long id) { return(db.Get(OsmGeoType.Way, id) as Way); }
/// <summary> /// Gets the relation with the given id. /// </summary> public static Relation GetRelation(this IOsmGeoSource db, long id) { return(db.Get(OsmGeoType.Relation, id) as Relation); }
/// <summary> /// Gets the node with the given id. /// </summary> public static Node GetNode(this IOsmGeoSource db, long id) { return(db.Get(OsmGeoType.Node, id) as Node); }