Reputation: 31
I'm trying to do a spatial query on a set of documents which have a radius field and a location field:
<field name="placeOfWork_coords" type="location" indexed="true" stored="true" required="false" multiValued="false" />
<field name="radius" type="pint" indexed="true" stored="true" required="false" multiValued="false" />
I would like to check if an arbitrary latlng point is within the radius of this document. I have only worked with static distances for the d
query parameter so far, so I would like to know how I can reference the radius field of the document in the query, if that is possible.
Upvotes: 1
Views: 181
Reputation: 52802
As far as I know you'll have to index the shape itself instead of having it as two separate fields; index a Circle with the given center point and radius. You can use a RptWithGeometrySpatialField field, and index your shape as:
Circle(4.56,1.23 d=0.0710)
The latter distance is in degrees, to convert to miles/km/meters, use the formulas provided on the wiki linked above:
Units, Conversion
Degrees to desired units:
Math.toRadians(degrees) * earthRadiusInTheUnitsYouWant
Degrees to kilometers:
degrees * 111.1951
Degrees to miles:
degrees * 69.09341
The RptWithGeometrySpatialField should be the most accurate option. When you're querying, you use the Intersects
operator:
&fq={!field f=geo}Intersects(-74.093 41.042)
.. should work. You might need a POINT type or similar to wrap the coordinates, but as far as I remember that isn't necessary. Previously it was lon lat
at least if there was no comma and lat,lon
if there was, so make sure to use the correct format.
Upvotes: 2