當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlOsmStreamSource.Initialize方法代碼示例

本文整理匯總了C#中OsmSharp.Osm.Xml.Streams.XmlOsmStreamSource.Initialize方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlOsmStreamSource.Initialize方法的具體用法?C# XmlOsmStreamSource.Initialize怎麽用?C# XmlOsmStreamSource.Initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OsmSharp.Osm.Xml.Streams.XmlOsmStreamSource的用法示例。


在下文中一共展示了XmlOsmStreamSource.Initialize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: getBuildingsAndLanduses

        /// <summary>
        /// Sets all the info about the buildings and landuses into their lists
        /// </summary>
        private void getBuildingsAndLanduses() {
            FileInfo fileInfo = new FileInfo(OSMFILE);
            XmlOsmStreamSource xmlSource = new XmlOsmStreamSource(fileInfo.OpenRead());
            xmlSource.Initialize();

            while (xmlSource.MoveNextWay()) {
                OsmSharp.Osm.Way way = (OsmSharp.Osm.Way)xmlSource.Current();
                if ((way != null) && (way.Visible.HasValue) && (bool)(way.Visible) && (way.Tags != null)) {

                    // Info about buildings
                    if (way.Tags.ContainsKey("building")) {
                        List<long> buildingNodes = new List<long>();
                        int height = 10; // Standard height is 10
                        string amenity = "";

                        // Check amenity and if it is a church
                        if (way.Tags.ContainsKey("amenity")) {
                            amenity = way.Tags["amenity"];

                            if (amenity == "place_of_worship") height = 25;
                        }

                        // Check height
                        if (way.Tags.ContainsKey("height")) {
                            height = (int)(float.Parse(way.Tags["height"], System.Globalization.CultureInfo.InvariantCulture));
                        } else if (way.Tags.ContainsKey("building:levels")) {
                            string[] verdiepen = way.Tags["building:levels"].Split('-');
                            height = 3 * Convert.ToInt32(verdiepen[verdiepen.Length - 1]);
                            amenity = "apartment";
                        }

                        foreach (long id in way.Nodes) buildingNodes.Add(id);

                        buildings.Add(new Building(buildingNodes, height, amenity, ZOOM));
                    }

                    // Info about landuses
                    if (way.Tags.ContainsKey("landuse")) {
                        List<long> landuseNodes = new List<long>();
                        foreach (long id in way.Nodes) landuseNodes.Add(id);

                        landuses.Add(new Landuse(landuseNodes, 0, way.Tags["landuse"], ZOOM));
                    }
                }
            }

            xmlSource.Dispose();
        }
開發者ID:whztt07,項目名稱:Osm3DBuildingGenerator,代碼行數:51,代碼來源:OsmData.cs


注:本文中的OsmSharp.Osm.Xml.Streams.XmlOsmStreamSource.Initialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。