0

We are trying to display a map with data points within a distance of a reference location using NHibernate Spatial. However, the closest we could find was this:

Get Points Within a Radius using NHibernate Spatial

We need to do this without using any SQL or HQL. The NHibernate Spatial v4.0.0.x does not implement the IsWithinDistance() function on github as on date (of asking this question):

IsWithinDistance not implemented in NHibernate Spatial

It will be great if you can point us to some solution to this.

Thanks in advance.

EDIT: Related questions:

Almost the same question here - But this one is closed. I don't think those are low quality answers. Someone should re-open it. My question here is a more general question that the other one which is more specific to the investigation.

Community
  • 1
  • 1
B Charles H
  • 95
  • 2
  • 9

1 Answers1

1

If you are using PostGIS and are not totally against using SQL/HQL, I would recommend using the ST_DWithin() function (see here). For other providers (e.g. MSSQL), you can use a buffer and intersects query.

This "buffer and intersects" tactic can also be used in a QueryOver statement to avoid resorting to SQL/HQL. For example:

Point referenceLocation; // Will have been initialized somewhere else
double distance = 1000; // Set to whatever distance you need
var polygon = (Polygon) referenceLocation.Buffer(distance); // You can also pass in some BufferParameters here

var dataPoints = Session.QueryOver<your_data_point_entity_type>()
    .WhereSpatialRestrictionOn(x => x.point_geom_column)
    .Intersects(polygon)
    .List();

As an aside, I may get around to finally implementing the IsWithinDistance() function within NHibernate.Spatial when I get some free time :) See this issue on GitHub.

Peet Whittaker
  • 750
  • 6
  • 31
  • Firstly glad to see the author of the library responding here! Thanks for taking the time. I have seen the answer and hope it is the one that works. I had to move to another project and I cannot ascertain the correctness right now. I will get back to this once I get some time. In the mean time, if someone else finds this working, please do up vote or let me know... Thanks much. – B Charles H Jun 08 '17 at 19:04
  • @BCharlesH No problem - hopefully it'll help others when they search :) I should also note that I'm not the package author, merely an occasional contributor ;) – Peet Whittaker Jun 09 '17 at 06:51