Giter VIP home page Giter VIP logo

core-3.5's Introduction

OsmSharp.Core .NET 3.5 (forked from OsmSharp.Core)

This version of OsmSharp.Core compiles for .NET 3.5, making it possible to use with Unity3D

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.Core

Usage

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/belgium-latest.osm.pbf").OpenRead());

var filter = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterPoly(
	new OsmSharp.Geo.Geometries.LineairRing(
		new GeoCoordinate(51.084978552372114, 3.655529022216797),
		new GeoCoordinate(51.081851317961930, 3.812427520751953),
		new GeoCoordinate(51.994851160022010, 3.760070800781250),
		new GeoCoordinate(51.084978552372114, 3.655529022216797)));
filter.RegisterSource(source);

var target = new PBFOsmStreamTarget(
	new FileInfo(@"/path/to/gent-triangle.osm.pbf").Open(FileMode.Create, FileAccess.ReadWrite));
target.RegisterSource(filter);
target.Pull();

core-3.5's People

Contributors

xivk avatar cmberryau avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.