In PostgreSQL PostGIS I can get the distance in meters by just casting the geometry column to geography using this syntax inside the sql query "geometry_column::geography". like so :
select * from "Tags" where ST_Distance("Location",'POINT(31.233334 30.033333)'::geography) < 1000 ;
Now I want to convert tag.Location and point to Geography inside the where function of Linq to get the same result.
var tags = db.Tags.Where((tag) => tag.Location.Distance(point) < RangeInMeters )
.Select(tag => new {
Id = tag.Id,
Title = tag.Title,
Coordinates = new double[]{tag.Location.X,tag.Location.Y},
});
here's tag.Location definition
[Column(TypeName="geometry (point)")]
public Point Location{get;set;}
and here's "point" variable definition
var point = new Point(new Coordinate(Longitude,Latitude));
point.SRID = 4326;
justin that cast.geographycontains coordinates on a sphere whilegeometryon a plane. You need to project from the sphere to a plane and vice versa. NTS alone doesn't include projections and makes this quite explicit in the docs page. That cast doesn't calculate distances though. What's the actual PostgreSQL query you used? To calculate distances you need two points - Panagiotis Kanavosinside the where function of Linq to get the same result.the same as what query? LINQ queries aren't executed directly, they'r converted to SQL queries. What query are you trying to generate? - Panagiotis Kanavos[Column(TypeName="geography")]- Panagiotis Kanavos