OSMDataPrimitives 2.2.2
dotnet add package OSMDataPrimitives --version 2.2.2
NuGet\Install-Package OSMDataPrimitives -Version 2.2.2
<PackageReference Include="OSMDataPrimitives" Version="2.2.2" />
paket add OSMDataPrimitives --version 2.2.2
#r "nuget: OSMDataPrimitives, 2.2.2"
// Install OSMDataPrimitives as a Cake Addin #addin nuget:?package=OSMDataPrimitives&version=2.2.2 // Install OSMDataPrimitives as a Cake Tool #tool nuget:?package=OSMDataPrimitives&version=2.2.2
OSMDataPrimitives
Intention
This pretty little project is intended to provide the 3 basic data types (nodes, ways and relations) of OpenStreetMap as .NET classes. I'm about to use it in some other projects.
Usage
To create new instances of an OSMNode:
using OSMDataPrimitives;
var node = new OSMNode(1, 52.123456, 12.654321) {
UserId = 1,
UserName = "username",
Version = 1,
Changeset = 1,
Timestamp = DateTime.Now
};
node.Tags.Add("name", "foo");
node.Tags.Add("ref", "bar");
It's also easy to create new instances of an OSMWay:
var way = new OSMWay(1) {
UserId = 1,
UserName = "username",
Version = 1,
Changeset = 1,
TimeStamp = DateTime.Now
};
way.Tags.Add("name", "first road");
way.Tags.Add("ref", "A1");
way.NodeRefs.Add(1);
way.NodeRefs.Add(2);
way.NodeRefs.Add(3);
way.NodeRefs.Add(4);
And last but not least an OSMRelation:
var relation = new OSMRelation(1) {
UserId = 1,
UserName = "username",
Version = 1,
Changeset = 1,
TimeStamp = DateTime.Now
};
relation.Tags.Add("name", "my little country");
relation.Tags.Add("note", "just a test.");
relation.Members.Add(new OSMMember(MemberType.Way, 1, "outer"));
relation.Members.Add(new OSMMember(MemberType.Way, 2, "outer"));
To simply convert these OSMElement's to a XML-String or a XmlElement:
using OSMDataPrimitives;
using OSMDataPrimitives.Xml;
var node = new OSMNode(1, 52.123456, 12.654321) {
UserId = 1,
UserName = "username",
Version = 1,
Changeset = 1,
Timestamp = DateTime.Now
};
node.Tags.Add("name", "foo");
node.Tags.Add("ref", "bar");
var xmlString = node.ToXmlString();
Console.WriteLine(xmlString);
/*
* output:
* <node id="1" lat="52.123456" lon="12.654321" version="1" uid="1" user="username" changeset="1" timestamp="2017-01-31T12:34:17Z"><tag k="name" v="foo" /><tag k="ref" v="bar" /></node>
*/
var xmlElement = node.ToXml();
Console.WriteLine(xmlElement.OuterXml);
/*
* output (the same as above):
* <node id="1" lat="52.123456" lon="12.654321" version="1" uid="1" user="username" changeset="1" timestamp="2017-01-31T12:36:09Z"><tag k="name" v="foo" /><tag k="ref" v="bar" /></node>
*/
It is also possible to build PostgreSQL queries for the OSMElement's:
var node = new OSMNode(1, 52.123456, 12.654321) {
UserId = 1,
UserName = "username",
Version = 1,
Changeset = 1,
Timestamp = DateTime.Now
};
node.Tags.Add("name", "foo");
node.Tags.Add("ref", "bar");
NameValueCollection sqlParameters;
var sqlQuery = node.ToPostgreSQLInsert(out sqlParameters);
Console.WriteLine(sqlQuery);
/*
* output:
* INSERT INTO nodes (osm_id, lat, lon, tags) VALUES(@osm_id::bigint, @lat::double precision, @lon::double precision, @tags::hstore)
*
* The values for @osm_id, @lat, @lon and @tags are put into the sqlParameters-variable.
*/
// to add all the meta-data:
sqlQuery = node.ToPostgreSQLInsert(out sqlParameters, inclusiveMetaFields: true);
Console.WriteLine(sqlQuery);
/*
* output:
* INSERT INTO nodes (osm_id, version, changeset, uid, user, timestamp, lat, lon, tags) VALUES(@osm_id::bigint, @version::bigint, @changeset::bigint, @uid::bigint, @user, TIMESTAMP @timestamp, @lat::double precision, @lon::double precision, @tags::hstore)
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on OSMDataPrimitives:
Package | Downloads |
---|---|
OSMDataPrimitives.BSON
This is the BSON-Extension for the OSMDataPrimitives project |
|
OSMDataPrimitives.Spatial
This is the Spatial-Extension for the OSMDataPrimitives project |
|
O5MLibrary
This project provides reading and writing capabilities of O5M Data. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.2 | 488 | 2/1/2024 |
2.2.1 | 129 | 1/30/2024 |
2.2.0 | 138 | 1/29/2024 |
2.1.3 | 201 | 1/8/2024 |
2.1.2 | 332 | 11/22/2023 |
2.1.1 | 146 | 11/22/2023 |
2.1.0 | 161 | 11/20/2023 |
2.0.0 | 540 | 4/3/2023 |
1.3.0 | 834 | 11/19/2020 |
1.2.2 | 500 | 7/3/2020 |
1.2.0 | 1,750 | 11/14/2017 |
1.0.12 | 1,568 | 6/21/2017 |
1.0.10 | 1,536 | 2/13/2017 |
1.0.9 | 924 | 2/10/2017 |
1.0.8 | 1,345 | 2/9/2017 |
1.0.7 | 975 | 2/3/2017 |
1.0.6 | 1,184 | 1/30/2017 |
1.0.4 | 1,151 | 1/23/2017 |
1.0.3 | 1,193 | 1/22/2017 |
1.0.2 | 967 | 1/21/2017 |
1.0.1.39490 | 966 | 1/19/2017 |
changed target framework to .NET 6.0 - .NET 8.0