internal void Export() { mapping = new RoadMapping(4.5); var osm = new osm(); osm.version = 0.6M; osm.upload = false; osm.meta = new osmMeta { osm_base = DateTime.Now }; osm.generator = "Cities Skylines Magic Mapper Mod"; osm.note = Singleton <SimulationManager> .instance.m_metaData.m_CityName; osm.bounds = new osmBounds { minlon = 35.753054M, minlat = 34.360353M, maxlon = 35.949310M, maxlat = 34.522050M }; var nm = Singleton <NetManager> .instance; mapping.InitBoundingBox(osm.bounds, 1); nodeCount = 128000; wayCount = 128000; AddNodesAndWays(); AddBuildings(); AddDistricts(); AddCity(); AddCountours(); osm.node = FilterUnusedNodes(); osm.way = ways.ToArray(); var serializer = new XmlSerializer(typeof(osm)); var ms = new StreamWriter(Singleton <SimulationManager> .instance.m_metaData.m_CityName + ".osm"); serializer.Serialize(ms, osm); ms.Close(); }
private void Init(osm osm, double scale) { mapping.InitBoundingBox(osm.bounds, scale); foreach (var node in osm.node) { if (!nodes.ContainsKey(node.id) && node.lat != 0 && node.lon != 0) { Vector2 pos = Vector2.zero; if (mapping.GetPos(node.lon, node.lat, ref pos)) { nodes.Add(node.id, pos); } } } foreach (var way in osm.way.OrderBy(c => c.changeset)) { RoadTypes rt = RoadTypes.None; List <long> points = null; int layer = 0; if (mapping.Mapped(way, ref points, ref rt, ref layer)) { var currentList = new List <long>(); for (var i = 0; i < points.Count; i += 1) { var pp = points[i]; if (nodes.ContainsKey(pp)) { currentList.Add(pp); } else { if (currentList.Count() > 1 || currentList.Contains(pp)) { ways.AddLast(new Way(currentList, rt, layer)); currentList = new List <long>(); } } } if (currentList.Count() > 1) { ways.AddLast(new Way(currentList, rt, layer)); } } } var intersection = new Dictionary <long, List <Way> >(); foreach (var ww in ways) { foreach (var pp in ww.nodes) { if (!intersection.ContainsKey(pp)) { intersection.Add(pp, new List <Way>()); } intersection[pp].Add(ww); } } var allSplits = new Dictionary <Way, List <int> >(); foreach (var inter in intersection) { if (inter.Value.Count > 1) { foreach (var way in inter.Value) { if (!allSplits.ContainsKey(way)) { allSplits.Add(way, new List <int>()); } allSplits[way].Add(way.nodes.IndexOf(inter.Key)); } } } foreach (var waySplits in allSplits) { SplitWay(waySplits.Key, waySplits.Value); } BreakWaysWhichAreTooLong(); SimplifyWays(); }
internal void Export() { mapping = new RoadMapping(4.5); var osm = new osm(); osm.version = 0.6M; osm.upload = false; osm.meta = new osmMeta { osm_base = DateTime.Now }; osm.generator = "Cities Skylines Magic Mapper Mod"; osm.note = Singleton<SimulationManager>.instance.m_metaData.m_CityName; osm.bounds = new osmBounds { minlon = 35.753054M, minlat = 34.360353M, maxlon = 35.949310M, maxlat = 34.522050M }; var nm = Singleton<NetManager>.instance; mapping.InitBoundingBox(osm.bounds, 1); nodeCount = 128000; wayCount = 128000; AddNodesAndWays(); AddBuildings(); AddDistricts(); AddCity(); AddCountours(); osm.node = FilterUnusedNodes(); osm.way = ways.ToArray(); var serializer = new XmlSerializer(typeof(osm)); var ms = new StreamWriter(Singleton<SimulationManager>.instance.m_metaData.m_CityName + ".osm"); serializer.Serialize(ms, osm); ms.Close(); }
private void Init(osm osm,double scale) { mapping.InitBoundingBox(osm.bounds, scale); foreach (var node in osm.node) { if (!nodes.ContainsKey(node.id) && node.lat != 0 && node.lon != 0) { Vector2 pos = Vector2.zero; if (mapping.GetPos(node.lon, node.lat, ref pos)) { nodes.Add(node.id, pos); } } } foreach (var way in osm.way.OrderBy(c => c.changeset)) { RoadTypes rt = RoadTypes.None; List<uint> points = null; int layer = 0; if (mapping.Mapped(way, ref points, ref rt, ref layer)) { Vector2 previousPoint = Vector2.zero; var currentList = new List<uint>(); for (var i = 0; i < points.Count; i += 1) { var pp = points[i]; if (nodes.ContainsKey(pp)) { currentList.Add(pp); previousPoint = nodes[pp]; } else { if (currentList.Count() > 1 || currentList.Contains(pp)) { ways.AddLast(new Way(currentList, rt, layer)); currentList = new List<uint>(); } } } if (currentList.Count() > 1) { ways.AddLast(new Way(currentList, rt, layer)); } } } var intersection = new Dictionary<uint, List<Way>>(); foreach (var ww in ways) { foreach (var pp in ww.nodes) { if (!intersection.ContainsKey(pp)) { intersection.Add(pp, new List<Way>()); } intersection[pp].Add(ww); } } var allSplits = new Dictionary<Way, List<int>>(); foreach (var inter in intersection) { if (inter.Value.Count > 1) { foreach (var way in inter.Value) { if (!allSplits.ContainsKey(way)) { allSplits.Add(way, new List<int>()); } allSplits[way].Add(way.nodes.IndexOf(inter.Key)); } } } foreach (var waySplits in allSplits) { SplitWay(waySplits.Key, waySplits.Value); } BreakWaysWhichAreTooLong(); SimplifyWays(); }
private void Init(osm osm) { mapping.InitBoundingBox(osm.bounds, scale); // get nodes from OSM nodes.Clear(); foreach (var node in osm.node) { if (!nodes.ContainsKey(node.id) && node.lat != 0 && node.lon != 0) { Vector2 pos = Vector2.zero; if (mapping.GetPos(node.lon, node.lat, ref pos)) { nodes.Add(node.id, pos); } } } // get ways from OSM ways.Clear(); roadTypeCount.Clear(); foreach (var way in osm.way) { RoadTypes rt = RoadTypes.None; List <long> points = null; int layer = 0; OSMRoadTypes osmrt = OSMRoadTypes.unclassified; string streetName = "noname"; if (way != null && way.tag != null) { foreach (var tag in way.tag) { if (tag != null) { if (tag.k.Trim().ToLower() == "name") { streetName = tag.v; } } } } if (mapping.Mapped(way, ref points, ref rt, ref osmrt, ref layer)) { if (roadTypeCount.ContainsKey(osmrt)) { roadTypeCount[osmrt] += points.Count; } else { roadTypeCount.Add(osmrt, points.Count); } var way_points = new List <long>(); for (var i = 0; i < points.Count; i += 1) { var pp = points[i]; if (nodes.ContainsKey(pp)) { way_points.Add(pp); } else { if (way_points.Count() > 1 || way_points.Contains(pp)) { if (!ways.ContainsKey(osmrt)) { ways.Add(osmrt, new LinkedList <Way>()); } Way w = new Way(way_points, rt, osmrt, layer, streetName); ways[osmrt].AddLast(w); allWays.Add(w); way_points = new List <long>(); } } } if (way_points.Count() > 1) { if (!ways.ContainsKey(osmrt)) { ways.Add(osmrt, new LinkedList <Way>()); } Way w = new Way(way_points, rt, osmrt, layer, streetName); ways[osmrt].AddLast(w); if (allWays.IndexOf(w) == -1) { allWays.Add(w); } } } } allWays = new List <Way>(); foreach (var rt in ways) { foreach (Way way in ways[rt.Key]) { if (allWays.IndexOf(way) == -1) { allWays.Add(way); } } } var intersections = new Dictionary <long, List <Way> >(); var allSplits = new Dictionary <Way, List <int> >(); foreach (var ww in allWays) { foreach (var pp in ww.nodes) { if (!intersections.ContainsKey(pp)) { intersections.Add(pp, new List <Way>()); } intersections[pp].Add(ww); } } foreach (var inter in intersections) { if (inter.Value.Count > 1) { foreach (var way in inter.Value) { if (!allSplits.ContainsKey(way)) { allSplits.Add(way, new List <int>()); } allSplits[way].Add(way.nodes.IndexOf(inter.Key)); } } } foreach (var waySplits in allSplits) { SplitWay(waySplits.Key, waySplits.Value); } BreakWaysWhichAreTooLong(); MergeWaysWhichAreTooShort(); SimplifyWays(); }