void drawWayOptimal(ref Texture2D tex, GISway way, Vector2d chunkLow, Vector2d chunkHigh) { GISnode pprev = null; foreach (var node in way.localNodeContainer) { if (pprev == null) { pprev = node; continue; } bool czyRysowac = checkLineInBox(pprev.XY, node.XY, chunkLow, chunkHigh); if (czyRysowac) { Vector2d a0 = pprev.XY; Vector2d a1 = node.XY; pointsToBorder(ref a0, ref a1, chunkLow, chunkHigh); var p0 = new Vector2Int(); p0.x = (int)((pprev.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * tex.width); p0.y = (int)((pprev.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * tex.height); var p1 = new Vector2Int(); p1.x = (int)((node.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * tex.width); p1.y = (int)((node.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * tex.height); drawLine(ref tex, p0, p1, globalColor); } //koniec pprev = node; } }
void drawWayOptimal(byte[] tex, GISway way, Vector2d chunkLow, Vector2d chunkHigh) { GISnode pprev = null; foreach (var node in way.localNodeContainer) { if (pprev == null) { pprev = node; continue; } bool czyRysowac = checkLineInBox(pprev.XY, node.XY, chunkLow, chunkHigh); if (czyRysowac) { Vector2d a0 = pprev.XY; Vector2d a1 = node.XY; var p0 = new Vector2Int(); p0.x = (int)((pprev.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * 256); p0.y = (int)((pprev.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * 256); var p1 = new Vector2Int(); p1.x = (int)((node.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * 256); p1.y = (int)((node.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * 256); drawLine(tex, p0, p1, new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); } //koniec pprev = node; } }
void drawPointOptimal(byte[] tex, GISnode node, Vector2d chunkLow, Vector2d chunkHigh) { Vector2d a1 = node.XY; var p1 = new Vector2Int(); p1.x = (int)((node.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * 256); p1.y = (int)((node.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * 256); drawPoint(tex, p1, new Vector4(1.0f, 1.0f, 0.0f, 1.0f)); //koniec }
void drawWay(ref Texture2D tex, GISway way, Vector2d chunkLow, Vector2d chunkHigh) { GISnode prev = null; Vector2d?pprev = null; bool renderPrev = false; float thickness = 10; foreach (var node in way.localNodeContainer) { var p = new Vector2d(); p.x = (node.XY.x - chunkLow.x) / (chunkHigh.x - chunkLow.x) * 256.0; p.y = (node.XY.y - chunkLow.y) / (chunkHigh.y - chunkLow.y) * 256.0; //if (prev == null) {prev = node; continue;} if (((p.x >= 0 && p.y >= 0 && p.x < 256 && p.y < 256) || renderPrev) && pprev != null) { //punkt node jest w chunku for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { bool rysuj = GISparser.lineChecker((Vector2d)pprev, p, new Vector2d(x, y), thickness); if (rysuj) { tex.SetPixel(x, y, Color.black); } } } //koniec renderPrev = true; } else { renderPrev = false; } pprev = p; } }
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); }