0

I'm trying to use LINQ with SQL server net core 2.2 to get a buffer around a line representing a route as a Geography type line.

Journey is a table which holds details of a route in JourneyAsGeogLine represented a s a Geography line (SRID 4326). When I use code as below it appears to be interpreting bufferWidth as degrees: I understand that EF ignores SRID when running on client so is not treating bufferwidth as metres. How can I resolve this and create a buffer defined in metres round a Geography line (SRID:4326) using LINQ?

var thisRouteBuffer = _context.Journey.Where(f => f.Id == journeyID)
                        .FirstOrDefault().JourneyAsGeogLine.Buffer(bufferWidth);
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Martin
  • 45
  • 1
  • 5
  • EF itself doesn't support spatial features. It does so through [NetTopologySuite](https://github.com/NetTopologySuite/NetTopologySuite) library. When you say `running on the client` it actually means `using NetTopologySuite`. `JourneyAsGeogLine` is not part of that library though. What does that do? Is it a plain property or does it perform any calculations? Does it preserve the SRID property? – Panagiotis Kanavos Apr 01 '19 at 10:13
  • According to NTS's documentation the IGeometry interface *does* have [an SRID property](http://nettopologysuite.github.io/html/interface_geo_a_p_i_1_1_geometries_1_1_i_geometry.html#ad61a784c1513461b78da9a8db6d2ef30). Does your geography value contain the SRID you expected? BTW you should probalby only select the `JourneyAsGeogLine`, not the entire object, eg `_context.Journey.Where(f => f.Id == journeyID).Select(j=>j.JourneyAsGeogLine).FirstOrDefault();` – Panagiotis Kanavos Apr 01 '19 at 10:15
  • The issue about SRID and whether it is used or ignored and the need to perhaps use a library such as ProNet4API is discussed here: https://learn.microsoft.com/en-us/ef/core/modeling/spatial. The issue isn't really whether the SRID is there more that it is ignored, Microsoft explicitly say it is ignored clentside and client evaluated values will not respect SRID. I take your point that I should only select one column in the table/property in the object. – Martin Apr 01 '19 at 17:41
  • in that case you have the answer, and it doesn't contradict what I posted. You'll have to calculate the distance in degrees on the client, *or* [switch to a different projection like UTM](https://gis.stackexchange.com/questions/32046/how-can-i-make-a-buffer-with-xxx-meter-by-nettopologysuite). NTS has extracted projections to ProjNet4GeoAPI. And yes, NTS and JTS on which it was based is a bit ... uneven? Overspecialized leaving such calculations to other tools? – Panagiotis Kanavos Apr 02 '19 at 07:36
  • Check [both this question on NTS](https://gis.stackexchange.com/questions/32046/how-can-i-make-a-buffer-with-xxx-meter-by-nettopologysuite) and [this question on JTS](https://gis.stackexchange.com/questions/156465/calculate-distance-with-jts). In the end you have to use a *different* tool for calculations. – Panagiotis Kanavos Apr 02 '19 at 07:39
  • I did reproject the data and it all works fine. All feels a bit 'unnecessary'. I was concerned I was missing the obvious. – Martin May 04 '19 at 06:55

0 Answers0