Ejemplo n.º 1
0
 /// <summary>
 /// On way found.
 /// </summary>
 /// <param name="way">Way.</param>
 /// <param name="rawData">Raw data.</param>
 /// <param name="infos">Infos.</param>
 protected void OnWayFound(OSMWay way, byte[] rawData, ElementDebugInfos infos)
 {
     if (this.FoundWayRaw != null)
     {
         this.FoundWayRaw(way, rawData, infos);
     }
 }
Ejemplo n.º 2
0
    public static void CreateBuilding(OSMWay way, OSMapInfo mapInfo, Material material)
    {
        // Create an instance of the object and place it in the centre of its points
        GameObject go          = new GameObject();
        Vector3    localOrigin = GetCenter(way, mapInfo);

        go.transform.position = localOrigin - mapInfo.Bounds.Center;

        // Add the mesh filter and renderer components to the object
        MeshFilter   mf = go.AddComponent <MeshFilter>();
        MeshRenderer mr = go.AddComponent <MeshRenderer>();

        // Apply the material
        mr.material = material;

        // Create the collections for the object's vertices, indices, UVs etc.
        List <Vector3> vectors = new List <Vector3>();
        List <Vector3> normals = new List <Vector3>();
        List <Vector2> uvs     = new List <Vector2>();
        List <int>     indices = new List <int>();

        // Call the child class' object creation code
        OnObjectCreated(mapInfo, way, localOrigin, vectors, normals, uvs, indices);

        // Apply the data to the mesh
        mf.mesh.vertices  = vectors.ToArray();
        mf.mesh.normals   = normals.ToArray();
        mf.mesh.triangles = indices.ToArray();
        mf.mesh.uv        = uvs.ToArray();
    }
Ejemplo n.º 3
0
        public static void SaveCandidateIncomingConnections(CandidatePoint candidate, string filename)
        {
            int   counter = -1;
            OSMDB result  = new OSMDB();

            OSMNode osmCandidate = new OSMNode(counter--, candidate.MapPoint.Latitude, candidate.MapPoint.Longitude);

            osmCandidate.Tags.Add(new OSMTag("observation", candidate.ObservationProbability.ToString()));
            osmCandidate.Tags.Add(new OSMTag("time", candidate.Layer.TrackPoint.Time.ToString()));
            result.Nodes.Add(osmCandidate);
            foreach (var connection in candidate.IncomingConnections)
            {
                OSMNode from = new OSMNode(counter--, connection.From.MapPoint.Latitude, connection.From.MapPoint.Longitude);
                from.Tags.Add(new OSMTag("observation", connection.From.ObservationProbability.ToString()));
                from.Tags.Add(new OSMTag("time", connection.From.Layer.TrackPoint.Time.ToString()));
                result.Nodes.Add(from);

                OSMWay osmConnection = new OSMWay(counter--, new long[] { from.ID, osmCandidate.ID });
                osmConnection.Tags.Add(new OSMTag("transmission", connection.TransmissionProbability.ToString()));

                result.Ways.Add(osmConnection);
            }

            result.Save(filename);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// On way found.
 /// </summary>
 /// <param name="way">Way.</param>
 protected void OnWayFound(OSMWay way)
 {
     if (this.FoundWay != null)
     {
         this.FoundWay(way);
     }
 }
Ejemplo n.º 5
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);
    }
Ejemplo n.º 6
0
    public OSMData(string osmXMLpath)
    {
        XmlTextReader xmlReader = new XmlTextReader(osmXMLpath);

        xmlReader.MoveToContent();
        while (xmlReader.Read())
        {
            if (xmlReader.NodeType.Equals(XmlNodeType.Element))
            {
                switch (xmlReader.LocalName)
                {
                case "node":
                    OSMNode n = ParseOSMNode(xmlReader);
                    nodes.Add(n.Id, n);
                    break;

                case "way":
                    OSMWay way = ParseOSMWay(xmlReader);
                    ways.Add(way.Id, way);
                    break;

                case "relation":
                    OSMRelation relation = ParseOSMRelation(xmlReader);
                    relations.Add(relation.Id, relation);
                    break;

                default:
                    //ignore other nodes
                    break;
                }
            }
        }
        UnityEngine.Debug.Log("New OSMDATA: " + nodes.Count + " Nodes " + ways.Count + " Ways " + relations.Count + " Relations");
        Console.AddMessage("New OSMDATA: " + nodes.Count + " Nodes " + ways.Count + " Ways " + relations.Count + " Relations");
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of OSMRoute based on specific OSMWay
        /// </summary>
        /// <param name="way">The way that defines geomery and tags</param>
        /// <param name="roadType">The RoadType of this OSMRoute</param>
        public OSMRoad(OSMWay way, RoadType roadType) : base(way.ID)
        {
            _tags  = way.Tags;
            _nodes = new List <long>(way.Nodes);

            RoadType = roadType;

            Speed = RoadType.Speed;

            if (Tags.ContainsTag("maxspeed"))
            {
                string[] chunks       = Tags["maxspeed"].Value.Split(' ');
                double   numericSpeed = 0;
                if (double.TryParse(chunks[0], out numericSpeed))
                {
                    if (chunks.Length == 2 && chunks[1] == "mph")
                    {
                        Speed = numericSpeed * MphConversionFactor;
                    }
                    else
                    {
                        Speed = numericSpeed;
                    }
                }
            }
        }
Ejemplo n.º 8
0
    public CarriageWay(OSMWay way)
    {
        if (way.Tags["highway"] == "path" ||
            way.Tags["highway"] == "footway" ||
            way.Tags["highway"] == "pedestrian"
            )
        {
            streetMember.Add(new PathStreetMember());
        }
        else
        {
            if (way.Tags.ContainsKey("lanes"))
            {
                int lanes;
                if (int.TryParse(way.Tags["lanes"], out lanes))
                {
                    createCarLanes(lanes);
                }
            }
            else
            {
                createCarLanes(1);
            }

            //Gutter
            streetMember.Add(new Gutter());

            bool createFoot = false;
            bool createBike = false;

            if (way.Tags.ContainsKey("foot"))
            {
                if (way.Tags["foot"] == "yes" || way.Tags["foot"] == "designated" || way.Tags["foot"] == "1" || way.Tags["foot"] == "true")
                {
                    createFoot = true;
                }
            }
            if (way.Tags.ContainsKey("bicycle"))
            {
                if (way.Tags["bicycle"] == "yes" || way.Tags["bicycle"] == "designated" || way.Tags["bicycle"] == "1" || way.Tags["bicycle"] == "true")
                {
                    createBike = true;
                }
            }

            if (createFoot || createBike)
            {
                streetMember.Add(new Curb());
            }
            if (createBike)
            {
                streetMember.Add(new BikeLane());
            }
            if (createFoot)
            {
                streetMember.Add(new WalkWay());
            }
        }
    }
Ejemplo n.º 9
0
 void GetWays(XmlNodeList wayNodes)
 {
     foreach (XmlNode wayNode in wayNodes)
     {
         OSMWay way = new OSMWay(wayNode);
         ways.Add(way);
     }
 }
Ejemplo n.º 10
0
    //void Update()
    //{
    //    foreach (OSMWay w in ways)
    //    {
    //        if (w.Visible)
    //        {
    //            Color c = Color.cyan; // cyan for building
    //            if (!w.isBoundary)
    //            {
    //                c = Color.red; // red for roads
    //            }

    //            for (int i = 1; i < w.NodeIDs.Count; i++)
    //            {
    //                OSMNode p1 = nodes[w.NodeIDs[i - 1]];
    //                OSMNode p2 = nodes[w.NodeIDs[i]];

    //                Vector3 v1 = p1 - bounds.Center;
    //                Vector3 v2 = p2 - bounds.Center;

    //                Debug.DrawLine(v1, v2, c);
    //            }
    //        }
    //    }
    //}

    void GetWays(XmlNodeList xmlNodeList)
    {
        foreach (XmlNode node in xmlNodeList)
        {
            OSMWay way = new OSMWay(node);
            ways.Add(way);
        }
    }
Ejemplo n.º 11
0
 public static bool TryCreateFromOSM(OSMWay way, Tile tile)
 {
     if (way.Tags.ContainsKey("building"))
     {
         Buildings.Add(new Building(way, tile.Query.OSM), tile);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 12
0
    private static void OnObjectCreated(OSMapInfo mapInfo, OSMWay way, Vector3 origin, List <Vector3> vectors, List <Vector3> normals, List <Vector2> uvs, List <int> indices)
    {
        for (int i = 1; i < way.NodeIDs.Count; i++)
        {
            OSMNode p1 = mapInfo.Nodes[way.NodeIDs[i - 1]];
            OSMNode p2 = mapInfo.Nodes[way.NodeIDs[i]];

            Vector3 s1 = p1 - origin;
            Vector3 s2 = p2 - origin;

            Vector3 diff = (s2 - s1).normalized;
            // elongate the road a little bit
            s1 -= diff;
            s2 += diff;

            // https://en.wikipedia.org/wiki/Lane
            // According to the article, it's 3.7m in Canada
            var cross = Vector3.Cross(diff, Vector3.up) * 3.7f * way.Lanes;

            // Create points that represent the width of the road
            Vector3 v1 = s1 + cross;
            Vector3 v2 = s1 - cross;
            Vector3 v3 = s2 + cross;
            Vector3 v4 = s2 - cross;

            vectors.Add(v1);
            vectors.Add(v2);
            vectors.Add(v3);
            vectors.Add(v4);

            uvs.Add(new Vector2(0, 0));
            uvs.Add(new Vector2(1, 0));
            uvs.Add(new Vector2(0, 1));
            uvs.Add(new Vector2(1, 1));

            normals.Add(Vector3.up);
            normals.Add(Vector3.up);
            normals.Add(Vector3.up);
            normals.Add(Vector3.up);

            int idx1, idx2, idx3, idx4;
            idx4 = vectors.Count - 1;
            idx3 = vectors.Count - 2;
            idx2 = vectors.Count - 3;
            idx1 = vectors.Count - 4;

            // first triangle v1, v3, v2
            indices.Add(idx1);
            indices.Add(idx3);
            indices.Add(idx2);

            // second         v3, v4, v2
            indices.Add(idx3);
            indices.Add(idx4);
            indices.Add(idx2);
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Raises the WayRead event
        /// </summary>
        /// <param name="node">The OSMWay read from the database</param>
        protected void OnWayRead(OSMWay way)
        {
            OSMWayReadHandler temp = WayRead;

            if (temp != null)
            {
                temp(way);
            }
        }
Ejemplo n.º 14
0
 public void AddWay(OSMWay way)
 {
     if (way != null)
     {
         if (!ways.Keys.Contains(way.Id))
         {
             ways.Add(way.Id, way);
         }
     }
 }
Ejemplo n.º 15
0
 public OSMWay(OSMWay copy)
 {
     this.wayId                    = copy.wayId;
     this.roadType                 = copy.roadType;
     this.streetName               = copy.streetName;
     this.tigerCfcc                = copy.tigerCfcc;
     this.tigerCounty              = copy.tigerCounty;
     this.tigerNameBase            = copy.tigerNameBase;
     this.tigerNameDirectionSuffix = copy.tigerNameDirectionSuffix;
     this.closedShape              = copy.closedShape;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Get length of the OSMWay in meters
        /// </summary>
        /// <param name="way"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        static double GetLength(OSMWay way, OSMDB db)
        {
            double result = 0;

            for (int i = 0; i < way.Nodes.Count - 1; i++)
            {
                result += LK.GeoUtils.Calculations.GetDistance2D(db.Nodes[way.Nodes[i]], db.Nodes[way.Nodes[i + 1]]);
            }

            return(result);
        }
    public Vector3 GetCenter(OSMWay way)
    {
        Vector3 total = Vector3.zero;

        foreach (var id in way.NodeIDs)
        {
            total += map.nodes[id];
        }

        return(total / way.NodeIDs.Count);
    }
Ejemplo n.º 18
0
    private static Vector3 GetCenter(OSMWay way, OSMapInfo mapInfo)
    {
        Vector3 total = Vector3.zero;

        foreach (ulong nodeID in way.NodeIDs)
        {
            total += mapInfo.Nodes[nodeID];
        }

        return(total / way.NodeIDs.Count);
    }
Ejemplo n.º 19
0
    private static Vector3 CalcWayCenter(OSMapInfo mapInfo, OSMWay pSpace)
    {
        Vector3 wayCenter = new Vector3();

        foreach (ulong nodeId in pSpace.NodeIDs)
        {
            wayCenter += mapInfo.Nodes[nodeId].WorldCoord;
        }
        wayCenter /= pSpace.NodeIDs.Count;
        return(wayCenter);
    }
Ejemplo n.º 20
0
        /// <summary>
        /// Exctract nodes from the way and adds them into UsedNodes list
        /// </summary>
        /// <param name="way"></param>
        void ExtractUsedNodes(OSMWay way)
        {
            foreach (long nodeID in way.Nodes)
            {
                if (_usedNodes.ContainsKey(nodeID) == false)
                {
                    _usedNodes.Add(nodeID, new List <long>());
                }

                _usedNodes[nodeID].Add(way.ID);
            }
        }
Ejemplo n.º 21
0
 public static bool TryCreateFromOSM(OSMWay way, Tile tile)
 {
     if (way.Tags.ContainsKey("natural"))
     {
         if (way.Tags["natural"] == "water")
         {
             waters.Add(new Water(way, tile.Query.OSM), tile);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Saves path to the OSMDB
        /// </summary>
        /// <param name="path">The list of polylines that represent matched path</param>
        /// <returns>OSMDB with path converted to the OSM format</returns>
        public OSMDB SaveToOSM(IList <Polyline <IPointGeo> > path)
        {
            _db        = new OSMDB();
            _dbCounter = -1;

            IPointGeo lastPoint = null;
            OSMNode   node      = null;

            foreach (var line in path)
            {
                if (line.Nodes.Count == 0)
                {
                    continue;
                }

                if (line.Nodes.Count == 1)
                {
                    throw new Exception();
                }

                OSMWay way = new OSMWay(_dbCounter--);
                way.Tags.Add(new OSMTag("way-id", ((PolylineID)line).WayID.ToString()));
                way.Tags.Add(new OSMTag("order", (_db.Ways.Count + 1).ToString()));
                _db.Ways.Add(way);
                foreach (var point in line.Nodes)
                {
                    if (point != lastPoint)
                    {
                        lastPoint = point;
                        PointEx pt = (PointEx)point;

                        node = new OSMNode(_dbCounter--, pt.Latitude, pt.Longitude);
                        if (pt.NodeID != 0)
                        {
                            node.Tags.Add(new OSMTag("node-id", pt.NodeID.ToString()));
                        }
                        if (pt.Time != DateTime.MinValue)
                        {
                            node.Tags.Add(new OSMTag("time", pt.Time.ToString()));
                        }
                        if (pt.Crossroad)
                        {
                            node.Tags.Add(new OSMTag("crossroad", "yes"));
                        }

                        _db.Nodes.Add(node);
                    }
                    way.Nodes.Add(node.ID);
                }
            }

            return(_db);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Callback function for OSMXmlDataReader, checks whether the way matches desired RoadTypes and adds the matched road into DB
 /// </summary>
 /// <param name="way">The way read form the OSM file</param>
 void WayRead(OSMWay way)
 {
     foreach (RoadType roadType in _acceptedRoads)
     {
         if (roadType.Match(way) && _ways.ContainsKey(way.ID) == false)
         {
             ExtractUsedNodes(way);
             _storage.Ways.Add(new OSMRoad(way, roadType));
             _ways.Add(way.ID, way.ID);
         }
     }
 }
Ejemplo n.º 24
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);
        }
    }
Ejemplo n.º 25
0
    private void DrawWay(OSMapInfo mapInfo, OSMWay way, Color color)
    {
        for (int i = 1; i < way.NodeIDs.Count; i++)
        {
            OSMNode p1 = mapInfo.Nodes[way.NodeIDs[i - 1]];
            OSMNode p2 = mapInfo.Nodes[way.NodeIDs[i]];

            Vector3 v1 = p1 - mapInfo.Bounds.Center;
            Vector3 v2 = p2 - mapInfo.Bounds.Center;

            Debug.DrawLine(v1, v2, color);
        }
    }
Ejemplo n.º 26
0
 private void ConnectHighwayNodesFromWay(OSMWay osmWay)
 {
     if (osmWay.Visible && osmWay.NodeIDs.Count > 0)
     {
         HighwayNode currentNode = NavInfo.Nodes[osmWay.NodeIDs[0]];
         for (int i = 1; i < osmWay.NodeIDs.Count; ++i)
         {
             HighwayNode nextNode = NavInfo.Nodes[osmWay.NodeIDs[i]];
             currentNode.Neighbours.Add(nextNode);
             nextNode.Neighbours.Add(currentNode);
             currentNode = nextNode;
         }
     }
 }
Ejemplo n.º 27
0
        private void WriteWay(OSMWay way, out byte[] writtenData)
        {
            if (!this._waysStarted)
            {
                this.Reset();
                this._stream.WriteByte((byte)O5MFileByteMarker.Reset);
                this._waysStarted = true;
            }

            this._stream.WriteByte((byte)O5MFileByteMarker.Way);

            var bytes   = new List <byte>();
            var diffId  = (long)way.Id - this._lastWayId;
            var idBytes = VarintBitConverter.GetVarintBytes(diffId);

            bytes.AddRange(idBytes);
            this._lastWayId = (long)way.Id;

            this.WriteVersionData(way, bytes);

            if (way.NodeRefs.Count == 0)
            {
                bytes.Add(0x00);
            }
            else
            {
                var nodeRefsBytes = new List <byte>();
                foreach (var nodeRef in way.NodeRefs)
                {
                    var nextReferenceDiff = (long)nodeRef - this._lastReferenceId;
                    var nodeRefBytes      = VarintBitConverter.GetVarintBytes(nextReferenceDiff);
                    this._lastReferenceId = (long)nodeRef;
                    nodeRefsBytes.AddRange(nodeRefBytes);
                }
                var nodeRefsBytesCountBytes = VarintBitConverter.GetVarintBytes((ulong)nodeRefsBytes.Count);
                bytes.AddRange(nodeRefsBytesCountBytes);
                bytes.AddRange(nodeRefsBytes);
            }

            this.WriteTags(way, bytes);

            var length = VarintBitConverter.GetVarintBytes((ulong)bytes.Count);

            this._stream.Write(length, 0, length.Length);
            writtenData = bytes.ToArray();
            this._stream.Write(writtenData, 0, bytes.Count);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Writes the specific OSMWay to the output
        /// </summary>
        /// <param name="way">The OSMWay to be written.</param>
        public void WriteWay(OSMWay way)
        {
            _xmlWriter.WriteStartElement("way");

            WriteOSMObjectAttributes(way);

            foreach (var nodeRef in way.Nodes)
            {
                _xmlWriter.WriteStartElement("nd");
                _xmlWriter.WriteAttributeString("ref", nodeRef.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
                _xmlWriter.WriteEndElement();
            }

            WriteOSMObjectTags(way);

            _xmlWriter.WriteEndElement();
        }
Ejemplo n.º 29
0
        private void ReadWay()
        {
            string attId = _xmlReader.GetAttribute("id");

            if (attId == null)
            {
                throw new XmlException("Attribute 'id' is missing.");
            }
            int wayId = int.Parse(attId, System.Globalization.CultureInfo.InvariantCulture);

            OSMWay way = new OSMWay(wayId);

            if (false == _xmlReader.IsEmptyElement)
            {
                _xmlReader.Read();

                while (_xmlReader.NodeType != XmlNodeType.EndElement)
                {
                    switch (_xmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (_xmlReader.Name)
                        {
                        case "nd":
                            way.Nodes.Add(ReadWayNd());
                            continue;

                        case "tag":
                            way.Tags.Add(ReadTag());
                            continue;

                        default:
                            _xmlReader.Skip();
                            continue;
                        }

                    default:
                        _xmlReader.Skip();
                        break;
                    }
                }
            }

            OnWayRead(way);
            _xmlReader.Skip();
        }
Ejemplo n.º 30
0
    public static OSMMap ParseMap(XmlDocument doc, ref XmlTextReader xmlReader, ref OSMMap osmMap)
    {
        //osmMap = new OSMMap();

        XmlNode rootnode = doc.ReadNode(xmlReader);

        OSMMap.ParseOSMHeader(rootnode, ref osmMap);

        int nodeCount     = 0;
        int wayCount      = 0;
        int relationCount = 0;

        foreach (XmlNode node in rootnode.ChildNodes)
        {
            switch (node.Name)
            {
            case "bounds":
                osmMap.AddBounds(OSMMap.ParseBounds(node, ref osmMap));
                break;

            case "node":
                nodeCount++;
                osmMap.AddNode(OSMNode.ParseNode(node));
                break;

            case "way":
                wayCount++;
                osmMap.AddWay(OSMWay.ParseWay(node, ref osmMap));
                break;

            case "relation":
                relationCount++;
                osmMap.AddRelation(OSMRelation.ParseRelation(node, ref osmMap));
                break;

            default:
                break;
            }
        }
        //Console.WriteLine("nodeCount = {0} = {1}", nodeCount, osmMap.nodes.Count);
        //Console.WriteLine("wayCount = {0} = {1}", wayCount, osmMap.ways.Count);
        //Console.WriteLine("relationCount = {0} = {1}", relationCount, osmMap.relations.Count);

        return(osmMap);
    }