I need to select points that have attributes that are within a relative number range of each other. For instance; given the following numbers: 95,705,139,65,537,266,525 and 188; I need to find all of those numbers that are within a range of 50, 100 and 150 of each other.
I then need to find those that are within a distance of each other.
I am using QGIS. Any ideas gratfully accepted. Thanks.

2 Answers
2

Since you have tagged the question "sql" I guess that sql is an option to solve this.

If I understand your question right, you want to find the 50 range case, 100 range case 150 range case in different queries?

There are other options for that but to look at the simplest first we do those assumptions:

In your table you have a geometry column for your points, we call it the_geom , an id column to identify the resulting records, we call id gid and a value column with the values you presented above, we call it the_value.

THen to make the 50 range query, with a fixed maximum distance of 100 (units of the projection you use) you can write query like this:

Another approach here could be to create a table that can keep ranges and distances. Then you can easily put range classes in your resulting view, and you can put different distances for different ranges for instance. This table is also the right place to put information about how to style the result in QGIS like size of markers.

I might add to Nicklas' well detailed answer:
If you're looking to find points with the same table that are either a given distance from each other or have an attribute within a given value, then you can use the form:

I think that is identical to the first query in my answer :-), with the difference that you call your tables a1, a2 and I called mine a, b. As you say, self joins is the way to go.
–
Nicklas AvénMay 13 '12 at 14:39

1

Sorry, you're quite right, of course. I saw your 'a' and 'b' aliases and didn't notice that they referred to the same single table. I apologize for butting in...
–
MichaMay 13 '12 at 17:30