Пример #1
0
 /// <summary>
 /// The Constructor
 /// </summary>
 /// <param name="strPath"></param>
 public OSMParser(string filePath, string outFilePath)
 {
     this.FilePath    = filePath;
     this.OutfilePath = outFilePath;
     map       = new OSMMap();
     isRunning = false;
     finished  = false;
 }
Пример #2
0
    //<relation id="448540" user="******" uid="172947" visible="true" version="21" changeset="4699466" timestamp="2010-05-14T20:09:09Z">
    public static OSMRelation ParseRelation(XmlNode node, ref OSMMap map)
    {
        OSMRelation osmRelation = new OSMRelation();

        //HashDictionary<int, OSMNode> tmpNodesDict = new HashDictionary<int, OSMNode>();
        //bool keep = false;

        // parse node-attributes
        foreach (XmlAttribute attribute in node.Attributes)
        {
            string name = attribute.Name;
            switch (name)
            {
            case "id":
                osmRelation.Id = int.Parse(attribute.Value);
                break;

            case "visible":
                osmRelation.Visible = bool.Parse(attribute.Value);
                break;

            case "version":
                osmRelation.version = int.Parse(attribute.Value);
                break;

            default:
                break;
            }
        }

        // parse <nd /> Nodes
        foreach (XmlNode childnode in node.ChildNodes)
        {
            switch (childnode.Name)
            {
            case "member":
                //osmRelation.AddMember(OSMRelationMember.ParseRelationMember(childnode));
                osmRelation.Members.Add(OSMMember.ParseRelationMember(childnode));
                break;

            case "tag":
                //osmRelation.AddTag(OSMParser.ReadKeyValue(childnode));
                osmRelation.AddTag(childnode.Attributes[0].Value, childnode.Attributes[0].Value);
                //KeyValuePair<string, string> tag = OSMParser.ReadKeyValue(childnode);
                break;

            default:
                break;
            }
        }

        return(osmRelation);
    }
Пример #3
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public OSMMap ParseOSM()
    {
        xmlReader = new XmlTextReader(this.filePath);
        XmlDocument doc = new XmlDocument();

        while (xmlReader.Read())
        {
            if (xmlReader.NodeType == XmlNodeType.Element)
            {
                if (xmlReader.Name == "osm")
                {
                    OSMMap.ParseMap(doc, ref xmlReader, ref map);
                }
            }
        }
        return(this.map);
    }
Пример #4
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);
    }
Пример #5
0
    public static MapBounds ParseBounds(XmlNode node, ref OSMMap map)
    {
        MapBounds bounds = new MapBounds();

        foreach (XmlAttribute attribute in node.Attributes)
        {
            String name = attribute.Name;
            switch (name)
            {
            case "minlat":         // south
                bounds.South = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "minlon":         // west
                bounds.West = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "maxlat":         // north
                bounds.North = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "maxlon":         // east
                bounds.East = float.Parse(attribute.Value, CultureInfo.CreateSpecificCulture("en-US"));
                break;

            case "box":
                string   tmp      = attribute.Value;
                string[] splitStr = tmp.Split(',');
                bounds.South = float.Parse(splitStr[0], CultureInfo.CreateSpecificCulture("en-US"));        //south
                bounds.East  = float.Parse(splitStr[1], CultureInfo.CreateSpecificCulture("en-US"));        //east
                bounds.North = float.Parse(splitStr[2], CultureInfo.CreateSpecificCulture("en-US"));        //north
                bounds.West  = float.Parse(splitStr[3], CultureInfo.CreateSpecificCulture("en-US"));        //west
                break;

            case "origin":
                map.Origin = attribute.Value;
                break;

            default:
                break;
            }
        }
        return(bounds);
    }
Пример #6
0
    private static void ParseOSMHeader(XmlNode node, ref OSMMap map)
    {
        foreach (XmlAttribute attribute in node.Attributes)
        {
            String name = attribute.Name;
            switch (name)
            {
            case "version":
                map.OsmVersion = attribute.Value;
                break;

            case "generator":
                map.Generator = attribute.Value;
                break;

            default:
                break;
            }
        }
    }
Пример #7
0
 /// <summary>
 /// The default Constructor
 /// </summary>
 public OSMParser()
 {
     map       = new OSMMap();
     isRunning = false;
     finished  = false;
 }
Пример #8
0
    /// <summary>
    /// Update the GUI
    /// </summary>
    public void OnGUI()
    {
        // Initialize GUI-Utils

        if (!OpenStreetMapsWindow.initializedAttributes)
        {
            myGuiUtils = new MyGUIUtils();
            myGuiUtils.Initialize();

            //mybounds = new MapBounds(50.9517f, 6.9258f, 6.9902f, 50.9202f); // Köln Groß
            //mybounds = new MapBounds(50.23513f, 8.04716f, 8.07123f, 50.22266f); // Michelbach
            mybounds = MapBounds.Cologne;


            tileMap = new OSMTileMap();
            //tileMap.centerLatitude = mybounds.CenterLatitude;
            //tileMap.centerLongitude = mybounds.CenterLongitude;
            tileMap.centerLatitude  = 50.9390d;
            tileMap.centerLongitude = 6.9605d; //7.02744f; //6.9605d;//7.56211f;  Basti 6.93728f;

            tileMap.zoomLevel = 13;


            osmMap    = new OSMMap();
            osmParser = new OSMParser();

            moving       = new List <bool>();
            points       = new List <Vector2>();
            pointsCoords = new List <Vector2>();
            point        = new Vector2();


            zoomIn       = Resources.Load("OSMWindowIcons/zoomIn", typeof(Texture2D)) as Texture2D;
            zoomOut      = Resources.Load("OSMWindowIcons/zoomOut", typeof(Texture2D)) as Texture2D;
            titleTexture = Resources.Load("OSMWindowIcons/title", typeof(Texture2D)) as Texture2D;
            //Texture2D titleTexture = Resources.Load("title_small", typeof(Texture2D)) as Texture2D;
            pointTexture      = Resources.Load("OSMWindowIcons/marker", typeof(Texture2D)) as Texture2D;
            selectionTexture  = Resources.Load("OSMWindowIcons/selection", typeof(Texture2D)) as Texture2D;
            navigationTexture = Resources.Load("OSMWindowIcons/navigation", typeof(Texture2D)) as Texture2D;
            downloadTexture   = Resources.Load("OSMWindowIcons/download", typeof(Texture2D)) as Texture2D;


            //nodePrefab = GameObject.Find("BCNodePrefab");
            //if (nodePrefab == null)
            //{
            //    nodePrefab = new GameObject("BCNodePrefab");
            //    nodePrefab.AddComponent(typeof(Node));
            //    nodePrefab.AddComponent<BCIntersection>();
            //}

            //edgePrefab = GameObject.Find("BCEdgePrefab");
            //if (edgePrefab == null)
            //{
            //    edgePrefab = new GameObject("BCEdgePrefab");
            //    edgePrefab.AddComponent<Edge>();
            //    edgePrefab.AddComponent<MeshFilter>();
            //    edgePrefab.AddComponent<MeshRenderer>();
            //    edgePrefab.AddComponent<MeshCollider>();
            //    edgePrefab.AddComponent<BCRoad>();
            //}

            //entrancePrefab = GameObject.Find("BCEntrancePrefab");
            //if (entrancePrefab == null)
            //{
            //    entrancePrefab = new GameObject("BCEntrancePrefab");
            //    entrancePrefab.AddComponent(typeof(BCEntrance));
            //    entrancePrefab.AddComponent<MeshFilter>();
            //    entrancePrefab.AddComponent<MeshRenderer>();
            //    entrancePrefab.AddComponent<MeshCollider>();

            //}


            OpenStreetMapsWindow.initializedAttributes = true;
        }


        // Calculate Center Tile, Position and Coords
        CaculateValues();
        tileMap.DisplayTileMap();

        //osmParser = new OSMParser();
        _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUILayout.ExpandWidth(true));

        GUILayout.BeginVertical("Box", GUILayout.Width(sidebarWidth), GUILayout.ExpandHeight(true));
        GUILayout.Space(100f);

        // Display Title-Texture
        //DisplayTitle();

        // Display Zoom controls and execute zoomControl-handling
        ZoomControl();

        // Scroll-Control
        ScrollControl();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(300f));
        EditorGUILayout.BeginHorizontal();
        GUIContent[] toolbarOptions = new GUIContent[2];
        toolbarOptions[0] = new GUIContent(navigationTexture, "Navigation Mode");
        toolbarOptions[1] = new GUIContent(selectionTexture, "Selection Mode");
        editorMode        = GUILayout.Toolbar(editorMode, toolbarOptions, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight), GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        HandleNavigationOrSelection();
        GUILayout.EndVertical();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth), GUILayout.Height(80f));
        OSMServerSelection();
        GUILayout.EndVertical();
        EditorGUILayout.Separator();

        GUILayout.BeginVertical(GUILayout.Width(sidebarWidth));

        //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
        //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

        if (GUILayout.Button(downloadTexture, GUILayout.Width(zoomButtonWidth), GUILayout.Height(zoomButtonHeight * 2), GUILayout.ExpandWidth(true)))
        {
            //TileManager.OriginLatitude = this.mybounds.CenterLatitude;
            //TileManager.OriginLongitude = this.mybounds.CenterLongitude;

            OSMTileProviderBehaviour.mapBounds = mybounds;

            OSMTileProvider.GetOSMTileGameObjectsInBoundingBoxCutting(OSMTileProviderBehaviour.mapBounds, OSMTileProviderBehaviour.CurrentZoomLevel);

            //osmParser.BoundsList = new List<MapBounds>();
            //osmParser.BoundsList.Add(this.mybounds);

            //osmParser.StartParsingNoChunks(reloadContentOSM);

            //MapBounds.CenterOffset = GeographicCoordinates.ConvertLonLatToXY(
            //           osmParser.Map.Box.CenterLongitude,
            //           osmParser.Map.Box.CenterLatitude,
            //           GeographicCoordinates.MapCenter);

            //GameObject srtmMap = new GameObject();
            //srtmMap.name = "SRTMMap";


            //mapTile.bounds = this.mybounds;
            //mapTile.latitude = this.mybounds.South;
            //mapTile.longitude = this.mybounds.West;

            //SRTMMapTile mapTile = srtmMap.AddComponent<SRTMMapTile>();
            //mapTile.ParseToCutMap(this.mybounds);
            //mapTile.transform.position = mapTile.verticesMap[0, 0];
            //srtmMap.active = false;

            //GenerateGraph();

            //foreach (Node tmpNode in Editor.FindSceneObjectsOfType(typeof(Node)))
            //{
            //    tmpNode.FirePositionChanged(NodeEvent.Dirty, 1);
            //}

            EditorUtility.ClearProgressBar();
        }
        GUILayout.BeginHorizontal(GUILayout.Width(sidebarWidth));
        //GUILayout.Label(osmParser.FilePath, GUILayout.Width(sidebarWidth - 30f));
        if (GUILayout.Button("...", GUILayout.Width(25f)))
        {
            osmParser.FilePath = EditorUtility.OpenFilePanel("Open OSM-XML-File...", EditorApplication.applicationContentsPath, "");
            this.osmParser.StartParsingNoChunks(true);
            Debug.Log("Done");
            //if(File.Exists(@osmFilename))
            //    osmParser.FilePath = osmFilename;
        }
        GUILayout.EndHorizontal();


        GUILayout.EndVertical();

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
        // TODO: Unity changed its policy on using events  check if this still works without
        //Event.current.Use();
    }
Пример #9
0
    /*
     * <!ELEMENT way (tag*,nd,tag*,nd,(tag|nd)*)>
     * <!ATTLIST way id                 CDATA #REQUIRED>
     * <!ATTLIST way changeset          CDATA #IMPLIED>
     * <!ATTLIST way visible            (true|false) #REQUIRED>
     * <!ATTLIST way user               CDATA #IMPLIED>
     * <!ATTLIST way timestamp          CDATA #IMPLIED>
     *
     * <!ELEMENT nd EMPTY>
     * <!ATTLIST nd ref                 CDATA #REQUIRED>
     */
    public static OSMWay ParseWay(XmlNode node, ref OSMMap map)
    {
        OSMWay osmWay = new OSMWay();

        // TODO: Check import
        ////HashDictionary<int, OSMNode> tmpNodesDict = new HashDictionary<int, OSMNode>();
        //bool keep = false;

        //// parse node-attributes
        //foreach (XmlAttribute attribute in node.Attributes)
        //{
        //    string name = attribute.Name;
        //    switch (name)
        //    {
        //        case "id":
        //            osmWay.Id = int.Parse(attribute.Value);
        //            break;
        //        case "visible":
        //            osmWay.Visible = bool.Parse(attribute.Value);
        //            break;
        //        case "version":
        //            osmWay.version = int.Parse(attribute.Value);
        //            break;
        //        default:
        //            break;
        //    }
        //}

        //// parse <nd /> Nodes
        //foreach (XmlNode childnode in node.ChildNodes)
        //{
        //    switch (childnode.Name)
        //    {
        //        case "nd":
        //            long id = long.Parse(childnode.Attributes[0].Value);
        //            if (map.Nodes.Contains(id))
        //            {
        //                osmWay.Nodes.Add(map.Nodes[id]);
        //                //if (!tmpNodesDict.Contains(id))
        //                //    tmpNodesDict.Add(id, map.Nodes[id]);
        //            }
        //            break;
        //        case "tag":
        //            osmWay.AddTag(OSMParser.ReadKeyValue(childnode));
        //            KeyValuePair<string, string> tag = OSMParser.ReadKeyValue(childnode);

        //            switch (tag.Key)
        //            {
        //                case "highway":
        //                    {
        //                        switchWayHighwayValues(out keep, tag.Value);
        //                    }
        //                    break;
        //                case "lanes":
        //                    {
        //                        try
        //                        {
        //                            osmWay.Lanes = int.Parse(tag.Value);
        //                            //Console.Write("lanes={0}", osmWay.Lanes);
        //                        }
        //                        catch (FormatException e)
        //                        {
        //                            e.ToString();
        //                            //Console.Write("lanes={0}", value);
        //                        }

        //                    }
        //                    break;
        //                case "name":
        //                case "nam":
        //                case "name:de":
        //                case "int_name":
        //                case "ref":
        //                case "nat_ref":
        //                case "loc_ref":
        //                case "int_ref":
        //                    OSMStatistics.wayNameTagCount++;

        //                    break;
        //                default:
        //                    //Console.Write(key);
        //                    break;
        //            }
        //            break;
        //        default:
        //            break;
        //    }
        //}

        return(osmWay);
    }