I start off passing a central latitude ($lat_degrees) and longitude
($long_degrees) and a radius ($radius) to a TCL script. Using the
spherical cosine law to calculate distance, I want to select all sites
in a table within that given radius. Here are 2 code fragments from the
script...
===================================================================
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 { create table temp2 as
select e_stnid, i_stnid, deci_lat, deci_long, elevation, stn_name,
distance( $lat_degrees, $long_degrees, deci_lat, deci_long) as dist
from cl.stations
where dist <= $radius}
===================================================================
$lat_degrees and $long_degrees are defined
deci_lat and deci_long are valid field names (type real) in table
stations in the attached database (alias "cl"). I get an error message
which tells me that deci_lat and deci_long are not defined. I've run a
separate test to confirm that every row has non-null numbers in deci_lat
and deci_long. So that's not the problem. Here's the error message...
missing operand at _...@_
in expression " _...@_/ 57.295780490442965"
(parsing expression " / 57.295780490442965")
invoked from within
"expr $lat2 / $radian "
(procedure "sql_distance" line 5)
invoked from within
"sql_distance 49.25 123 {} {}"
invoked from within
"db eval { create table temp2 as
select e_stnid, i_stnid, deci_lat, deci_long, elevation,
stn_name,
distance( $lat_degrees, $long..."
invoked from within
"if { $argc < 4 } {
puts "Error: This query requires at least 4 parameters, namely"
puts "Central Latitude, Central Longitude, Radius, and at least..."
(file "./tcltest.004" line 2
--
Walter Dnes <[email protected]>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users