Compare commits
No commits in common. "c2cadd678ce0a3c8c64bf87dcc2bd85917c43d66" and "f0cd97fbc79b98be07984e7db59aa88bdad6aaaa" have entirely different histories.
c2cadd678c
...
f0cd97fbc7
@ -32,7 +32,7 @@ public class Tag
|
||||
return new Tag(type, value);
|
||||
}
|
||||
|
||||
public static Tag? ConvertToTag(string key, string value)
|
||||
public static Tag ConvertToTag(string key, string value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@ -73,18 +73,12 @@ public class Tag
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
return new Tag(Tag.TagType.EMPTY, false);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"TAG {key.ToString()} {value.ToString()}";
|
||||
}
|
||||
|
||||
|
||||
public enum TagType : byte
|
||||
{
|
||||
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id
|
||||
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id, EMPTY
|
||||
}
|
||||
|
||||
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
|
||||
|
@ -5,48 +5,48 @@ namespace OSMDatastructure.Graph;
|
||||
[Serializable]
|
||||
public class TagManager
|
||||
{
|
||||
public readonly Dictionary<ulong, HashSet<Tag>> wayTagSets = new();
|
||||
public readonly Dictionary<ulong, HashSet<Tag>> wayTags = new();
|
||||
|
||||
public bool ContainsKey(ulong wayId, Tag.TagType key)
|
||||
{
|
||||
return wayTagSets.ContainsKey(wayId) && wayTagSets[wayId].Any(tag => tag.key == key);
|
||||
return wayTags.ContainsKey(wayId) && wayTags[wayId].Any(tag => tag.key == key);
|
||||
}
|
||||
|
||||
public object? GetTag(ulong wayId, Tag.TagType key)
|
||||
{
|
||||
return ContainsKey(wayId, key) ? wayTagSets[wayId].First(tag => tag.key == key) : null;
|
||||
return ContainsKey(wayId, key) ? wayTags[wayId].First(tag => tag.key == key) : null;
|
||||
}
|
||||
|
||||
public void AddTag(ulong wayId, string key, string value)
|
||||
{
|
||||
Tag? tag = Tag.ConvertToTag(key, value);
|
||||
if(tag is not null)
|
||||
AddTag(wayId, tag);
|
||||
Tag tag = Tag.ConvertToTag(key, value);
|
||||
AddTag(wayId, tag);
|
||||
}
|
||||
|
||||
public void AddTag(ulong wayId, Tag tag)
|
||||
{
|
||||
if(!wayTagSets.ContainsKey(wayId))
|
||||
wayTagSets.Add(wayId, new HashSet<Tag>());
|
||||
HashSet<Tag> wayTags = wayTagSets[wayId];
|
||||
if (!wayTags.Any(wayTag => wayTag.key == tag.key))
|
||||
if (tag.key != Tag.TagType.EMPTY)
|
||||
{
|
||||
wayTags.Add(tag);
|
||||
if(!wayTags.ContainsKey(wayId))
|
||||
wayTags.Add(wayId, new HashSet<Tag>());
|
||||
wayTags[wayId].Add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTag(ulong wayId, KeyValuePair<Tag.TagType, dynamic> tag)
|
||||
public void AddTag(ulong wayId, KeyValuePair<Tag.TagType, dynamic> keyValuePair)
|
||||
{
|
||||
AddTag(wayId, new Tag(tag.Key, tag.Value));
|
||||
if(!wayTags.ContainsKey(wayId))
|
||||
wayTags.Add(wayId, new HashSet<Tag>());
|
||||
wayTags[wayId].Add(new Tag(keyValuePair.Key, keyValuePair.Value));
|
||||
}
|
||||
|
||||
public HashSet<Tag>? GetTagsForWayId(ulong wayId)
|
||||
{
|
||||
return wayTagSets.TryGetValue(wayId, out HashSet<Tag>? value) ? value : null;
|
||||
return wayTags.TryGetValue(wayId, out HashSet<Tag>? value) ? value : null;
|
||||
}
|
||||
|
||||
public bool ContainsWay(ulong wayId)
|
||||
{
|
||||
return wayTagSets.ContainsKey(wayId);
|
||||
return wayTags.ContainsKey(wayId);
|
||||
}
|
||||
}
|
@ -120,9 +120,8 @@ public class RegionConverter
|
||||
currentTags.TryAdd(Tag.TagType.id, Convert.ToUInt64(wayReader.GetAttribute("id")!));
|
||||
if (wayReader.Name == "tag")
|
||||
{
|
||||
Tag? wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
|
||||
if(wayTag is not null)
|
||||
currentTags.TryAdd(wayTag.key, wayTag.value);
|
||||
Tag wayTag = Tag.ConvertToTag(wayReader.GetAttribute("k")!, wayReader.GetAttribute("v")!);
|
||||
currentTags.TryAdd(wayTag.key, wayTag.value);
|
||||
}
|
||||
else if (wayReader.Name == "nd")
|
||||
{
|
||||
@ -194,13 +193,8 @@ public class RegionConverter
|
||||
string tagsRegionPath = Path.Combine(outputPath, regionHash.ToString(), tagsFileName);
|
||||
regionTagsFileStreams.Add(regionHash, new FileStream(tagsRegionPath, FileMode.OpenOrCreate));
|
||||
}
|
||||
|
||||
ulong id = currentTags[Tag.TagType.id];
|
||||
TagManager tm = new TagManager();
|
||||
foreach(KeyValuePair<Tag.TagType, dynamic> kv in currentTags)
|
||||
tm.AddTag(id, kv);
|
||||
#pragma warning disable SYSLIB0011
|
||||
bFormatter.Serialize(regionTagsFileStreams[regionHash], tm);
|
||||
bFormatter.Serialize(regionTagsFileStreams[regionHash], currentTags);
|
||||
#pragma warning restore SYSLIB0011
|
||||
}
|
||||
}
|
@ -25,18 +25,6 @@ public class RegionLoader
|
||||
Region r = GetRegion(regionHash);
|
||||
return r.ways;
|
||||
}
|
||||
|
||||
public TagManager GetTags(ulong regionHash)
|
||||
{
|
||||
Region r = GetRegion(regionHash);
|
||||
return r.tagManager;
|
||||
}
|
||||
|
||||
public HashSet<Tag>? GetTagsForWay(ulong regionHash, ulong wayId)
|
||||
{
|
||||
Region r = GetRegion(regionHash);
|
||||
return r.tagManager.GetTagsForWayId(wayId);
|
||||
}
|
||||
|
||||
public Region GetRegion(ulong regionHash)
|
||||
{
|
||||
@ -72,17 +60,6 @@ public class RegionLoader
|
||||
newRegion.nodes.Add(deserializedNode);
|
||||
}
|
||||
}
|
||||
|
||||
using (FileStream tagsFileStream = new FileStream(Path.Join(path, regionHash.ToString(), RegionConverter.tagsFileName), FileMode.Open))
|
||||
{
|
||||
while (tagsFileStream.Position < tagsFileStream.Length)
|
||||
{
|
||||
TagManager tm = (TagManager)bFormatter.Deserialize(tagsFileStream);
|
||||
ulong id = (ulong)tm.wayTagSets.First()!.Value.First(tag => tag.key == Tag.TagType.id)!.value;
|
||||
foreach(Tag tag in tm.wayTagSets.First()!.Value)
|
||||
newRegion.tagManager.AddTag(id, tag);
|
||||
}
|
||||
}
|
||||
#pragma warning restore SYSLIB0011
|
||||
|
||||
regionIdsDict.Add(regionHash, newRegion);
|
||||
|
@ -17,10 +17,7 @@ public class Server
|
||||
Console.WriteLine("Loaded");
|
||||
RegionLoader rl = new RegionLoader("D:/map");
|
||||
Region r = rl.GetRegion(13870001898000);
|
||||
Console.WriteLine(r.nodes.First());
|
||||
Console.WriteLine(r.ways.First());
|
||||
Console.WriteLine(rl.GetTagsForWay(13870001898000, 5897420)!.Last());
|
||||
Console.WriteLine("Region loaded");
|
||||
|
||||
|
||||
/*
|
||||
Coordinates start = new Coordinates(48.243351f, 11.640417f);
|
||||
|
Loading…
Reference in New Issue
Block a user