Exemple #1
0
        /// <summary>
        /// Returns all objects within the given bounding box.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public List <OsmGeo> BoundingBoxGet(GeoCoordinateBox box)
        {
            string response = this.DoApiCall(false, string.Format(
                                                 "/api/0.6/map?bbox={0},{1},{2},{3}",
                                                 box.MinLon.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                                 box.MinLat.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                                 box.MaxLon.ToString(System.Globalization.CultureInfo.InvariantCulture),
                                                 box.MaxLat.ToString(System.Globalization.CultureInfo.InvariantCulture)), Method.GET, null);

            if (response != null && response.Trim().Length > 0)
            {
                XmlReaderSource xml_source = new XmlReaderSource(XmlReader.Create(new StringReader(response)));
                OsmDocument     osm        = new OsmDocument(xml_source);

                List <OsmGeo>             box_objects = new List <OsmGeo>();
                OsmSharp.Osm.Xml.v0_6.osm xml_osm     = (osm.Osm as OsmSharp.Osm.Xml.v0_6.osm);
                if (xml_osm.node != null)
                {
                    foreach (Osm.Xml.v0_6.node xml_node in xml_osm.node)
                    {
                        box_objects.Add(this.Convertv6XmlNode(xml_node));
                    }
                }
                if (xml_osm.way != null)
                {
                    foreach (Osm.Xml.v0_6.way xml_way in xml_osm.way)
                    {
                        box_objects.Add(this.Convertv6XmlWay(xml_way));
                    }
                }
                if (xml_osm.relation != null)
                {
                    foreach (Osm.Xml.v0_6.relation xml_relation in xml_osm.relation)
                    {
                        box_objects.Add(this.Convertv6XmlRelation(xml_relation));
                    }
                }
                return(box_objects);
            }
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Writes to the osm document.
        /// </summary>
        private void WriteToDocument()
        {
            _read = true;

            // collect all needed data.
            _bb = this.BoundingBox;

            // generate osm document.
            OsmSharp.Osm.Xml.v0_6.osm osm = new OsmSharp.Osm.Xml.v0_6.osm();

            // dimension the arrays.
            osm.node = new node[_nodes.Count];
            osm.way = new way[_ways.Count];
            osm.relation = new relation[_relations.Count];

            // iterate over all objects and convert them.
            IList<Node> nodes = _nodes.Values.ToList<Node>();
            for(int idx = 0;idx < nodes.Count;idx++)
            {
                node xml_obj = nodes[idx].ConvertTo();
                osm.node[idx] = xml_obj;
            }
            IList<Way> ways = _ways.Values.ToList<Way>();
            for (int idx = 0; idx < ways.Count; idx++)
            {
                way xml_obj = ways[idx].ConvertTo();
                osm.way[idx] = xml_obj;
            }
            IList<Relation> relations = _relations.Values.ToList<Relation>();
            for (int idx = 0; idx < relations.Count; idx++)
            {
                relation xml_obj = relations[idx].ConvertTo();
                osm.relation[idx] = xml_obj;
            }

            // convert the bounds as well.
            osm.bounds = _bb.ConvertTo();

            _document.Osm = osm;
            _document.Save();
        }