Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private IEnumerable <Simple> ParseSimple(string key, Color color)
        {
            foreach (var way in Xdoc.Descendants("way"))
            {
                var id = way.Attribute("id").Value;

                if (way.Attribute("visible").Value != "true")
                {
                    continue;
                }

                if (ways.Contains(id))
                {
                    continue;
                }

                var isKey = (from tag in way.Descendants("tag")
                             where tag.Attribute("k").Value == key && tag.Attribute("v").Value != "no"
                             select tag).Any();

                if (isKey)
                {
                    ways.Add(id);
                    yield return(new Simple(id, way, CreateFootprint(way), color));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IEnumerable <BuildingPart> Buildings()
        {
            ways.Clear();
            var compounds = ParseCompounds();

            // Build first multipolygon building parts of complex buildings
            foreach (var building in Compounds(compounds, CompoundType.MultipolygonBuildingPart))
            {
                yield return(building);
            }

            // Second are remaining multipolygon of complex buildings
            foreach (var building in Compounds(compounds, CompoundType.MultipolygonBuilding))
            {
                yield return(building);
            }

            // Third are remaining simpler parts of complex buildings
            foreach (var building in Compounds(compounds, CompoundType.Building))
            {
                yield return(building);
            }

            // Fourth remaining parts of simple buildings
            foreach (var building in ParseSimples())
            {
                yield return(new BuildingPart(building.Id, building.Polygon, ParsePart(building.Data), ParseRoof(building.Data), building.Color));
            }

#if DEBUG
            Console.Clear();
            var count = 0;
            foreach (var way in Xdoc.Descendants("way"))
            {
                var id = way.Attribute("id").Value;
                if (way.Attribute("visible").Value != "true")
                {
                    continue;
                }

                if (ways.Contains(id))
                {
                    continue;
                }

                var build = from tag in way.Descendants("tag")
                            where tag.Attribute("k").Value == "building" || tag.Attribute("k").Value == "building:part"
                            select tag;

                if (build.Any())
                {
                    yield return(new BuildingPart(id, CreateFootprint(way), ParsePart(way), ParseRoof(way), Color.Red));

                    count++;
                    Console.WriteLine("Way {0}: {1} = {2}", id, build.First().Attribute("k").Value, build.First().Attribute("v").Value);
                }
            }
            Console.WriteLine("{0}\nTotal remaining building structures = {1}", new String('-', 40), count);
#endif
        }
Ejemplo n.º 3
0
//        public IEnumerable<Building> Buildings()
        private void Buildings()
        {
            var ways = (from e in Xdoc.Descendants("way")
                        where !Cache.Exist((string)e.Attribute("id"))
                        where (string)e.Attribute("visible") == "true"
                        from t in e.Descendants("tag")
                        // warning: some nodes could contain both k,v pairs, use Distinct() since we don't want key duplicates
                        where (string)t.Attribute("k") == "building" || (string)t.Attribute("k") == "building:part"
                        select new
            {
                Key = (string)e.Attribute("id"),
                Value = e
            }).Distinct().ToDictionary(pair => pair.Key, pair => pair.Value);

            var relations = from e in Xdoc.Descendants("relation")
                            where (string)e.Attribute("visible") == "true"
                            from t in e.Descendants("tag")
                            where (string)t.Attribute("k") == "type" && (string)t.Attribute("v") == "building"
                            select new
            {
                Name    = Name(e),
                Element = e
            };

            // Process building parts from relations
            foreach (var rel in relations)
            {
                var      building = new Building(rel.Name);
                XElement way;
                foreach (var m in rel.Element.Descendants("member"))
                {
                    if ((string)m.Attribute("type") == "way")
                    {
                        string id = (string)m.Attribute("ref");
                        if (ways.TryGetValue(id, out way))
                        {
                            var part = BuildPart(way, (string)m.Attribute("role") == "part" ? true : false);
                            building.Parts.Add(part);
                            ways.Remove(id);
                            Cache.AddOrUpdate(id, part);
                        }
                    }
                }
//                yield return building;
            }

            // Process remaining standalone building
            foreach (var way in ways)
            {
                var part = BuildPart(way.Value);
                Cache.AddOrUpdate(way.Key, part);
//                yield return new Building(Name(way.Value), part);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Dictionary <string, Compound> ParseCompounds()
        {
            var compounds = new Dictionary <string, Compound>();

            foreach (var relation in Xdoc.Descendants("relation"))
            {
                if (relation.Attribute("visible").Value != "true")
                {
                    continue;
                }

                var id = relation.Attribute("id").Value;

                var type = (from tag in relation.Descendants("tag")
                            where tag.Attribute("k").Value == "type"
                            select tag.Attribute("v").Value).FirstOrDefault();

                switch (type)
                {
                case "building":
                    compounds.Add(id, new Compound(CompoundType.Building, relation));
                    break;

                case "multipolygon":
                {
                    var subtype = (from tag in relation.Descendants("tag")
                                   where tag.Attribute("k").Value == "building" || tag.Attribute("k").Value == "building:part"
                                   select tag.Attribute("k").Value).FirstOrDefault();

                    switch (subtype)
                    {
                    case "building":
                        compounds.Add(id, new Compound(CompoundType.MultipolygonBuilding, relation));
                        break;

                    case "building:part":
                        compounds.Add(id, new Compound(CompoundType.MultipolygonBuildingPart, relation));
                        break;
                    }
                }
                break;

                default:
                    break;
                }
            }
            return(compounds);
        }
Ejemplo n.º 5
0
        public BuildingPart BuildPart(XElement way, bool volume = true)
        {
            var tags = way.Descendants("tag")
                       .ToDictionary(
                tag => tag.Attribute("k").Value,  // add key
                tag => tag.Attribute("v").Value); // add value

            // Building creation
            var buildingPart = new BuildingPart(
                tags.ContainsKey("name") ? tags["name"] : "",
                Convert.ToInt64(way.Attribute("id").Value));

            // Outline construction
            // TODO check if closed?
            foreach (var elt in way.Descendants("nd"))
            {
                // find node that matches ways' node ref
                var query = (from node in Xdoc.Descendants("node")
                             where (string)node.Attribute("id") == (string)elt.Attribute("ref")
                             select node).First();

                var pos = Mercator.ToMeters(Convert.ToDouble(query.Attribute("lat").Value), Convert.ToDouble(query.Attribute("lon").Value));
                var x   = pos.X - Tile.Center.X;
                var y   = pos.Y - Tile.Center.Y;
                buildingPart.Outline.Add(new Vector2(x, y));
            }

            // Part data
            PartData part;

            part.volume       = volume;
            part.height       = float.Parse(tags.ContainsKey("height") ? Regex.Match(tags["height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture);
            part.min_height   = float.Parse(tags.ContainsKey("min_height") ? Regex.Match(tags["min_height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture);
            part.levels       = Convert.ToInt16(tags.ContainsKey("building:levels") ? tags["building:levels"] : "-1");
            part.min_level    = Convert.ToInt16(tags.ContainsKey("building:min_level") ? tags["building:min_level"] : "-1");
            buildingPart.Data = part;

            Surface surf;

            surf.colour              = tags.ContainsKey("building:colour") ? tags["building:colour"] : "";
            surf.material            = tags.ContainsKey("building:material") ? tags["building:material"] : "";
            buildingPart.PartSurface = surf;

            return(buildingPart);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// NATURAL
        /// Support for Natural like map elements
        /// TODO:
        /// - Trees: rows, woods.
        /// - other naturals
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Natural> Natural()
        {
            var nodes = (from e in Xdoc.Descendants("node")
                         where e.Attribute("visible").Value == "true"
                         from t in e.Descendants("tag")
                         where t.Attribute("k").Value == "natural" && t.Attribute("v").Value == "tree"
                         select new
            {
                Id = e.Attribute("id").Value,
                Name = t.Attribute("v").Value,
                Lat = Convert.ToDouble(e.Attribute("lat").Value),
                Long = Convert.ToDouble(e.Attribute("lon").Value),
                Element = e
            });

            foreach (var node in nodes)
            {
                NaturalData data = default(NaturalData);
                data.circumference = DefaultTreeCircumference;
                data.height        = DefaultTreeHeight;
                foreach (var tag in node.Element.Descendants("tag"))
                {
                    switch (tag.Attribute("k").Value.ToLower())
                    {
                    case "genus":
                        data.genus = tag.Attribute("v").Value;
                        break;

                    case "leaf_type":
                        data.leaf_type = tag.Attribute("v").Value;
                        break;

                    case "circumference":
                        MatchFloat(tag.Attribute("v").Value, out data.circumference);
                        break;

                    case "height":
                        MatchFloat(tag.Attribute("v").Value, out data.height);
                        break;
                    }
                }
                var pos = MercatorHelper.ToMeters(node.Lat, node.Long);
                yield return(new Natural(node.Id, new Vector2(pos.X - Tile.Center.X, pos.Y - Tile.Center.Y), data));
            }
        }
Ejemplo n.º 7
0
        private void button4_Click(object sender, EventArgs e)
        {
            ServiceReference3.WebService1SoapClient soap = new ServiceReference3.WebService1SoapClient();
            //string xml = dataSet.GetXml();

            try
            {
                XDocument Xdoc = new XDocument(new XElement("Users"));
                if (System.IO.File.Exists("D:\\LessonManagerApp.xml"))
                {
                    Xdoc = XDocument.Load("D:\\LessonManagerApp.xml");
                }
                else
                {
                    Xdoc = new XDocument();
                    XElement xmlstart = new XElement("Users");
                    Xdoc.Add(xmlstart);
                }
                XElement xml1 = /*new XElement("Users",*/
                                new XElement("User",
                                             new XElement("StartTime", textBox1.Text),
                                             new XElement("Duration", customControl11.Text),
                                             new XElement("Notes", textBox3.Text),
                                             new XElement("Instructor_ID", comboBox1.Text));

                if (Xdoc.Descendants().Count() > 0)
                {
                    Xdoc.Descendants().First().Add(xml1);
                }
                else
                {
                    Xdoc.Add(xml1);
                }

                Xdoc.Element("Users").Save("D:\\LessonManagerApp.xml");
                soap.UploadNotes("xml1");
                MessageBox.Show("Uploaded Successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 8
0
        public ColorPalette(ConfigOptions config)
        {
            var configFolder = config.ConfigurationFolder;

            _configFile = Path.Combine(configFolder, FileName);
            _localPath  = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            SchemaSet   = SetXmlSchema(config.XmlValidation);

            Xdoc    = XDocument.Load(_configFile);
            Vanilla = Xdoc.Descendants().First(key => (string)key.Attribute("name") == ".Vanilla");
            Build   = Vanilla.AttributeOrEmpty("build").Value;

            if (config.BackupConfiguration)
            {
                BackupConfiguration(configFolder, _configFile);
            }

            ColorCount = Vanilla.Descendants().Count(key => (string)key.Attribute("name") == "Colors");

            InstalledThemes = ColorCount == 0 ? new List <string>() : GetInstalledPalettes();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Candidate for memoization?
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 private XElement FindWayById(string id)
 {
     return((from node in Xdoc.Descendants("way") where node.Attribute("id").Value == id select node).FirstOrDefault());
 }