There's a lot more to this program, but I've cut it down to the bare
minimum that illustrates my problem. I call a TCL script from the linux
commandline, and get an error message like so...
========================================================================
[waltdnes][~/SQLite] ./fragment 49.25 123 25
can't read "lat1": no such variable
while executing
"expr $lat1 / $radian "
(procedure "sql_distance" line 3)
invoked from within
"sql_distance 49.25 123 48.916666666666664 -123.7"
invoked from within
"db eval { select e_stnid, i_stnid, deci_lat, deci_long, elevation,
distance($lat_degrees, $long_degrees, deci_lat, deci_long) as dist
..."
(file "./fragment" line 21)
========================================================================
Here is the cut-down program...
========================================================================
#!/usr/bin/tclsh
set lat_degrees [expr [lindex $argv 0]]
set long_degrees [expr [lindex $argv 1]]
set radius [expr [lindex $argv 2]]
load /usr/lib/sqlite-3.6.17/libtclsqlite3.so
sqlite3 db :memory:
# Note: GIS convention has longitude negative in the western hemisphere.
# But end-users will get annoyed at having to enter the minus sign all the
# time. So the conversion is done internally in the distance() function.
proc sql_distance {lat1, long1, lat2, long2} {
set radian [expr 180 / 3.1415926]
set lat1 [expr $lat1 / $radian ]
set long1 [expr $long1 / $radian * (-1) ]
set lat2 [expr $lat2 / $radian ]
set long2 [expr $long2 / $radian ]
return [expr {
acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($long2 -
$long1)) * 6371}]}
db function distance sql_distance
db eval {attach 'climate.sqlite' as cl}
db eval { select e_stnid, i_stnid, deci_lat, deci_long, elevation,
distance($lat_degrees, $long_degrees, deci_lat, deci_long) as dist
from cl.stations
where dist <= $radius} {puts stdout "$e_stnid, $i_stnid, $deci_lat,
$deci_long, $elevation, $dist"}
db close
========================================================================
I'm trying to do a select on all sites within a given radius of a
given point. I'm using the "spherical cosine law" to calculate distance.
The "sql_distance 49.25 123 48.916666666666664 -123.7" error message
shows that I successfully passed the first 2 command line parameters and
the last 2 came from an entry in table cl.stations.
Given that all 4 parameters hace been passed tothe distance()
function, why are they undefined in the proc?
--
Walter Dnes <[email protected]>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users