core icon indicating copy to clipboard operation
core copied to clipboard

How to fetch Latitude and Longitude co-ordinates from osmGeo object while filtering

Open sivanand82 opened this issue 3 years ago • 4 comments

Hi Team,

I have been using the OSM library for fetching results for range of range co-ordinates. The library works well though but the unable to fetch latitude and longitude co-ordinates from the filter query.

var lastfiltered = from osmGeo in source where osmGeo.Type == OsmSharp.OsmGeoType.Node &&

                                // where osmGeo.Type != OsmSharp.OsmGeoType.Relation &&
                                osmGeo.Tags != null
                                && osmGeo.Tags.Contains(t)
                                   select osmGeo;

var complete = filtered.ToComplete();

The osmGeo abstract class does not have a defnition of longtitudes and latitudes.How to resolve this

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; }
}

sivanand82 avatar Mar 30 '22 13:03 sivanand82

You need to check and cast to nodes, something like this should work:

if (osmGeo is Node n) { 
   var latLon = (n.Latitude.value, n.Longitude.value)
}

xivk avatar Mar 31 '22 07:03 xivk

Sorry forgot mention that i am using the CompleteOsmGeo instead of osmGeo file.Such a cast would be valid this scenario as well right?

sivanand82 avatar Mar 31 '22 08:03 sivanand82

I think so because of this: https://github.com/OsmSharp/core/blob/develop/src/OsmSharp/Complete/Node.Complete.cs

xivk avatar Mar 31 '22 09:03 xivk

Thanks Ben.It worked for me,

sivanand82 avatar Apr 01 '22 11:04 sivanand82