Exemplo n.º 1
0
 // 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.");
 }
Exemplo n.º 2
0
 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.");
 }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
 /// <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);
 }
Exemplo n.º 5
0
 /// <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);
 }