not a geotools answer,but best to let the database handle this as it is far more efficient at this. see https://postgis.net/workshops/postgis-intro/knn.html
once you have the SQL to your liking you could use a prepared statement. After a quick search I found that there is a nearest filter implementation: https://docs.geotools.org/latest/javadocs/org/geotools/data/postgis/filter/FilterFunction_pgNearest.html that you could use with a visitor i think, not sure how optimized that is. Op di 9 jun. 2020 om 15:58 schreef Schuster Stefan <stefan.schus...@gevas.de >: > Hi all, > > > > I use a postgis db with a table "roads", all entries hava a LINESTRING > geometry. > > > > For a given coordinate, I'd like to find the road that is nearest to this > coordinate. > > > > One idea was a CQL "intersects" between a box around the coordinate and > the linestrings, and then calculate the distance for each match. But this > needs to define a size of the box, which is not wanted. > > Any other Ideas? > > > > Thanks in advance > > Stefan > > > > > _______________________________________________ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > -- Disclaimer; This message is just a reflection of what I thought at the time of sending. The message may contain information that is not intended for you or that you don't understand.
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users