473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

scanning an array

Claus Mygind
571 512MB
I have two arrays each contains two columns. lon and lat.

I want to use the lon and lat values from the one array to look and find the nearest matching values in the 2nd array.

Here is some sample data of longitude and latitude.

lat="39.7553670" lon="-88.8309830"
lat="39.7874000" lon="-89.1040170"
lat="39.8309670" lon="-89.0850330"
lat="40.1745330" lon="-88.2416830"

I will never have exact matching values, so I just want to find the best fit. The best fit in the 2nd array may be either a slightly higher or lower value than the search value.

I want to extract a value from a third column from the 2nd array and place it into a similar column of the first array.

Any suggestions on how that might be coded?

Expand|Select|Wrap|Line Numbers
  1.       aFoundCache = new Array(1,4)
  2.       aFoundCache[1,1] = "WayPoint"
  3.     aFoundCache[1,2] = "Lat"
  4.     aFoundCache[1,1] = "Lon"
  5.       aFoundCache[1,1] = "Time"
  6.  
  7.       aTrackPoint = new Array(1,4)
  8.       aTrackPoint[1,1] = "Lat"
  9.       aTrackPoint[1,2] = "Lon"
  10.       aTrackPoint[1,3] = "Date"
  11.       aTrackPoint[1,4] = "Time"
  12.  
Oct 9 '09 #1
4 2431
Dormilich
8,658 Expert Mod 8TB
how exactly are the lon/lat arrays defined?

Expand|Select|Wrap|Line Numbers
  1. // pseudo code
  2. // using x, y as search values
  3. // using lon, lat as reference values
  4.  
  5. // using least squares
  6. for_each (// reference array) {
  7.   stddev.push((lon - x)*(lon-x)+(lat-y)*(lat-y))
  8. }
  9.  
  10. // find smallest value
  11. for_each (// stddev) {
  12.   if (stddev[i]<stddev[i-1])
  13.     var min = i;
  14. }
  15.  
  16. // et voilà, reference[min] is your closest match
Oct 9 '09 #2
Claus Mygind
571 512MB
Actually I made a mistake. The code I am using here is in my server side app. But the fundamentals you describe should work just the same. So I should be able to apply your excellent code. Thank very much.
Oct 9 '09 #3
Dormilich
8,658 Expert Mod 8TB
your server side app may have a method to find the smallest value easier (something like e.g. min() …)
Oct 9 '09 #4
Claus Mygind
571 512MB
Nope what you provided was exactly what I needed.I would have had to write to disk in a table. I thank you very much. I was familiar with the formular so it was very easy to implement. You saved me a bunch of time.

I was even able to add a sort to put the points in proper order

If you like here is my server sided code which I derived from your example.

Expand|Select|Wrap|Line Numbers
  1.    //Add time stamp of time found to cache  from nearest track point
  2.          //start at row 2 because row 1 is a header
  3.          for nE = 2 to ALEN( aFoundCache,1 )
  4.  
  5.  
  6.             aStd = new Array(1,2)
  7.             aStd[1,1] = "Std Val"
  8.             aStd[1,2] = "Time"
  9.  
  10.             x = aFoundCache[nE,2]
  11.             y = aFoundCache[nE,3]
  12.  
  13.             //start at row 2 because row 1 is a header
  14.             for nT = 2 to ALEN( aTrackPoint,1 )
  15.                lat = aTrackPoint[nT,1]
  16.                lon = aTrackPoint[nT,2]
  17.                tim = aTrackPoint[nT,4]
  18.  
  19.  
  20.                aStd.grow(1)
  21.                aStd[ALEN( aStd,1 ),1] = (lon - x)*(lon-x)+(lat-y)*(lat-y)
  22.                aStd[ALEN( aStd,1 ),2] = tim
  23.  
  24.             endfor
  25.  
  26.             //start at the 2nd row, first row is a header
  27.             min = aStd[2,1]
  28.  
  29.             for nS = 2 to ALEN( aStd,1 )
  30.                // find smallest value
  31.                min = iif(aStd[nS,1] < min, aStd[nS,1], min  )
  32.             endfor
  33.  
  34.             cRow = aStd.subscript(aStd.scan(min),1)
  35.             aFoundCache[nE,4] = aStd[cRow,2]
  36.  
  37.          endfor
  38.  
  39.          aFoundCache.sort(4)
  40.  
Oct 10 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: CHANGE username to westes | last post by:
What are the most popular, and well supported, libraries of drivers for bar code scanners that include a Visual Basic and C/C++ API? My requirements are: - Must allow an application to be...
4
by: Zen | last post by:
I'm using Access 2000, and I'd like to know if there is a way to use a scanner (flatbed, doc-feed, etc) to scan forms with OMR or OCR software, and have the data be automatically (or if not...
0
by: James Dean | last post by:
I am scanning through a monochrome bitmap file and i want to output the outline of the bitmap so i need to set each bit of the outline. At the moment i just make an 8 bit array from each byte in...
8
by: Marie-Christine Bechara | last post by:
I have a form with a button called btnScan. When i click on this button i want to scan a file and save it in the database. Any hints?? ideas??? solutions??? *** Sent via Developersdex...
9
by: Michael D. Ober | last post by:
In VB 6, you can create control arrays for your option groups and scan with the following code dim opt as OptionButton for each opt in OptionGroup ' Do something next opt I know VB 2005...
7
by: Vince Panuccio | last post by:
Hello, If im looking for a pattern of byes in a byte array, what would be the best approach? I could convert the array into a string and use IndexOf recursivly by remembering the last...
1
kirubagari
by: kirubagari | last post by:
For i = 49 To mfilesize Step 6 rich1.SelStart = Len(rich1.Text) rich1.SelText = "Before : " & HexByte2Char(arrByte(i)) & _ " " & HexByte2Char(arrByte(i + 1)) & " " _ &...
1
by: ahammad | last post by:
Hello, I would like to scan a certain directory for XML files. Then I want to take in every XML file, read it, and stores the contents as a string in an array. For example, if the directory has...
2
by: iheartvba | last post by:
Hi Guys, I have been using EzTwain Pro to scan documents into my access program. It allows me to specify the location I want the Doc to go to. It also allows me to set the name of the document...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.