Skip to main content

Questions tagged [knn]

use this tag when dealing with questions related to kNN(K-Nearest Neighbors) a spatial property.

4 votes
2 answers
95 views

Calculating accurate distances using various ST_Distance options

I want to get the nearest neighbour information for a point, and I'm getting different results based on different geometry/geography types. Assuming I only care about the most accurate result, which ...
Ruslan's user avatar
  • 695
3 votes
1 answer
87 views

PostGIS query to get the closest data available

I've got three tables in a PostgreSQL/PostGIS database: referencia.comarcas_agrarias_centroides (holds geom centroids of agricultural regions) referencia.estaciones_r_pen (holds geom locations of ...
jpinilla's user avatar
  • 3,230
4 votes
1 answer
99 views

Dynamically drawing the polygon formed by nearest points to @map_extent_center in QGIS

From a DEM raster layer I created a set of random points and informed each point with the value of 'ELEVATION'. I also used the following expression to connect the 10 points closest to the @...
Ingrid Ingravida's user avatar
2 votes
1 answer
88 views

KNN (<->) order by -- possible to use spatial index with a secondary order by?

From reading here as well as the docs, I know how to use the <-> operator in my order by in order to do KNN search, and this is fast and uses the gist spatial index as expected. However, I have ...
Loose_Screw_748's user avatar
3 votes
0 answers
92 views

Slow KNN within fixed radius search (PostGIS) - ST_DWITHIN vs KNN

Ask: I want to return all customers matching certain characteristics within a 50 mile radius of the incoming zip code. This query takes just over a second to complete, and that's because of this line: ...
Loose_Screw_748's user avatar
8 votes
1 answer
267 views

Connecting dynamically the 8 nearest lines to @map_extent_center in QGIS

Starting from a points geometry layer, I am working on the following function that has the goal of drawing 8 nearest lines to the @map_extent_center of the map view: make_line( $geometry, @...
Ingrid Ingravida's user avatar
11 votes
2 answers
303 views

Creating buffers to closest distances with two categories in QGIS

I would like to develop an expression that does the following nearest-neighbour analysis: From a layer of points 'point_layer', I would like to calculate for each point the distance to the nearest ...
Ingrid Ingravida's user avatar
2 votes
1 answer
114 views

Trying to get accurate results using ST_DWithin with srid -1

I have a table where each row has a point Geometry(POINT(...)) [long lat]. These geometries don't specify an srid. Which means we're using a cartesian plane to do the calculations. All of this data is ...
Bombadillio's user avatar
0 votes
0 answers
22 views

Using QGIS, what is the simplest way to find the closest point in one layer for every point in the second layer?

In QGIS, I have two layers of points (layer #1 - blue, and layer #2 - pink). How can I find the closest point in layer #1 for each point in layer #2, and then save this new selection as its own new ...
p1unge's user avatar
  • 109
1 vote
1 answer
72 views

Distance unit in KNN using cross join lateral

The underlying geometries are SRID 4326. I want to confirm whether "pma.dist" in the select clause would be a distance in meters. Here is my code: SELECT clusters.areaid, ...
analyst92's user avatar
  • 857
3 votes
2 answers
123 views

Match rows from different tables by comparing similar lat lon coordinates

I am new to PostgreSQL and PostGIS. The first project I am working on is the first I am struggeling with and the one I would like to discuss. I have 2 stops tables I call for simplicity tbl_stops_1 ...
dancesWithCycles's user avatar
2 votes
1 answer
216 views

Select points within a buffer / radius of a point [duplicate]

When a user click on a map, I first want to get closest point (placename), then use that point to get number of points (schools) within 10km buffer / radius ... $str = pg_query($conn, "SELECT ...
Asanda Lamba's user avatar
2 votes
1 answer
138 views

Optimizing KNN query with multiple search conditions

I have two point tables in SRID 4326: Table 1. unjoined_pts & Table 2. midpts. I want to join the attributes from the unjoined_pts table to the closest midpts table based on a few conditions. The ...
MJM's user avatar
  • 995
6 votes
1 answer
378 views

Documentation for <->

I found this question and am wondering, is it for PostgreSQL? Where’s the documentation for <->? Trying to find the fastest way to get the distance between a lat and long earth coordinates in ...
user433342's user avatar
1 vote
2 answers
512 views

Find nearest point of interest for each category in PostgreSQL

I have 2 tables: poi and categories with below schema. POI table: id name category geog 1 poi-1 cat-1 point() 2 poi-2 cat-1 point() 3 poi-3 cat-2 point() 4 poi-4 cat-3 point() .. .. .. .. ...
apaleja's user avatar
  • 405

15 30 50 per page
1
2 3 4 5 6