-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
270 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
language: csharp | ||
mono: none | ||
dotnet: 2.1 | ||
dotnet: 2.2 | ||
script: | ||
- dotnet restore OsmDataKit.sln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
|
||
namespace OsmDataKit | ||
{ | ||
public static class GeoObjectExtensions | ||
{ | ||
public static IGeoCoords GetCenterCoords(this GeoObject geo) | ||
{ | ||
switch (geo) | ||
{ | ||
case NodeObject node: | ||
return node; | ||
|
||
case WayObject way: | ||
return way.Nodes.AverageCoords(); | ||
|
||
case RelationObject relation: | ||
return relation.GetAllNestedNodes().AverageCoords(); | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(nameof(geo)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OsmDataKit | ||
{ | ||
public static class RelationMemberObjectExtensions | ||
{ | ||
public static IEnumerable<NodeObject> GetNodes(this IEnumerable<RelationMemberObject> members) => | ||
members.Where(i => i.Geo is NodeObject).Select(i => i.Geo as NodeObject); | ||
|
||
public static IEnumerable<WayObject> GetWays(this IEnumerable<RelationMemberObject> members) => | ||
members.Where(i => i.Geo is WayObject).Select(i => i.Geo as WayObject); | ||
|
||
public static IEnumerable<RelationObject> GetRelations(this IEnumerable<RelationMemberObject> members) => | ||
members.Where(i => i.Geo is RelationObject).Select(i => i.Geo as RelationObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,53 @@ | ||
using OsmSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OsmDataKit | ||
{ | ||
public static class RelationObjectExtensions | ||
{ | ||
public static IEnumerable<NodeObject> Nodes(this RelationObject relation) => | ||
relation.Members.Where(i => i.Geo.Type == OsmGeoType.Node) | ||
.Select(i => (NodeObject)i.Geo); | ||
public static IEnumerable<NodeObject> GetNodes(this RelationObject relation) => | ||
relation.Members.GetNodes(); | ||
|
||
public static IEnumerable<WayObject> Ways(this RelationObject relation) => | ||
relation.Members.Where(i => i.Geo.Type == OsmGeoType.Way) | ||
.Select(i => (WayObject)i.Geo); | ||
public static IEnumerable<WayObject> GetWays(this RelationObject relation) => | ||
relation.Members.GetWays(); | ||
|
||
public static IEnumerable<RelationObject> Relations(this RelationObject relation) => | ||
relation.Members.Where(i => i.Geo.Type == OsmGeoType.Relation) | ||
.Select(i => (RelationObject)i.Geo); | ||
public static IEnumerable<RelationObject> GetRelations(this RelationObject relation) => | ||
relation.Members.GetRelations(); | ||
|
||
public static IEnumerable<NodeObject> GetAllNodes(this RelationObject relation) => | ||
relation.Nodes().Concat(relation.Ways().SelectMany(i => i.Nodes)) | ||
.Concat(relation.Relations().SelectMany(i => i.GetAllNodes())); | ||
public static IEnumerable<NodeObject> GetAllNestedNodes(this RelationObject relation) => | ||
relation.GetNodes().Concat(relation.GetWays().SelectMany(i => i.Nodes)) | ||
.Concat(relation.GetRelations().SelectMany(i => i.GetAllNestedNodes())); | ||
|
||
internal static bool GetIsBroken(this RelationObject relation) | ||
{ | ||
foreach (var member in relation.Members) | ||
{ | ||
switch (member.Geo) | ||
{ | ||
case NodeObject node: | ||
break; | ||
|
||
case WayObject way: | ||
|
||
if (way.IsBroken) | ||
return true; | ||
|
||
break; | ||
|
||
case RelationObject rel: | ||
|
||
if (rel.GetIsBroken()) | ||
return true; | ||
|
||
break; | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(nameof(member)); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.