Пример #1
0
    public void ParseOSMXml(object sender, DownloadStringCompletedEventArgs args)
    {
        string result = args.Result;

        if (result == null)
        {
            //UnityEngine.Debug.Log("No Result");
            //retry--;
            //if (retry > 0)
            //{
            UnityEngine.Debug.Log("retry... ");// + retry);
            DownloadOSMString();
            //}
            return;
        }
        if (args.Cancelled)
        {
            //UnityEngine.Debug.Log("Query got canceled");
            //retry--;
            //if (retry > 0)
            //{
            UnityEngine.Debug.Log("retry... ");// + retry);
            DownloadOSMString();
            //}
        }
        //UnityEngine.Debug.Log(result);

#if UNITY_EDITOR
        //File.WriteAllBytes(logPath, Encoding.UTF8.GetBytes(result));
#endif

        OSM = new OSMData(new MemoryStream(Encoding.UTF8.GetBytes(result)));
        OnQueryDone();
    }
Пример #2
0
    public Bridge(Intersection from, Intersection to, OSMWay way, OSMData osm)
    {
        this.from = from;
        this.to   = to;
        this.way  = way;
        //this.osm = osm;


        //Calculate pathway for street

        //Polyline pathway = new Polyline();

        //OSMNode node;

        //foreach (long nodeId in way.GetWayNodesFromTo(from, to))
        //{
        //    if (osm.nodes.TryGetValue(nodeId, out node))
        //    {
        //        pathway.Add(new Vertex(node + Vector3.up * 0.1f));
        //    }
        //}

        //pathway = pathway.InterpolateHeights();

        //this.street = new Street(from, to, way, osm, pathway);
        this.street = new Street(from, to, way, osm);
    }
Пример #3
0
    private static void ReadTrailNode(OSMData trailData, Dictionary <long, OSMNode> wayNodes, XmlElement node)
    {
        OSMNode trailNode = new OSMNode();

        if (node.ChildNodes.Count > 0)
        {
            string iconName = "";
            string name     = "";
            foreach (XmlElement childNode in node.ChildNodes)
            {
                if (childNode.LocalName.Equals(tagElement) && childNode.GetAttribute("k").Equals(iconKeyValue))
                {
                    iconName = childNode.GetAttribute("v");
                }
                else if (childNode.LocalName.Equals(tagElement) && childNode.GetAttribute("k").Equals(POIName))
                {
                    name = childNode.GetAttribute("v");
                }
            }
            if (!iconName.Equals("") && !name.Equals(""))
            {
                POINode poiNode = new POINode(iconName, name);
                poiNode.id  = long.Parse(node.GetAttribute(idAttribute));
                poiNode.lat = float.Parse(node.GetAttribute(latAttribute));
                poiNode.lon = float.Parse(node.GetAttribute(lonAttribute));
                trailData.AddPOI(poiNode);
            }
        }

        trailNode.id  = long.Parse(node.GetAttribute(idAttribute));
        trailNode.lat = float.Parse(node.GetAttribute(latAttribute));
        trailNode.lon = float.Parse(node.GetAttribute(lonAttribute));

        wayNodes.Add(trailNode.id, trailNode);
    }
Пример #4
0
 private void GenerateTrails(OSMData osmData)
 {
     foreach (Trail trail in osmData.trails)
     {
         trailDisplay.trailColor = trail.color;
         trailDisplay.trailName  = trail.trailName;
         trailDisplay.DisplayNodes(TranslateTrail(trail));
     }
 }
Пример #5
0
 private void GeneratePoiNodes(OSMData osmData)
 {
     foreach (POINode poiNode in osmData.poiNodes)
     {
         DisplayNode displayNode = ChangeLatLonToDisplayNode(poiNode.lon, poiNode.lat, mapData);
         Icon        icon        = iconHandler.SelectIcon(poiNode.icon);
         poiDisplay.DisplayPOINode(displayNode, icon, poiNode.name);
     }
 }
Пример #6
0
    public bool FirstInBounds(OSMBoundingBox box, OSMData osm)
    {
        OSMNode node;

        if (osm.nodes.TryGetValue(WayNodes[0], out node))
        {
            return(node.IsInBounds(box));
        }
        return(false);
    }
Пример #7
0
        private string GetValue(OSMData osmData)
        {
            PropertyInfo property = GetProperty(osmData);

            if (property == null)
            {
                return(null);
            }
            object value = property.GetValue(osmData.Address);

            return(value?.ToString());
        }
Пример #8
0
 private void GenerateRivers(OSMData osmData)
 {
     foreach (River r in osmData.rivers)
     {
         List <DisplayNode> riverNodes = new List <DisplayNode>();
         for (int i = 0; i < r.nodeList.Count; i++)
         {
             riverNodes.Add(ChangeLatLonToDisplayNode(r.nodeList[i].lon, r.nodeList[i].lat, mapData));
         }
         areaDisplay.AddRiver(riverNodes);
     }
 }
Пример #9
0
 private void GenerateAreas(OSMData osmData)
 {
     foreach (Area a in osmData.areas)
     {
         List <DisplayNode> areaBounds = new List <DisplayNode>();
         for (int i = 0; i < a.nodeList.Count; i++)
         {
             areaBounds.Add(ChangeLatLonToDisplayNode(a.nodeList[i].lon, a.nodeList[i].lat, mapData));
         }
         areaDisplay.AddArea(a.color, areaBounds);
     }
 }
Пример #10
0
    public Street(Intersection from, Intersection to, OSMWay way, OSMData osm, Polyline pathway)
    {
        this.from = from;
        this.to   = to;
        this.way  = way;
        //this.osm = osm;

        //Creation of the pathway is handled outside (by bridge)
        this.pathway = pathway;
        centerLine   = new Polyline(pathway.Vertices);


        //Needs centerLine, therefore after that
        from.AddStreet(this);
        to.AddStreet(this);

        /*Default is oneway=no, except for highway=motorway which implies oneway=yes. junction=roundabout also implies oneway=yes. highway=motorway_link has been a discussion a few times before, and it's best to add the oneway=* tag on those all the time, one way or not. --Eimai 12:59, 8 January 2009 (UTC)
         * Should this be indicated in the page? --Seav 10:49, 14 January 2009 (UTC)
         * Other implicit oneway=yes cases are: highway=motorway_link, highway=trunk_link and highway=primary_link. --Beldin 21:55, 22 April 2009 (UTC)*/

        if (way.Tags.ContainsKey("oneway"))
        {
            if (way.Tags["oneway"] == "yes" || way.Tags["oneway"] == "1" || way.Tags["oneway"] == "true")
            {
                isOneWay = true;
            }
        }
        if (way.Tags.ContainsKey("highway"))
        {
            if (way.Tags["highway"] == "motorway")
            {
                isOneWay = true;
            }
        }
        if (way.Tags.ContainsKey("junction"))
        {
            if (way.Tags["junction"] == "roundabout")
            {
                isOneWay = true;
            }
        }

        if (isOneWay)
        {
            carriageways[0] = new CarriageWay(way);
        }
        else
        {
            carriageways[0] = new CarriageWay(way);
            carriageways[1] = new CarriageWay(way);
        }
    }
Пример #11
0
        private async Task <string> GetSubFolderFromAction()
        {
            Coordinates coordinates = GetCoordinates();
            string      result      = null;

            if (coordinates != null && coordinates.IsValid())
            {
                OSMData osmData = await _geoService.GetOsmData(coordinates);

                result = GetValue(osmData);
            }
            return(result ?? await ActionHelpers.ExecuteWithAlternative(_model.Alternative, Config.UserConfig.ByCityDefaultText));
        }
Пример #12
0
        private async Task <OSMData> CallOsmData(Coordinates coordinates)
        {
            string osmDataResponse = await
                                     CallUrl(
                $"https://nominatim.openstreetmap.org/reverse?format=json&lat={coordinates.Latitude}&lon={coordinates.Longitude}");

            OSMData data = ToOSMData(osmDataResponse);

            Config.LastCallToOSM = DateTime.Now;
            await GetAmenityInfo(data);

            return(data);
        }
Пример #13
0
    public static OSMData ReadOSMData(string path)
    {
        XmlDocument xmlDoc = new XmlDocument();

        ReadXmlDocument(path, xmlDoc);
        XmlElement rootNode = xmlDoc.DocumentElement;

        Dictionary <long, OSMNode> wayNodes = new Dictionary <long, OSMNode>();
        Dictionary <long, OSMway>  ways     = new Dictionary <long, OSMway>();
        OSMData osmData = new OSMData();

        foreach (XmlElement node in rootNode)
        {
            string childNodeType = node.LocalName;
            switch (childNodeType)
            {
            case wayElement:
                ReadWay(ways, node);
                break;

            case nodeElement:
                ReadTrailNode(osmData, wayNodes, node);
                break;

            default:
                break;
            }
        }



        foreach (OSMway way in ways.Values)
        {
            FillInWayNodeLatLon(way, wayNodes);

            if (way.IsArea())
            {
                osmData.AddArea(new Area(way, way.LandUse()));
            }
            else if (way.IsRiver())
            {
                osmData.AddRiver(new River(way));
            }
            else
            {
                osmData.AddTrail(new Trail(way));
            }
        }
        return(osmData);
    }
Пример #14
0
        private void SaveToFile(Coordinates coordinates, OSMData osmData)
        {
            var filePath = $@"{_path}\{coordinates}.log";

            if (File.Exists(filePath))
            {
                return;
            }

            StreamWriter writer = new StreamWriter(filePath, false);

            writer.WriteLine(JsonConvert.SerializeObject(osmData));
            writer.Close();
        }
Пример #15
0
        public async Task <OSMData> GetOsmData(Coordinates coordinates)
        {
            if (!coordinates.IsValid())
            {
                return(Config.Get <OSMData>());
            }

            OSMData data = ReadFromFile(coordinates);

            if (data != null)
            {
                return(data);
            }

            data = await CallOsmData(coordinates);

            SaveToFile(coordinates, data);
            return(data);
        }
Пример #16
0
    public void GenerateOSMObjects(MapGenerator mapGenerator, string mapName)
    {
        mapData      = mapGenerator.mapData;
        trailDisplay = this.GetComponent <TrailDisplay> ();
        poiDisplay   = this.GetComponent <POIDisplay> ();
        iconHandler  = this.GetComponent <IconHandler>();
        areaDisplay  = this.GetComponent <AreaDisplay>();
        OSMData osmData = DataImporter.GetOSMData(mapName);

        trailDisplay.mapData = mapData;
        poiDisplay.mapData   = mapData;

        iconHandler.generateIconDictionary();
        GenerateTrails(osmData);
        GeneratePoiNodes(osmData);
        GenerateAreas(osmData);
        GenerateRivers(osmData);
        areaDisplay.displayAreas();
    }
Пример #17
0
    public River(OSMRelation rel, OSMData osm, ModularMesh mesh)
    {
        Debug.Log("RIVERBANKS");
        //layout = new Polyline();

        //OSMNode node;

        ////Discard last waynode if its the same as first
        //if (way.WayNodes[0] == way.WayNodes[way.WayNodes.Count - 1])
        //{
        //    for (int i = 0; i < way.WayNodes.Count - 1; i++)
        //    {
        //        if (nodes.TryGetValue(way.WayNodes[i], out node))
        //        {
        //            Vector3 pos = new Vector3(node.X, SRTMHeightProvider.GetInterpolatedHeight(node.Latitude, node.Longitude), node.Z);
        //            layout.Add(new Vertex(pos, mesh));
        //        }

        //    }
        //}
        //else
        //{
        //    for (int i = 0; i < way.WayNodes.Count; i++)
        //    {
        //        if (nodes.TryGetValue(way.WayNodes[i], out node))
        //        {
        //            Vector3 pos = new Vector3(node.X, SRTMHeightProvider.GetInterpolatedHeight(node.Latitude, node.Longitude), node.Z);
        //            layout.Add(new Vertex(pos, mesh));
        //        }

        //    }
        //}

        ////layout.MakeClockwise();

        //leveledLayout = layout.LevelUp(null);
        //leftBorder = leveledLayout.Inset(-50f, mesh);
        //rightBorder = leveledLayout.Inset(50f, mesh);

        //area = new TriangleStrip(leftBorder, rightBorder, mesh, MaterialManager.GetMaterial("diffuseBlue"));
    }
Пример #18
0
    public Building(OSMWay way, OSMData osm)
    {
        if (way.Tags.ContainsKey("building:height"))
        {
            float.TryParse(way.Tags["building:height"], out height);
        }
        else
        {
            height = Random.Range(20f, 40f);
        }

        layout = new Polygon();

        OSMNode node;

        //Discard last waynode if its the same as first
        if (way.WayNodes[0] == way.WayNodes[way.WayNodes.Count - 1])
        {
            for (int i = 0; i < way.WayNodes.Count - 1; i++)
            {
                if (osm.nodes.TryGetValue(way.WayNodes[i], out node))
                {
                    Vector3 pos = new Vector3(node.X, SRTMHeightProvider.GetInterpolatedHeight(node.Latitude, node.Longitude), node.Z);
                    layout.Add(new Vertex(pos));
                }
            }
        }
        else
        {
            for (int i = 0; i < way.WayNodes.Count; i++)
            {
                if (osm.nodes.TryGetValue(way.WayNodes[i], out node))
                {
                    Vector3 pos = new Vector3(node.X, SRTMHeightProvider.GetInterpolatedHeight(node.Latitude, node.Longitude), node.Z);
                    layout.Add(new Vertex(pos));
                }
            }
        }

        layout.MakeClockwise();
    }
Пример #19
0
        private async Task GetAmenityInfo(OSMData data)
        {
            string response = await CallUrl($"https://api.openstreetmap.org/api/0.6/{data.OsmType}/{data.OsmId}");

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(response);
            if (xml.DocumentElement == null)
            {
                return;
            }
            var amenity     = xml.DocumentElement.SelectSingleNode("//*[@k='amenity']") ?? xml.DocumentElement.SelectSingleNode("//*[@k='tourism']");
            var amenityName = xml.DocumentElement.SelectSingleNode("//*[@k='name']");

            if (data.Address == null)
            {
                data.Address = new Address();
            }
            data.Address.AmenityType = amenity?.Attributes?["v"]?.Value;
            data.Address.AmenityName = amenityName?.Attributes?["v"]?.Value;

            Config.LastCallToOSM = DateTime.Now;
        }
Пример #20
0
 public TrafficSignal(OSMNode node, OSMData osm)
 {
     position = new Vertex(node);
 }
Пример #21
0
        private PropertyInfo GetProperty(OSMData osmData)
        {
            var osmType = osmData.Address.GetType();

            return(osmType.GetProperty(_model.Type.Type));
        }
Пример #22
0
    public Street(Intersection from, Intersection to, OSMWay way, OSMData osm)
    {
        this.from = from;
        this.to   = to;
        this.way  = way;
        //this.osm = osm;

        OSMNode node;

        pathway = new Polyline();

        foreach (long nodeId in way.GetWayNodesFromTo(from, to))
        {
            if (osm.nodes.TryGetValue(nodeId, out node))
            {
                pathway.Add(new Vertex(node + Vector3.up * 0.1f));
            }
        }

        centerLine = new Polyline(pathway.Vertices);


        //Needs centerLine, therefore after that
        from.AddStreet(this);
        to.AddStreet(this);

        /*Default is oneway=no, except for highway=motorway which implies oneway=yes. junction=roundabout also implies oneway=yes. highway=motorway_link has been a discussion a few times before, and it's best to add the oneway=* tag on those all the time, one way or not. --Eimai 12:59, 8 January 2009 (UTC)
         * Should this be indicated in the page? --Seav 10:49, 14 January 2009 (UTC)
         * Other implicit oneway=yes cases are: highway=motorway_link, highway=trunk_link and highway=primary_link. --Beldin 21:55, 22 April 2009 (UTC)*/


        if (way.Tags.ContainsKey("oneway"))
        {
            if (way.Tags["oneway"] == "yes" || way.Tags["oneway"] == "1" || way.Tags["oneway"] == "true")
            {
                isOneWay = true;
            }
        }
        if (way.Tags.ContainsKey("highway"))
        {
            if (way.Tags["highway"] == "motorway")
            {
                isOneWay = true;
            }
        }
        if (way.Tags.ContainsKey("junction"))
        {
            if (way.Tags["junction"] == "roundabout")
            {
                isOneWay = true;
            }
        }

        if (isOneWay)
        {
            carriageways[0] = new CarriageWay(way);
        }
        else
        {
            carriageways[0] = new CarriageWay(way);
            carriageways[1] = new CarriageWay(way);
        }
    }
Пример #23
0
 public Water(OSMWay way, OSMData osm)
 {
     this.way = way;
     this.osm = osm;
 }
Пример #24
0
 public void Setup()
 {
     osmData   = OSMDataImporter.ReadOSMData("Assets/Resources/testData/testTrailData.xml");
     precision = 0.0001F;
 }
    public void BuildMap()
    {
        ClearMap();
        if (reader == null)
        {
            reader = GetComponent <OSMReader>();
        }
        if (data == null)
        {
            data = reader.GetOSMData();
        }
        foreach (Way way in data.ways)
        {
            GameObject go;
            Vector3[]  points = new Vector3[way.nodes.Count];
            for (int i = 0; i < way.nodes.Count; i++)
            {
                points[i] = data.nodes[way.nodes[i]].GetPosition();
            }
            switch (way.type)
            {
            case WayType.line_thin:
                go = Instantiate(line_thin, linethinParent);
                go.GetComponent <Line_thin>().UpdateLineRenderer(points);
                go.GetComponent <Line_thin>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.stop_line:
                go = Instantiate(stop_line, stoplineParent);
                go.GetComponent <Stop_line>().UpdateLineRenderer(points);
                go.GetComponent <Stop_line>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.traffic_light:
                Vector3 trafficPos = (points[0] + points[1]) / 2;
                go = Instantiate(traffic_light, trafficlightParent);
                go.transform.position = trafficPos;
                go.GetComponent <Traffic_light>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.traffic_sign:
                go = Instantiate(traffic_sign, trafficsignParent);
                go.GetComponent <Traffic_sign>().UpdateLineRenderer(points);
                go.GetComponent <Traffic_sign>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            default:
                break;
            }
        }

        foreach (Relation relation in data.relations)
        {
            if (relation.subType == RelationSubType.traffic_light)
            {
                Vector3       targetPos = new Vector3();
                Traffic_light light     = new Traffic_light();
                foreach (Member member in relation.menbers)
                {
                    if (MapDictionary.TryGetValue(member.refID, out MapElement element))
                    {
                        if (member.roleType == RoleType.ref_line)
                        {
                            Line line = element.GetComponent <Line>();
                            targetPos  = line.lineRenderer.GetPosition(0) + line.lineRenderer.GetPosition(1);
                            targetPos *= 0.5f;
                        }
                        else if (member.roleType == RoleType.refers)
                        {
                            light = element.GetComponent <Traffic_light>();
                        }
                    }
                }
                targetPos.y = light.transform.position.y;
                light.transform.LookAt(targetPos);
            }
        }
    }