Skip to content

klosejay/core

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

265 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OsmSharp

Build status

  • OsmSharp: NuGet NuGet
  • OsmSharp.Geo: NuGet NuGet

Visit our website
MIT licensed

OsmSharp's core enables you to work directly with OSM-data in .NET/Mono. Most important features are:

  • Read/Write OSM-XML.
  • Read/Write OSM-PBF.
  • Streamed architecture, minimal memory footprint.
  • Convert a stream of native OSM objects to 'complete' OSM objects: Ways with all their actual nodes, Relations with all members instantiated.
  • Convert OSM objects to geometries.

Install

PM> Install-Package OsmSharp

There's also a package to use NTS together with OsmSharp to convert OSM-data to features/geometries.

PM> Install-Package OsmSharp.Geo

Usage

This readme contains some basic examples, for more documentation and samples check the wiki.

A common usecase is to stream and filter OSM data. To read from an OSM file and enumerate all objects just open the file as a stream source and use foreach.

Read data from an OSM-PBF file:

// using OsmSharp.Osm.PBF.Streams;

using(var fileStream = new FileInfo(@"/path/to/some/osmfile.osm.pbf").OpenRead())
{
  var source = new PBFOsmStreamSource(fileStream);
  foreach (var element in source)
  {
    Console.WriteLine(element.ToString());
  }
}

Write data to an OSM-PBF file:

// using OsmSharp.Collections.Tags;
// using OsmSharp.Osm;
// using OsmSharp.Osm.PBF.Streams;

using(var fileStream = new FileInfo(@"/path/to/my/osmfile.osm.pbf").OpenRead())
{
	var target = new PBFOsmStreamTarget(fileStream);
	target.Initialize();
	target.AddNode(new Node()
		{
			Id = 1,
			ChangeSetId = 1,
			Latitude = 0,
			Longitude = 0,
			Tags = new TagsCollection(
				Tag.Create("key", "value")),
			TimeStamp = DateTime.Now,
			UserId = 1424,
			UserName = "you",
			Version = 1,
			Visible = true
		});
	target.Flush();
	target.Close();
}

Filter an area and extract a smaller region:

// using OsmSharp.Math.Geo;
// using OsmSharp.Osm.PBF.Streams;

var source = new PBFOsmStreamSource(
	new FileInfo(@"/path/to/file.osm.pbf").OpenRead());

var filtered = source.FilterBox(6.238002777099609f, 49.72076145492323f, 
	6.272850036621093f, 49.69928180928878f); // left, top, right, bottom

using (var stream = new FileInfo(@"/path/to/filterede.osm.pbf").Open(FileMode.Create, FileAccess.ReadWrite))
{
   var target = new PBFOsmStreamTarget(stream);
   target.RegisterSource(filter);
   target.Pull();
}

Licensing

The OsmSharp project is licensed under the MIT license.

This project includes some code from SharpZipLib, also MIT licensed.

About

The core functionality of OsmSharp.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C# 99.9%
  • Shell 0.1%