public void init(string path) { gisdata = GISparser.LoadOSM(path); this.clearCache(); map.clearSegmentCache(); /*qt = new GISquadtree(null); * qt.size = new Vector2d(1, 1); * qt.position = new Vector2d(0, 0); * foreach (var way in gisdata.wayContainer) * { * qt.insert(way); * } */ }
public void init(string path) { gisdata = GISparser.LoadOSM(path); this.clearCache(); map.clearSegmentCache(); uzytecznePunkty = new List <GISnode>(); dostepneNazwy = new Dictionary <string, string>(); foreach (var node in gisdata.nodeContainer) { string output = null; node.tags.TryGetValue("amenity", out output); if (output != null) { uzytecznePunkty.Add(node); try { dostepneNazwy.Add(output, output); } catch { } } } }
//qt = new GISquadtree(null); public void loadFile(string text) { gisdata = GISparser.LoadOSM(text); }
public static GISdata LoadOSM(string path) { GISdata loadedData = new GISdata(); osm Osm = new osm(); //najpierw ładujemy ten osm który zawiera wszystkie dane XmlSerializer serializer = new XmlSerializer(typeof(osm)); StreamReader reader = new StreamReader(path); Osm = (osm)serializer.Deserialize(reader); reader.Close(); osmNode[] osmNodes = Osm.node; osmWay[] osmWays = Osm.way; GISnode currentNode = null; GISway currentWay = null; double minLat = double.MaxValue; double maxLat = double.MinValue; double minLon = double.MaxValue; double maxLon = double.MinValue; Dictionary <long, GISnode> nodeDic = new Dictionary <long, GISnode>(); //wczytujemy najpierw nody bo są potrzebne przy drogach foreach (osmNode node in osmNodes) { double currentLat = double.Parse(node.lat, CultureInfo.InvariantCulture); double currentLon = double.Parse(node.lon, CultureInfo.InvariantCulture); //aktualny node tworzony - id, współrzędne currentNode = new GISnode(Convert.ToInt64(node.id), currentLat, currentLon); //sprawdzamy czy ma tagi if (node.tag != null) { foreach (tag nodeTag in node.tag) { //dodajemy każdy tag do słownika currentNode.tags.Add(nodeTag.k, nodeTag.v); } } //ustawiamy visibility i dodajemy currentNode.visible = Convert.ToBoolean(node.visible); loadedData.nodeContainer.Add(currentNode); nodeDic.Add(currentNode.id, currentNode); if (currentLat > maxLat) { maxLat = currentLat; } if (currentLon > maxLon) { maxLon = currentLon; } if (currentLat < minLat) { minLat = currentLat; } if (currentLon < minLon) { minLon = currentLon; } } foreach (osmWay way in osmWays) { //aktualny way tworzony - tylko id currentWay = new GISway(Convert.ToInt64(way.id)); //sprawdzamy czy ma tagi if (way.tag != null) { foreach (tag wayTag in way.tag) { //dodajemy tagi currentWay.tags.Add(wayTag.k, wayTag.v); } } //przechodzimy się po wszystkich nodach waywa foreach (osmWayND wayNode in way.nd) { //szukamy w nodach już dodanych tego aktualnego (żeby była referencja) i dodajemy //GISnode node = loadedData.nodeContainer.Find(i => i.id == Convert.ToInt64(wayNode.@ref));//nieefektywne gówno GISnode node = null; nodeDic.TryGetValue(Convert.ToInt64(wayNode.@ref), out node); if (node == null) { Debug.LogWarning("Duży problem z plikiem OSM"); } currentWay.localNodeContainer.Add(node); } //ustawiamy visibility i dodajemy currentWay.visible = Convert.ToBoolean(way.visible); loadedData.wayContainer.Add(currentWay); } loadedData.maxLat = maxLat; loadedData.maxLon = maxLon; loadedData.minLat = minLat; loadedData.minLon = minLon; return(loadedData); }
public void fillHeatMap(Vector2d min, Vector2d max, GISdata data, string key, string value) { rend = GetComponent <SpriteRenderer>(); tex = new Texture2D(resolution.x, resolution.y); var maxD = GISparser.LatlonToXY(new Vector2d(data.maxLat, data.maxLon)); var minD = GISparser.LatlonToXY(new Vector2d(data.minLat, data.minLon)); maxL = max; minL = min; float[,] heatmap = new float[resolution.x, resolution.y]; float maxOdl = 255; float minOdl = 10000; foreach (var node in data.nodeContainer) { try { if (node.tags[key] == value) { minOdl = 10000; Vector2Int pos = XYtoPixel(GISparser.LatlonToXY(node.latlon)); float[,] heatmapLocal = new float[resolution.x, resolution.y]; //heatmapLocal[pos.x, pos.y] = 255; for (int y = 0; y < resolution.y; ++y) { for (int x = 0; x < resolution.x; ++x) { float odl = 1000 - Mathf.Sqrt((pos.x - x) * (pos.x - x) + (pos.y - y) * (pos.y - y)); //odl = Mathf.Sqrt(odl); if (odl > maxOdl) { maxOdl = odl; } heatmapLocal[x, y] = odl; } } for (int y = 0; y < resolution.y; ++y) { for (int x = 0; x < resolution.x; ++x) { if (heatmapLocal[x, y] > heatmap[x, y]) { heatmap[x, y] = heatmapLocal[x, y]; } if (heatmap[x, y] < minOdl) { minOdl = heatmap[x, y]; } } } } } catch { } } for (int y = 0; y < resolution.y; ++y) { for (int x = 0; x < resolution.x; ++x) { heatmap[x, y] = (heatmap[x, y] - minOdl) / (maxOdl - minOdl); heatmap[x, y] = 1 - heatmap[x, y]; Color c = new Color(heatmap[x, y], 0, heatmap[x, y]); tex.SetPixel(x, y, c); } } tex.filterMode = FilterMode.Point; tex.Apply(); Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f); rend.sprite = newSprite; }
public void fillTexture(Vector2d min, Vector2d max, GISdata data) { rend = GetComponent <SpriteRenderer>(); tex = new Texture2D(resolution.x, resolution.y); var maxD = GISparser.LatlonToXY(new Vector2d(data.maxLat, data.maxLon)); var minD = GISparser.LatlonToXY(new Vector2d(data.minLat, data.minLon)); maxL = max; minL = min; /*if (maxD.x < max.y) return; * if (maxD.y < max.y) return; * * if (minD.x > min.y) return; * if (minD.y > min.y) return;*/ /*for (int y = 0; y < resolution.y; ++y) * { * for (int x = 0; x < resolution.x; ++x) * { * * * * tex.SetPixel(x, y, randomColor()); * } * }*/ foreach (var way in data.wayContainer) { Color color = Color.black; Vector2d pos0 = Vector2d.zero; bool first = true; try { if (way.tags["highway"] == "residential") { color = Color.red; } if (way.tags["highway"] == "living_street") { color = Color.red; } if (way.tags["highway"] == "primary") { color = Color.red; } if (way.tags["highway"] == "secondary") { color = Color.red; } if (way.tags["highway"] == "tertiary") { color = Color.red; } if (way.tags["highway"] == "service") { color = Color.red; } if (way.tags["highway"] == "track") { color = Color.red; } if (way.tags["highway"] == "motorway") { color = Color.red; } if (way.tags["highway"] == "road") { color = Color.red; } if (way.tags["highway"] == "path") { color = Color.red; } if (way.tags["highway"] == "motorway") { color = Color.red; } if (way.tags["highway"] == "motorway") { color = Color.red; } if (way.tags["route"] == "road") { color = Color.red; } } catch { } foreach (var node in way.localNodeContainer) { var pos1 = GISparser.LatlonToXY(node.latlon); if (first) { first = false; pos0 = pos1; continue; } var pixel0 = XYtoPixel(pos0); var pixel1 = XYtoPixel(pos1); double thickness = 0.00001; double pixelSize = ((0.5) / (double)(resolution.y)) * (maxL.y - minL.y); int pthick = (int)(pixelSize / thickness); int pixminx = 0; int pixminy = 0; int pixmaxx = 0; int pixmaxy = 0; if (pixel0.x < pixel1.x) { pixminx = pixel0.x - pthick; pixmaxx = pixel1.x + pthick; } else { pixminx = pixel1.x - pthick; pixmaxx = pixel0.x + pthick; } if (pixel0.y < pixel1.y) { pixminy = pixel0.y - pthick; pixmaxy = pixel1.y + pthick; } else { pixminy = pixel1.y - pthick; pixmaxy = pixel0.y + pthick; } if (pixminx < 0) { pixminx = 0; } if (pixminy < 0) { pixminy = 0; } if (pixmaxx >= resolution.x) { pixmaxx = resolution.x; } if (pixmaxy >= resolution.y) { pixmaxy = resolution.y; } for (int y = pixminy; y <= pixmaxy; ++y) { for (int x = pixminx; x < pixmaxx; ++x) { bool check = GISparser.lineChecker(pos0, pos1, pixelToXY(new Vector2Int(x, y)), (float)thickness); if (check) { tex.SetPixel(x, y, color); } } } pos0 = pos1; } } tex.filterMode = FilterMode.Point; tex.Apply(); Sprite newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f); rend.sprite = newSprite; }
public void loadFile(string text) { gisdata = GISparser.LoadOSM(text); setPlaneSize(); setPlane(); }