private void AddCity() { Debug.Log("Building count: " + this.buildingCount.ToString()); Debug.Log("Middle: " + this.middle.ToString()); decimal lon = 0.0M; decimal lat = 0.0M; mapping.GetPos(new Vector3(this.middle.x / this.buildingCount, 0, this.middle.y / this.buildingCount), out lon, out lat); var md = Singleton <SimulationManager> .instance; var tags = new List <osmNodeTag>(); tags.Add(new osmNodeTag { k = "name", v = md.m_metaData.m_CityName }); tags.Add(new osmNodeTag { k = "place", v = "city" }); tags.Add(new osmNodeTag { k = "population", v = Singleton <DistrictManager> .instance.m_districts.m_buffer[0].m_populationData.m_finalCount.ToString() }); nodes.Add(new OSMNode { changeset = 50000000, id = (uint)nodeCount, version = 1, timestamp = DateTime.Now, user = "******", lon = lon, lat = lat, tag = tags.ToArray() }); }
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(); }
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(); }