本文整理汇总了C#中OsmSharp.Collections.Tags.TagsCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TagsCollection.Add方法的具体用法?C# TagsCollection.Add怎么用?C# TagsCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OsmSharp.Collections.Tags.TagsCollection
的用法示例。
在下文中一共展示了TagsCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRandomBlockTagSerializaton
public void TestRandomBlockTagSerializaton()
{
TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex();
TagsCollection tagsCollection = new TagsCollection();
for (int i = 0; i < 100; i++)
{
int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1;
for (int idx = 0; idx < tagCollectionSize; idx++)
{
int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10);
tagsCollection.Add(
string.Format("key_{0}", tagValue),
string.Format("value_{0}", tagValue));
}
uint tagsId = tagsIndex.Add(tagsCollection);
}
ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlock(tagsIndex, 10, 0);
Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
for (uint idx = 0; idx < tagsIndex.Max; idx++)
{
ComparisonHelpers.CompareTags(tagsIndex.Get(idx),
tagsIndexReadonly.Get(idx));
}
}
示例2: TestSerialization
/// <summary>
/// Tests preprocessing data from a PBF file.
/// </summary>
/// <param name="name"></param>
/// <param name="pbfFile"></param>
public static void TestSerialization(string name, string pbfFile)
{
FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
Stream stream = testFile.OpenRead();
PBFOsmStreamSource source = new PBFOsmStreamSource(stream);
FileInfo testOutputFile = new FileInfo(@"test.routing");
testOutputFile.Delete();
Stream writeStream = testOutputFile.OpenWrite();
CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream,
Vehicle.Car);
target.RegisterSource(source);
PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializer");
performanceInfo.Start();
performanceInfo.Report("Pulling from {0}...", testFile.Name);
var data = CHEdgeGraphOsmStreamTarget.Preprocess(
source, new OsmRoutingInterpreter(), Vehicle.Car);
TagsCollectionBase metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
routingSerializer.Serialize(writeStream, data, metaData);
stream.Dispose();
writeStream.Dispose();
OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information,
string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
performanceInfo.Stop();
}
示例3: MapCSSEvalTagTest
public void MapCSSEvalTagTest()
{
string function = "tag('width')";
TagsCollectionBase tags = new TagsCollection();
tags.Add("width", "2");
Assert.AreEqual(2, EvalInterpreter.Instance.InterpretDouble(function, tags));
}
示例4: TextProbableSpeed
/// <summary>
/// Tests the probable speed.
/// </summary>
/// <param name="vehicle"></param>
/// <param name="speed"></param>
/// <param name="tags"></param>
protected void TextProbableSpeed(Vehicle vehicle, double speed, params string[] tags)
{
// build tags collection.
TagsCollection tagsCollection = new TagsCollection();
for (int idx = 0; idx < tags.Length; idx = idx + 2)
{
tagsCollection.Add(tags[idx], tags[idx + 1]);
}
Assert.AreEqual(speed, vehicle.ProbableSpeed(tagsCollection).Value);
}
示例5: TestBooleanParsing
public void TestBooleanParsing()
{
// test IsTrue.
TagsCollectionBase tags = new TagsCollection();
tags.Add("area", "yes");
Assert.IsTrue(tags.IsTrue("area"));
tags = new TagsCollection();
tags.Add("area", "1");
Assert.IsTrue(tags.IsTrue("area"));
tags = new TagsCollection();
tags.Add("area", "true");
Assert.IsTrue(tags.IsTrue("area"));
tags = new TagsCollection();
tags.Add("area", "false");
Assert.IsFalse(tags.IsTrue("area"));
tags = new TagsCollection();
tags.Add("area", "0");
Assert.IsFalse(tags.IsTrue("area"));
tags = new TagsCollection();
tags.Add("area", "no");
Assert.IsFalse(tags.IsTrue("area"));
// test IsFalse.
tags = new TagsCollection();
tags.Add("area", "yes");
Assert.IsFalse(tags.IsFalse("area"));
tags = new TagsCollection();
tags.Add("area", "1");
Assert.IsFalse(tags.IsFalse("area"));
tags = new TagsCollection();
tags.Add("area", "true");
Assert.IsFalse(tags.IsFalse("area"));
tags = new TagsCollection();
tags.Add("area", "false");
Assert.IsTrue(tags.IsFalse("area"));
tags = new TagsCollection();
tags.Add("area", "0");
Assert.IsTrue(tags.IsFalse("area"));
tags = new TagsCollection();
tags.Add("area", "no");
Assert.IsTrue(tags.IsFalse("area"));
}
示例6: TestSerialize
/// <summary>
/// Tests serializing a stream.
/// </summary>
/// <param name="name"></param>
/// <param name="stream"></param>
/// <param name="scene"></param>
/// <param name="compress"></param>
public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress)
{
PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name));
performanceInfo.Start();
performanceInfo.Report("Serializing stream...");
TagsCollectionBase metaTags = new TagsCollection();
metaTags.Add("generated_by", "performance_test");
scene.Serialize(stream, compress, metaTags);
performanceInfo.Stop();
Console.Write("", scene.BackColor);
}
示例7: TestSerialization
/// <summary>
/// Tests preprocessing data from a PBF file.
/// </summary>
/// <param name="name"></param>
/// <param name="pbfFile"></param>
public static void TestSerialization(string name, string pbfFile)
{
var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
var stream = testFile.OpenRead();
var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
source.RegisterSource(new PBFOsmStreamSource(stream));
var testOutputFile = new FileInfo(@"test.pedestrian.routing");
testOutputFile.Delete();
Stream writeStream = testOutputFile.OpenWrite();
var tagsIndex = new TagsTableCollectionIndex();
var interpreter = new OsmRoutingInterpreter();
var graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize");
performanceInfo.Start();
performanceInfo.Report("Pulling from {0}...", testFile.Name);
var data = CHEdgeGraphOsmStreamTarget.Preprocess(
source, new OsmRoutingInterpreter(), Vehicle.Car);
var metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
var routingSerializer = new CHEdgeFlatfileSerializer();
routingSerializer.Serialize(writeStream, data, metaData);
stream.Dispose();
writeStream.Dispose();
OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
performanceInfo.Stop();
performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Deserialize");
performanceInfo.Start();
performanceInfo.Report("Deserializing again...");
// open file again and read.
writeStream = testOutputFile.OpenRead();
var deserializedGraph = routingSerializer.Deserialize(writeStream);
performanceInfo.Stop();
}
示例8: TestVehicleCanTranverse
/// <summary>
/// Tests the can traverse functionality.
/// </summary>
protected void TestVehicleCanTranverse(Vehicle vehicle, bool result, params string[] tags)
{
// build tags collection.
TagsCollection tagsCollection = new TagsCollection();
for (int idx = 0; idx < tags.Length; idx = idx + 2)
{
tagsCollection.Add(tags[idx], tags[idx + 1]);
}
if (result)
{ // assume the result is true.
Assert.IsTrue(vehicle.CanTraverse(tagsCollection));
}
else
{ // assume the result is false.
Assert.IsFalse(vehicle.CanTraverse(tagsCollection));
}
}
示例9: TestTagsCollectionIndex
/// <summary>
/// Tests the given tags collection index.
/// </summary>
/// <param name="tagsCollectionIndex"></param>
protected void TestTagsCollectionIndex(ITagsCollectionIndex tagsCollectionIndex)
{
List<KeyValuePair<uint, TagsCollectionBase>> addedTags = new List<KeyValuePair<uint, TagsCollectionBase>>();
for (int i = 0; i < 100; i++)
{
TagsCollection tagsCollection = new TagsCollection();
int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
for (int idx = 0; idx < tagCollectionSize; idx++)
{
int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
tagsCollection.Add(
string.Format("key_{0}", tagValue),
string.Format("value_{0}", tagValue));
}
int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
for (int idx = 0; idx < addCount; idx++)
{
uint tagsId = tagsCollectionIndex.Add(tagsCollection);
addedTags.Add(new KeyValuePair<uint, TagsCollectionBase>(tagsId, tagsCollection));
TagsCollectionBase indexTags = tagsCollectionIndex.Get(tagsId);
Assert.AreEqual(tagsCollection.Count, indexTags.Count);
foreach (Tag tag in tagsCollection)
{
Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
}
}
}
// check the index.
foreach (KeyValuePair<uint, TagsCollectionBase> pair in addedTags)
{
TagsCollectionBase indexTags = tagsCollectionIndex.Get(pair.Key);
Assert.AreEqual(pair.Value.Count, indexTags.Count);
foreach (Tag tag in pair.Value)
{
Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
}
foreach (Tag tag in indexTags)
{
Assert.IsTrue(pair.Value.ContainsKeyValue(tag.Key, tag.Value));
}
}
}
示例10: FillIndex
/// <summary>
/// Tests adding simple tags to the given index.
/// </summary>
/// <param name="index"></param>
/// <param name="collectionCount"></param>
public static void FillIndex(ITagsCollectionIndex index, int collectionCount)
{
for (int i = 0; i < collectionCount; i++)
{
TagsCollection tagsCollection = new TagsCollection();
int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
for (int idx = 0; idx < tagCollectionSize; idx++)
{
int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(100);
tagsCollection.Add(
string.Format("key_{0}", tagValue),
string.Format("value_{0}", tagValue));
}
int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
for (int idx = 0; idx < addCount; idx++)
{
uint tagsId = index.Add(tagsCollection);
}
}
}
示例11: TestTagIndexSerialization
public void TestTagIndexSerialization()
{
// set the seed manually.
OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);
// build a tags index and keep what was added.
var tagsIndex = new TagsIndex(new MemoryMappedStream(new MemoryStream()));
var addedTags = new List<KeyValuePair<uint, TagsCollectionBase>>();
for (int i = 0; i < 100; i++)
{
var tagsCollection = new TagsCollection();
var tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
for (int idx = 0; idx < tagCollectionSize; idx++)
{
var tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
tagsCollection.Add(
string.Format("key_{0}", tagValue),
string.Format("value_{0}", tagValue));
}
var addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
for (int idx = 0; idx < addCount; idx++)
{
var tagsId = tagsIndex.Add(tagsCollection);
addedTags.Add(new KeyValuePair<uint, TagsCollectionBase>(tagsId, tagsCollection));
var indexTags = tagsIndex.Get(tagsId);
Assert.AreEqual(tagsCollection.Count, indexTags.Count);
foreach (var tag in tagsCollection)
{
Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
}
}
}
// serialize/deserialize.
var deserializedTagsIndex = this.SerializeDeserialize(tagsIndex, false);
// verify if what was added is still there.
this.TestTagIndexContent(deserializedTagsIndex, addedTags);
}
示例12: TestTagIndex
/// <summary>
/// Tests the given tags collection index.
/// </summary>
/// <param name="tagsCollectionIndex"></param>
protected void TestTagIndex(ITagsIndex tagsCollectionIndex)
{
// set the seed manually.
OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);
var addedTags = new List<KeyValuePair<uint, TagsCollectionBase>>();
for (int i = 0; i < 100; i++)
{
var tagsCollection = new TagsCollection();
var tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
for (int idx = 0; idx < tagCollectionSize; idx++)
{
var tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
tagsCollection.Add(
string.Format("key_{0}", tagValue),
string.Format("value_{0}", tagValue));
}
var addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
for (int idx = 0; idx < addCount; idx++)
{
var tagsId = tagsCollectionIndex.Add(tagsCollection);
addedTags.Add(new KeyValuePair<uint, TagsCollectionBase>(tagsId, tagsCollection));
var indexTags = tagsCollectionIndex.Get(tagsId);
Assert.AreEqual(tagsCollection.Count, indexTags.Count);
foreach (var tag in tagsCollection)
{
Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
}
}
}
// test complete content.
this.TestTagIndexContent(tagsCollectionIndex, addedTags);
}
示例13: TestSerialization
/// <summary>
/// Tests preprocessing data from a PBF file.
/// </summary>
/// <param name="name"></param>
/// <param name="pbfFile"></param>
public static void TestSerialization(string name, string pbfFile)
{
var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
var performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
performanceInfo.Start();
performanceInfo.Report("Pulling from {0}...", testFile.Name);
var stream = testFile.OpenRead();
var source = new PBFOsmStreamSource(stream);
var progress = new OsmStreamFilterProgress();
progress.RegisterSource(source);
var testOutputFile = new FileInfo(@"test.routing");
testOutputFile.Delete();
Stream writeStream = testOutputFile.OpenWrite();
var tagsIndex = new TagsTableCollectionIndex();
var interpreter = new OsmRoutingInterpreter();
var graph = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var routingSerializer = new LiveEdgeFlatfileSerializer();
// read from the OSM-stream.
using (var fileFactory = new MemoryMappedFileFactory(@"d:\temp\"))
{
using (var memoryMappedGraph = new MemoryMappedGraph<LiveEdge>(10000, fileFactory))
{
using (var coordinates = new HugeCoordinateIndex(fileFactory, 10000))
{
var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(memoryMappedGraph, tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);
targetData.RegisterSource(progress);
targetData.Pull();
performanceInfo.Stop();
performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
performanceInfo.Start();
performanceInfo.Report("Writing file for {0}...", testFile.Name);
var metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
routingSerializer.Serialize(writeStream, memoryData, metaData);
}
}
}
stream.Dispose();
writeStream.Dispose();
OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
performanceInfo.Stop();
performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
performanceInfo.Start();
performanceInfo.Report("Reading file for {0}...", testFile.Name);
var testInputFile = new FileInfo(@"europe-latest.osm.pbf.routing");
Stream readStream = testInputFile.OpenRead();
var deserializedGraph = routingSerializer.Deserialize(readStream, false);
readStream.Dispose();
OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
string.Format("Read: {0}KB", testInputFile.Length / 1024));
OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());
performanceInfo.Stop();
}
示例14: RoutingSerializationV2CompressedRoutingTest
public void RoutingSerializationV2CompressedRoutingTest()
{
const string embeddedString = "OsmSharp.Test.Unittests.test_network.osm";
// create the tags index.
var tagsIndex = new TagsTableCollectionIndex();
// creates a new interpreter.
var interpreter = new OsmRoutingInterpreter();
// do the data processing.
var original =
new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(
original, interpreter, tagsIndex);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
targetData.RegisterSource(dataProcessorSource);
targetData.Pull();
// create serializer.
var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true);
// serialize/deserialize.
TagsCollectionBase metaData = new TagsCollection();
metaData.Add("some_key", "some_value");
byte[] byteArray;
using (var stream = new MemoryStream())
{
try
{
routingSerializer.Serialize(stream, original, metaData);
byteArray = stream.ToArray();
}
catch (Exception)
{
if (Debugger.IsAttached)
{
Debugger.Break();
}
throw;
}
}
IBasicRouterDataSource<LiveEdge> deserializedVersion =
routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));
// try to do some routing on the deserialized version.
var basicRouter = new DykstraRoutingLive();
Router router = Router.CreateLiveFrom(deserializedVersion, basicRouter, interpreter);
RouterPoint source = router.Resolve(Vehicle.Car,
new GeoCoordinate(51.0578532, 3.7192229));
RouterPoint target = router.Resolve(Vehicle.Car,
new GeoCoordinate(51.0576193, 3.7191801));
// calculate the route.
Route route = router.Calculate(Vehicle.Car, source, target);
Assert.IsNotNull(route);
Assert.AreEqual(5, route.Entries.Length);
float latitude, longitude;
deserializedVersion.GetVertex(20, out latitude, out longitude);
Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);
deserializedVersion.GetVertex(21, out latitude, out longitude);
Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001);
Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001);
Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type);
deserializedVersion.GetVertex(16, out latitude, out longitude);
Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001);
Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001);
Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type);
deserializedVersion.GetVertex(22, out latitude, out longitude);
Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001);
Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001);
Assert.AreEqual(RoutePointEntryType.Along, route.Entries[3].Type);
deserializedVersion.GetVertex(23, out latitude, out longitude);
Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001);
Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001);
Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[4].Type);
}
示例15: TestSimpleTagSerializatonNonBeginPosition
public void TestSimpleTagSerializatonNonBeginPosition()
{
TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex();
TagsCollection tagsCollection = new TagsCollection();
tagsCollection.Add("key1", "value1");
uint tagsId = tagsIndex.Add(tagsCollection);
ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201);
Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
for (uint idx = 0; idx < tagsIndex.Max; idx++)
{
ComparisonHelpers.CompareTags(tagsIndex.Get(idx),
tagsIndexReadonly.Get(idx));
}
}