Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing lat and lon #50

Closed
johanandbex opened this issue Mar 19, 2018 · 3 comments
Closed

missing lat and lon #50

johanandbex opened this issue Mar 19, 2018 · 3 comments

Comments

@johanandbex
Copy link

johanandbex commented Mar 19, 2018

Sorry of this is the wrong way to ask but I could see a better way. I am working with this and have a problem. I am parsing through a large pbs file and want to loop through certain nodes/ways but I need to be able to get the lat and lon from the "element" but I cant see it, code below. Problem is that OSMGEO doesnt know about those attributes so how can I get them?

namespace OsmSharp
{
public abstract class OsmGeo
{
protected OsmGeo();

    public long? Id { get; set; }
    public OsmGeoType Type { get; protected set; }
    public TagsCollectionBase Tags { get; set; }
    public long? ChangeSetId { get; set; }
    public bool? Visible { get; set; }
    public DateTime? TimeStamp { get; set; }
    public int? Version { get; set; }
    public long? UserId { get; set; }
    public string UserName { get; set; }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using OsmSharp;
using OsmSharp.Changesets;
using OsmSharp.Complete;
using OsmSharp.IO.PBF;
using OsmSharp.IO.Xml;
using OsmSharp.Logging;
using OsmSharp.Streams;

namespace readosmdata
{
class Program
{
static void Main(string[] args)
{
using (var fileStream = new FileInfo(@"D:/Users/Johan/MyDocuments/Projects/readosmdata/europe-latest.osm.pbf").OpenRead())
{
var source = new PBFOsmStreamSource(fileStream);

            Console.WriteLine(DateTime.Now);


            var filtered = from osmGeo in source
                where osmGeo.Type == OsmGeoType.Node ||
                      (osmGeo.Type == OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                select osmGeo;

            var complete = filtered.ToComplete();

            foreach (OsmGeo element in complete)
            {

                        foreach (var subTag in element.Tags)
                        {
                            if (subTag.Key.ToLower().Equals("building") || subTag.Key.ToLower().Equals("highway") ||
                                subTag.Key.ToLower().Equals("footpath") || subTag.Key.ToLower().Equals("power"))
                            {
                                Console.WriteLine(subTag.Key + " = " + subTag.Value);
                            }
                        }

                        //Console.WriteLine(element.ToString());
               }

            Console.WriteLine(DateTime.Now);
        }
    }
}

}

@xivk
Copy link
Contributor

xivk commented Mar 19, 2018

You need to check the type and cast the OsmGeo object to a Node object, then there is a lat/lon pair.
Casting can be done as follows for example:

var node = element as Node;
if (node == null)
{ // not a node.
   continue;
}

@johanandbex
Copy link
Author

Thanks very much! I'm a bit new to this.
Ill try it.

@xivk
Copy link
Contributor

xivk commented Mar 19, 2018

No worries, if you have more questions feel free to ask.

@xivk xivk closed this as completed Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants