Skip to content

Commit de222ab

Browse files
committed
Moved some commonly used extension methods to core project.
1 parent f3e8581 commit de222ab

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

OsmSharp.Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<!--- Package information, Version -->
55
<PropertyGroup>
6-
<PackageVersion>7.0.0-pre020</PackageVersion>
6+
<PackageVersion>7.0.0-pre021</PackageVersion>
77
<LangVersion>latest</LangVersion>
88
<Company>Itinero BV</Company>
99
<Authors>OsmSharp Contributors</Authors>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
5+
namespace OsmSharp.Streams;
6+
7+
/// <summary>
8+
/// Extension methods to easily save/load OSM data.
9+
/// </summary>
10+
public static class IEnumerableExtensions
11+
{
12+
/// <summary>
13+
/// Creates a new file and write the data as an OSM-XML file.
14+
/// </summary>
15+
/// <param name="data">The data to write.</param>
16+
/// <param name="file">The file to create.</param>
17+
public static void CreateAsOsmFile(this IEnumerable<OsmGeo> data, string file)
18+
{
19+
using var stream = File.Create(file);
20+
using var outputStream = new OsmSharp.Streams.XmlOsmStreamTarget(stream);
21+
outputStream.RegisterSource(data);
22+
outputStream.Pull();
23+
outputStream.Flush();
24+
}
25+
26+
/// <summary>
27+
/// Creates a new file and write the data as OSM-PBF file.
28+
/// </summary>
29+
/// <param name="data">The data to write.</param>
30+
/// <param name="file">The file to create.</param>
31+
public static void CreateAsOsmPbfFile(this IEnumerable<OsmGeo> data, string file)
32+
{
33+
using var stream = File.Create(file);
34+
var outputStream = new OsmSharp.Streams.PBFOsmStreamTarget(stream);
35+
outputStream.RegisterSource(data);
36+
outputStream.Pull();
37+
outputStream.Flush();
38+
}
39+
}

0 commit comments

Comments
 (0)