core
core copied to clipboard
How to fetch Latitude and Longitude co-ordinates from osmGeo object while filtering
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; }
}
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)
}
Sorry forgot mention that i am using the CompleteOsmGeo instead of osmGeo file.Such a cast would be valid this scenario as well right?
I think so because of this: https://github.com/OsmSharp/core/blob/develop/src/OsmSharp/Complete/Node.Complete.cs
Thanks Ben.It worked for me,