本文整理汇总了C#中OsmSharp.Osm.Node类的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于OsmSharp.Osm命名空间,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAddNode
public void TestAddNode()
{
Node testNode =new Node();
testNode.Id = -1;
testNode.Latitude = 0;
testNode.Longitude = 0;
var source = new MemoryDataSource();
source.AddNode(testNode);
// test if the node is actually there.
Assert.AreEqual(testNode, source.GetNode(-1));
// test if the node was not remove after getting it.
Assert.AreEqual(testNode, source.GetNodes(new List<long>() { -1 })[0]);
// test if the node is in the list of nodes.
Assert.AreEqual(testNode, new List<Node>(source.GetNodes())[0]);
// test if the node will be retrieved using a list of ids.
var ids = new List<long>();
ids.Add(-1);
IList<Node> nodes = source.GetNodes(ids);
Assert.IsNotNull(nodes);
Assert.AreEqual(1, nodes.Count);
Assert.AreEqual(testNode, nodes[0]);
}
示例2: AddNode
/// <summary>
///
/// </summary>
/// <param name="node"></param>
public override void AddNode(Node node)
{
if (node == null) throw new ArgumentNullException("node");
if (node.Id == null) throw new Exception("node.Id is null");
this.Store(node);
}
示例3: Create
/// <summary>
/// Creates a new node.
/// </summary>
/// <param name="id"></param>
/// <param name="latitude"></param>
/// <param name="longitude"></param>
/// <returns></returns>
public static Node Create(long id, double latitude, double longitude)
{
Node node = new Node();
node.Id = id;
node.Latitude = latitude;
node.Longitude = longitude;
return node;
}
示例4: AddNode
public override void AddNode(Node node)
{
if (!node.Id.HasValue)
return;
MaxStringLength(node.UserName, ref NodeUsr);
if (node.Tags == null)
return;
foreach (Tag tag in node.Tags)
{
MaxStringLength(tag.Key, ref NodeTagsKey);
MaxStringLength(tag.Value, ref NodeTagsValue);
}
}
示例5: TestWayAreaIsYesArea
public void TestWayAreaIsYesArea()
{
var node1 = new Node();
node1.Id = 1;
node1.Latitude = 0;
node1.Longitude = 0;
var node2 = new Node();
node2.Id = 2;
node2.Latitude = 1;
node2.Longitude = 0;
var node3 = new Node();
node3.Id = 3;
node3.Latitude = 0;
node3.Longitude = 1;
var way = new Way();
way.Id = 1;
way.Nodes = new List<long>();
way.Nodes.Add(1);
way.Nodes.Add(2);
way.Nodes.Add(3);
way.Nodes.Add(1);
way.Tags = new TagsCollection();
way.Tags.Add("area", "yes");
var source = new List<OsmGeo>();
source.Add(node1);
source.Add(node2);
source.Add(node3);
source.Add(way);
// create source stream.
var sourceStream = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(source.ToOsmStreamSource());
// create features source.
var featuresSourceStream = new OsmFeatureStreamSource(sourceStream);
// pull stream.
var features = new List<Feature>(featuresSourceStream);
Assert.IsNotNull(features);
Assert.AreEqual(1, features.Count);
var feature = features[0];
Assert.IsInstanceOf<LineairRing>(feature.Geometry);
Assert.IsTrue(feature.Attributes.ContainsKeyValue("area", "yes"));
}
示例6: CompareComplete
/// <summary>
/// Compares the two complete objects.
/// </summary>
public static void CompareComplete(Node expected, Node actual)
{
if (expected == null)
{ // ok, if the value is also null.
Assert.IsNull(actual);
}
else
{ // check and compare the value.
Assert.IsNotNull(actual);
Assert.AreEqual(expected.Id, actual.Id);
Assert.AreEqual(expected.ChangeSetId, actual.ChangeSetId);
Assert.AreEqual(expected.Coordinate, actual.Coordinate);
Assert.AreEqual(expected.TimeStamp, actual.TimeStamp);
Assert.AreEqual(expected.UserName, actual.UserName);
Assert.AreEqual(expected.UserId, actual.UserId);
Assert.AreEqual(expected.Version, actual.Version);
Assert.AreEqual(expected.Visible, actual.Visible);
}
}
示例7: TestEmptyCSS
public void TestEmptyCSS()
{
// create 'test' objects.
Node node1 = new Node();
node1.Id = 1;
node1.Latitude = 1;
node1.Longitude = 1;
Node node2 = new Node();
node2.Id = 2;
node2.Latitude = 2;
node2.Longitude = 2;
Way way = new Way();
way.Id = 1;
way.Nodes = new List<long>();
way.Nodes.Add(1);
way.Nodes.Add(2);
// create the datasource.
MemoryDataSource dataSource = new MemoryDataSource();
dataSource.AddNode(node1);
dataSource.AddNode(node2);
dataSource.AddWay(way);
// create the projection and scene objects.
var mercator = new WebMercator();
Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
// create the interpreter.
MapCSSInterpreter interpreter = new MapCSSInterpreter(string.Empty,
new MapCSSDictionaryImageSource());
interpreter.Translate(scene, mercator, dataSource, node1);
interpreter.Translate(scene, mercator, dataSource, node2);
interpreter.Translate(scene, mercator, dataSource, way);
// test the scene contents.
Assert.AreEqual(0, scene.Count);
Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, scene.BackColor);
}
示例8: TestWayAreaIsYes
public void TestWayAreaIsYes()
{
Node node1 = new Node();
node1.Id = 1;
node1.Latitude = 0;
node1.Longitude = 0;
Node node2 = new Node();
node2.Id = 2;
node2.Latitude = 1;
node2.Longitude = 0;
Node node3 = new Node();
node3.Id = 3;
node3.Latitude = 0;
node3.Longitude = 1;
Way way = new Way();
way.Id = 1;
way.Nodes = new List<long>();
way.Nodes.Add(1);
way.Nodes.Add(2);
way.Nodes.Add(3);
way.Nodes.Add(1);
way.Tags = new TagsCollection();
way.Tags.Add("area", "yes");
var source = new List<OsmGeo>();
source.Add(node1);
source.Add(node2);
source.Add(node3);
source.Add(way);
// the use of natural=water implies an area-type.
var interpreter = new SimpleFeatureInterpreter();
var completeStreamSource = new OsmSimpleCompleteStreamSource(source.ToOsmStreamSource());
// use the stream to interpret.
var features = new List<Feature>(new FeatureInterpreterStreamSource(completeStreamSource, interpreter));
Assert.AreEqual(1, features.Count);
}
开发者ID:APLANA-Alexey-Stolyarov,项目名称:OsmSharpDataProcessor,代码行数:40,代码来源:GeometryInterpreterStreamSourceTests.cs
示例9: APITestNodeCreateGetDelete
public void APITestNodeCreateGetDelete()
{
// intialize the connection.
var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
"osmsharp", "osmsharp");
// open a changeset.
apiInstance.ChangeSetOpen("Simple Node Creation Test");
// initialize the node.
var node = new Node();
node.Latitude = -0.494497;
node.Longitude = -24.119325;
node.Tags = new TagsCollection();
node.Tags.Add("type", "testnode");
node.Visible = true;
// save the node.
node = apiInstance.NodeCreate(node);
// close the changeset.
apiInstance.ChangeSetClose();
// check if the id now has a value.
Assert.IsTrue(node.Id.HasValue);
// get the new node id.
long nodeId = node.Id.Value;
// get the node again: a node can only be deleted using the correct changesetid and version.
node = apiInstance.NodeGet(node.Id.Value);
// open new changeset.
apiInstance.ChangeSetOpen("Simple Node Delete Test");
// get the node.
apiInstance.NodeDelete(node);
// close the current changeset.
apiInstance.ChangeSetClose();
// get the node.
Node apiNode = apiInstance.NodeGet(node.Id.Value);
Assert.IsNull(apiNode);
}
示例10: CompareSimple
/// <summary>
/// Compares a found node to an expected node.
/// </summary>
public static void CompareSimple(Node expected, Node actual)
{
Assert.IsNotNull(expected);
Assert.IsNotNull(actual);
Assert.AreEqual(expected.Id, actual.Id);
Assert.AreEqual(expected.ChangeSetId, actual.ChangeSetId);
Assert.AreEqual((float)expected.Latitude, (float)actual.Latitude);
Assert.AreEqual((float)expected.Longitude, (float)actual.Longitude);
Assert.AreEqual(expected.TimeStamp, actual.TimeStamp);
Assert.AreEqual(expected.Type, actual.Type);
Assert.AreEqual(expected.UserId, actual.UserId);
Assert.AreEqual(expected.UserName, actual.UserName);
Assert.AreEqual(expected.Version, actual.Version);
Assert.AreEqual(expected.Visible, actual.Visible);
ComparisonHelpers.CompareTags(expected.Tags, actual.Tags);
}
示例11: AddNode
/// <summary>
/// Adds a node.
/// </summary>
/// <param name="node"></param>
private void AddNode(Node node)
{
if (_nodes.ContainsKey(node.Id))
{
throw new InvalidOperationException("Cannot add an object that already exists in this source!" + Environment.NewLine +
"If there is a modification use a changeset!");
}
else
{
_nodes.Add(node.Id, node);
}
}
示例12: GetWaysFor
/// <summary>
/// Returns the way(s) for the given node.
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public IList<Way> GetWaysFor(Node node)
{
if (_ways_per_node.ContainsKey(node.Id))
{
return this.GetWays(_ways_per_node[node.Id]);
}
return null;
}
示例13: APITestRelationCreateGetUpdate
public void APITestRelationCreateGetUpdate()
{
// intialize the connection.
var apiInstance = new APIConnection("http://api06.dev.openstreetmap.org/",
"osmsharp", "osmsharp");
// open a changeset.
apiInstance.ChangeSetOpen("Simple Relation Creation Test");
// initialize the relation.
var relation = new Relation();
relation.Tags = new TagsCollection();
relation.Tags.Add("type", "testrelation");
relation.Members = new List<RelationMember>();
relation.Visible = true;
// initialize the nodes.
var node = new Node();
node.Latitude = -0.494497;
node.Longitude = -24.119325;
node.Tags = new TagsCollection();
node.Tags.Add("type", "testnode1");
node.Visible = true;
node = apiInstance.NodeCreate(node);
relation.Members.Add(new RelationMember()
{
MemberId = node.Id.Value,
MemberRole = "some_nodes_role",
MemberType = OsmGeoType.Node
});
node = new Node();
node.Latitude = -0.494497 + 0.0001f;
node.Longitude = -24.119325 + 0.0001f;
node.Tags = new TagsCollection();
node.Tags.Add("type", "testnode2");
node.Visible = true;
node = apiInstance.NodeCreate(node);
relation.Members.Add(new RelationMember()
{
MemberId = node.Id.Value,
MemberRole = "some_nodes_role",
MemberType = OsmGeoType.Node
});
// save the relation.
relation = apiInstance.RelationCreate(relation);
// close the changeset.
apiInstance.ChangeSetClose();
// check if the id now has a value.
Assert.IsTrue(relation.Id.HasValue);
// get the new relation id.
long relationId = relation.Id.Value;
// open new changeset.
apiInstance.ChangeSetOpen("Simple Relation Update Test");
// get the relation.
Relation apiRelation = apiInstance.RelationGet(relation.Id.Value);
apiRelation.Tags.Add("another_tag", "test adding a tag!");
apiInstance.RelationUpdate(apiRelation);
// close the current changeset.
apiInstance.ChangeSetClose();
// get the api relation.
apiRelation = apiInstance.RelationGet(relation.Id.Value);
Assert.AreEqual(2, apiRelation.Tags.Count);
Assert.IsTrue(apiRelation.Tags.ContainsKey("another_tag"));
Assert.AreEqual("test adding a tag!", apiRelation.Tags["another_tag"]);
}
示例14: TestCanvasJOSMSettingsCSS
public void TestCanvasJOSMSettingsCSS()
{
// create CSS.
string css = "canvas { " +
"background-color: white; " +
"default-points: true; " + // adds default points for every node (color: black, size: 2).
"default-lines: true; " + // adds default lines for every way (color: red, width: 1).
"} ";
// create 'test' objects.
Node node1 = new Node();
node1.Id = 1;
node1.Latitude = 1;
node1.Longitude = 1;
Node node2 = new Node();
node2.Id = 2;
node2.Latitude = 2;
node2.Longitude = 2;
Way way = new Way();
way.Id = 1;
way.Nodes = new List<long>();
way.Nodes.Add(1);
way.Nodes.Add(2);
// create the datasource.
MemoryDataSource dataSource = new MemoryDataSource();
dataSource.AddNode(node1);
dataSource.AddNode(node2);
dataSource.AddWay(way);
// create the projection and scene objects.
var mercator = new WebMercator();
Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
// create the interpreter.
MapCSSInterpreter interpreter = new MapCSSInterpreter(css,
new MapCSSDictionaryImageSource());
interpreter.Translate(scene, mercator, dataSource, node1);
interpreter.Translate(scene, mercator, dataSource, node2);
interpreter.Translate(scene, mercator, dataSource, way);
// test the scene contents.
Assert.AreEqual(3, scene.Count);
Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor);
// test the scene point 1.
Primitive2D primitive = scene.Get(0);
Assert.IsNotNull(primitive);
Assert.IsInstanceOf<Primitive2D>(primitive);
Point2D pointObject = primitive as Point2D;
Assert.AreEqual(2, pointObject.Size);
Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X);
Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y);
// test the scene point 2.
primitive = scene.Get(1);
Assert.IsNotNull(primitive);
Assert.IsInstanceOf<Point2D>(primitive);
pointObject = primitive as Point2D;
Assert.AreEqual(2, pointObject.Size);
Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color);
Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X);
Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y);
// test the scene line 2.
primitive = scene.Get(2);
Assert.IsNotNull(primitive);
Assert.IsInstanceOf<Line2D>(primitive);
Line2D line = primitive as Line2D;
Assert.AreEqual(1, line.Width);
Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color);
Assert.IsNotNull(line.X);
Assert.IsNotNull(line.Y);
Assert.AreEqual(2, line.X.Length);
Assert.AreEqual(2, line.Y.Length);
Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]);
Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]);
Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]);
Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]);
}
示例15: CompareNodes
/// <summary>
/// Compares a found node to an expected node.
/// </summary>
/// <param name="expected"></param>
/// <param name="found"></param>
private void CompareNodes(Node expected, Node found)
{
Assert.IsNotNull(expected);
Assert.IsNotNull(found);
Assert.AreEqual(expected.Id, found.Id);
Assert.AreEqual(expected.ChangeSetId, found.ChangeSetId);
Assert.AreEqual((float)expected.Latitude, (float)found.Latitude);
Assert.AreEqual((float)expected.Longitude, (float)found.Longitude);
Assert.AreEqual(expected.TimeStamp, found.TimeStamp);
Assert.AreEqual(expected.Type, found.Type);
Assert.AreEqual(expected.UserId, found.UserId);
Assert.AreEqual(expected.UserName, found.UserName);
Assert.AreEqual(expected.Version, found.Version);
Assert.AreEqual(expected.Visible, found.Visible);
this.CompareTags(expected.Tags, found.Tags);
}