Russell,
thank you for such a precise answer :) I was afraid this might turn
out like that :( Well, I'll go through MB then.
Jakub
On 9 Gru, 15:47, "Lawley, Russell S" <
rs...@bgs.ac.uk> wrote:
> Hi kompass,
> I have had to do this on numerous occasions, , the method i use is to create a look-up table of all the sites and their geology intersections (using a similar sql to that given to Uk_dave):
>
> Select site.site_id, geoltab.geo_id from site, geoltab where site.Obj intersects geoltab.Obj order by site.site_id, geoltab.geo_id into mylookup
>
> I then use a bit of mapbasic code to crawl down thru the lookup table looking at the top n records per unique site id (say top 3)
>
> So eg if mylookup looks like this, and i want the top three hits
>
> Site1, geol987 **
> Site1, geol88 **
> Site1, geol75 **
> Site1, geol6
> Site2, geol987 **
> Site2, geol68 **
> Site3, geol75 **
> Site3, geol6 **
> Site3, geol5 **
> Site3, geol3
>
> Then only the ** records get returned..Note that site 2 only has two hits to start with so can only return two hits
>
> In pseudo code terms you need something that
>
> 1. Saves the mylookup as a table in its own right, and then reopens it
> 2. Requests an n count value (say 3) via a dialog (or hard code)
> 3. fetches the first record of the lookup
> 4. Reads the siteid in column 1 into an ID_variable and sets the 'n'count to 1
> 5. starts a loop ( i use 'for i = 1 tableinfo(.. nrows)' ..but you could use whatever you prefer)
> a. fetches the ith row,
> b. reads the site_id and geolval from column 1 and column2
> c. checks to see if siteid is same as ID_variable
> i. if TRUE
> 1. check to see if ncount ≤ n
> a. if true then that record is wanted so save values or table row to new table (or whatever you want)
> b. if false then this record lies outside the nth range requested
> 2. increment ncount
> ii. if FALSE (it musy be a new site)
> 1. ncount = 1 (we know this from logic)
> a. so save values or table row to new table (or whatever you want)
> 2. reset so id_variable = the new siteid value
> 6. next loop
>
> so, basically a loop, a counter, a comparator and a method to either keep values or drop values.....fairly easy (lots of looping options and shortcuts) .... But.... not so fast on very big tables (mapbasic loops can be slow)