Exemple #1
0
 // Copy constractor
 public OsmNode(OsmNode copyFrom)
 {
     if (copyFrom != null)
     {
         this.id = copyFrom.id;
         this.version = copyFrom.version;
         if (copyFrom.timestamp != null) this.timestamp = copyFrom.timestamp;
         this.uid = copyFrom.uid;
         if (copyFrom.user != null) this.user = copyFrom.user;
         this.changeset = copyFrom.changeset;
         this.lat = copyFrom.lat;
         this.lon = copyFrom.lon;
         if (copyFrom.tags != null) this.tags = new Dictionary<string, string>(copyFrom.tags);
     }
 }
Exemple #2
0
        public RestaurantOsm(OsmNode node)
        {
            if (node.lat != null && node.lon != null) this.ItemLocation = new Location(node.lat, node.lon);

            this.Source = "OpenStreetMap";

            this.NodeReference = new OsmNode(node);

            // Parse tags
            if (node.tags != null && node.tags.Count > 0)
            {
                foreach (var tag in node.tags)
                {
                    switch (tag.Key)
                    {
                        case "name":
                            this.Name = tag.Value;
                            break;

                        case "name:en":
                            if (this.LocalizedName == null) this.LocalizedName = new Localized("en", tag.Value);
                            else this.LocalizedName.UpdateDescription("en", tag.Value);
                            break;

                        case "name:he":
                            if (this.LocalizedName == null) this.LocalizedName = new Localized("he", tag.Value);
                            else this.LocalizedName.UpdateDescription("he", tag.Value);
                            break;

                        case "name:ar":
                            if (this.LocalizedName == null) this.LocalizedName = new Localized("ar", tag.Value);
                            else this.LocalizedName.UpdateDescription("ar", tag.Value);
                            break;

                        case "amenity":
                            this.NodeReference.amenity = tag.Value;
                            if (this.Description == null || this.Description == "") this.Description = tag.Value;
                            break;

                        case "cuisine":
                            this.Cuisine = tag.Value;
                            this.Description = tag.Value;
                            break;

                        case "contact:phone":
                            this.Phone = tag.Value;
                            break;

                        case "addr:street":
                            if (this.Adress == null) this.Adress = new Address();
                            this.Adress.Street = tag.Value;
                            break;

                        case "addr:housenumber":
                            if (this.Adress == null) this.Adress = new Address();
                            int buildNum;
                            if (int.TryParse(tag.Value, out buildNum))
                            {
                                this.Adress.BuildingNum = buildNum;
                            }

                            break;

                        case "addr:postcode":
                            if (this.Adress == null) this.Adress = new Address();
                            this.Adress.Zip = tag.Value;
                            break;

                        case "addr:city":
                            if (this.Adress == null) this.Adress = new Address();
                            this.Adress.City = tag.Value;
                            break;

                        case "operator":
                            this.Operator = tag.Value;
                            break;

                        case "operator:en":
                            if (this.Operator == null || this.Operator == "") this.Operator = tag.Value;
                            break;

                        case "operator:he":
                            if (this.Operator == null || this.Operator == "") this.Operator = tag.Value;
                            break;

                        default:
                            Console.Write("tag.Key=" + tag.Key + " tag.Value=" + tag.Value + ".\n");
                            break;

                        //k="payment:10bis"
                        //k="payment:cibus"
                        //k="smoking"
                        //k="operator:he"
                        //k="opening_hours"
                        //k="contact:website"
                        //k="operator"
                        //k="operator:en"
                        //k="kosher"
                        //k="wheelchair"
                        //k="inf"
                    }//switch
                }// foreach
            }
            if (this.Name == null || this.Name == "") Console.Write("Name = null.\n");
        }
Exemple #3
0
        public List<OsmNode> ReadOSMXml(string filePath)
        {
            int count = 0, countOfsmallNode = 0, countNot6Attr = 0;

            try
            {
                //using (XmlReader xmlReader = XmlReader.Create(File.OpenText(@"\\WDMYCLOUD\Vadim\Work\osmosis-latest\bin\israel_restaurants.osm")))
                //using (XmlReader xmlReader = XmlReader.Create(File.OpenText(@"E:\Work\osmosis-latest\bin\israel_all_foods.osm")))
                using (XmlReader xmlReader = XmlReader.Create(File.OpenText(filePath)))
                {

                    List<OsmNode> nodeList = new List<OsmNode>();
                    Dictionary<string, string> bounds = new Dictionary<string, string>();
                    Dictionary<string, string> tags = new Dictionary<string, string>();
                    OsmNode tempNode = null;

                    xmlReader.MoveToContent();
                    while (xmlReader.Read())
                    {
                        if (xmlReader.NodeType == XmlNodeType.Element)
                        {
                            switch (xmlReader.Name)
                            {
                                case "bounds": // The node is an element.
                                    string minlon = xmlReader.GetAttribute(0);
                                    bounds.Add("minlon", xmlReader.GetAttribute(0));
                                    string minlat = xmlReader.GetAttribute(1);
                                    bounds.Add("minlat", xmlReader.GetAttribute(1));
                                    string maxlon = xmlReader.GetAttribute(2);
                                    bounds.Add("maxlon", xmlReader.GetAttribute(2));
                                    string maxlat = xmlReader.GetAttribute(3);
                                    bounds.Add("maxlat", xmlReader.GetAttribute(3));
                                    string origin = xmlReader.GetAttribute(4);
                                    bounds.Add("origin", xmlReader.GetAttribute(4));
                                    break;

                                case "node":
                                    tempNode = new OsmNode();
                                    if (xmlReader.AttributeCount == 8)
                                    {
                                        tempNode.id = long.Parse(xmlReader.GetAttribute(0));
                                        tempNode.version = int.Parse(xmlReader.GetAttribute(1));
                                        tempNode.timestamp = xmlReader.GetAttribute(2);
                                        tempNode.uid = int.Parse(xmlReader.GetAttribute(3));
                                        tempNode.user = xmlReader.GetAttribute(4);
                                        tempNode.changeset = int.Parse(xmlReader.GetAttribute(5));
                                        tempNode.lat = Double.Parse(xmlReader.GetAttribute(6), CultureInfo.InvariantCulture);
                                        tempNode.lon = Double.Parse(xmlReader.GetAttribute(7), CultureInfo.InvariantCulture);
                                    }
                                    else
                                    {
                                        countOfsmallNode++;
                                        if (xmlReader.AttributeCount != 6) countNot6Attr++;
                                    }
                                    break;

                                case "tag":

                                    string k = xmlReader.GetAttribute(0);
                                    string v = xmlReader.GetAttribute(1);
                                    if (!tags.ContainsKey(k))
                                    {
                                        tags.Add(k, v);
                                    }
                                    break;
                            }
                        }// if (xmlReader.NodeType == XmlNodeType.Element)
                        else
                        {
                            if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "node" && tempNode != null)
                            {
                                tempNode.tags = new Dictionary<string, string>(tags);
                                foreach (var tag in tags)
                                {
                                    var key = tag.Key;
                                    var value = tag.Value;
                                }
                                tags = new Dictionary<string, string>();
                                nodeList.Add(new OsmNode(tempNode));
                                tempNode = null;
                                count++;
                                //if (count == 464)
                                //{
                                //    Console.Write("count == 464.\n");
                                //}
                            }
                        }
                    } //while (xmlReader.Read())

                    log.DebugFormat("[ReadOSMXml] nodeList.Count={0}.", nodeList.Count.ToString());
                    return nodeList;
                }
            }
            catch (Exception e)
            {
                Console.Write("Exception" + e.ToString() + "\n" + " Count=" + count + "\n");
                return null;
            }
        }