点          名称        经度           纬度       烈度 
2         东引        120.4       26.3681 
3         文明村      120.003     26.6541 
4         里村        120.0685    26.6523 
5         外村        120.079     26.6509 
6         闾村        120.1015    26.6546 
7         沙村        120.0653    26.6442 
8         金村        120.0159    26.6156 
9         延亭村      120.0317    26.6246 
10        留村        120.0074    26.6104 
11        澳村        120.1398    26.5917 
12        澳村        120.1444    26.5785 
13        竹村        120.0879    26.6418 
14        西村        120.0388    26.5042 
15        宫村        120.0526    26.5093 
16        烟台村      120.0422    26.512 
17        小村        120.1001    26.669 
18        米村        120.1339    26.7167 
19        蛛网村      120.1142    26.7169 
20        华村        120.0599    26.6749 点        经度          纬度    烈度 
1       118.371     28.25    1 
2       118.421     28.25    1 
3       118.471     28.25    1 
4       118.521     28.25    1 
5       118.571     28.25    1 
6       118.621     28.25    1 
7       118.671     28.25    1 
8       118.721     28.25    1 
9       118.771     28.25    1 
10      118.371     28.2     1 
11      118.421     28.2     3 
12      118.471     28.2     1 
13      118.521     28.2     3 
14      118.571     28.2     1 
15      118.621     28.2     1 
16      118.671     28.2     4 
17      118.721     28.2     1 
18      118.771     28.2     1 
19      118.371     28.15    1 
20      118.421     28.15    6 
21      118.471     28.15    1 
22      118.521     28.15    1 
23      118.571     28.15    7 
24      118.621 2   8.15     1 
请教:(前提:用VB数据库来做!)我想将第一个表格的"烈度值"给添上,它是根据第二个表格的最近点来确定的,就是说,第一个表格的任一点距第二个表格中哪个点的最近,第一个表格的点的"列席值",就是第二个表格相应点的"烈度值",,,用一个循环语句,把第一个表格全给操作完! 
如果谁有这方面的例子,请帮忙发上来一个!谢谢了! 
 
 

解决方案 »

  1.   

    不容易啊,费了近一个小时,楼主好好看下
    create table #tmpa(
    点 decimal(10,0)
    ,名称 varchar(50)
    ,经度 decimal(10,4)
    ,纬度 decimal(10,4)
    ,烈度 decimal(10,0)
    )
    create table #tmpb(
    点 decimal(10,0)
    ,经度 decimal(10,4)
    ,纬度 decimal(10,4)
    ,烈度 decimal(10,0)
    )
    insert into #tmpa(点,名称,经度,纬度) values(2,'东引',120.4,26.3681)
    insert into #tmpa(点,名称,经度,纬度) values(3,'文明村',120.003,26.6541)
    insert into #tmpa(点,名称,经度,纬度) values(4,'里村',120.0685,26.6523)
    insert into #tmpa(点,名称,经度,纬度) values(5,'外村',120.079,26.6509)
    insert into #tmpa(点,名称,经度,纬度) values(6,'闾村',120.1015,26.6546)
    insert into #tmpa(点,名称,经度,纬度) values(7,'沙村',120.0653,26.6442)
    insert into #tmpa(点,名称,经度,纬度) values(8,'金村',120.0159,26.6156)
    insert into #tmpa(点,名称,经度,纬度) values(9,'延亭村',120.0317,26.6246)
    insert into #tmpa(点,名称,经度,纬度) values(10,'留村',120.0074,26.6104)
    insert into #tmpa(点,名称,经度,纬度) values(11,'澳村',120.1398,26.5917)
    insert into #tmpa(点,名称,经度,纬度) values(12,'澳村',120.1444,26.5785)
    insert into #tmpa(点,名称,经度,纬度) values(13,'竹村',120.0879,26.6418)
    insert into #tmpa(点,名称,经度,纬度) values(14,'西村',120.0388,26.5042)
    insert into #tmpa(点,名称,经度,纬度) values(15,'宫村',120.0526,26.5093)
    insert into #tmpa(点,名称,经度,纬度) values(16,'烟台村',120.0422,26.512)
    insert into #tmpa(点,名称,经度,纬度) values(17,'小村',120.1001,26.669)
    insert into #tmpa(点,名称,经度,纬度) values(18,'米村',120.1339,26.7167)
    insert into #tmpa(点,名称,经度,纬度) values(19,'蛛网村',120.1142,26.7169)
    insert into #tmpa(点,名称,经度,纬度) values(20,'华村',120.0599,26.6749)--select * from #tmpa
    insert into #tmpb(点,经度,纬度,烈度) values(1,118.371,28.25,1)
    insert into #tmpb(点,经度,纬度,烈度) values(2,118.421,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(3,118.471,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(4,118.521,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(5,118.571,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(6,118.621,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(7,118.671,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(8,118.721,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(9,118.771,28.25,1) 
    insert into #tmpb(点,经度,纬度,烈度) values(10,118.371,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(11,118.421,28.2,3)
    insert into #tmpb(点,经度,纬度,烈度) values(12,118.471,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(13,118.521,28.2,3)
    insert into #tmpb(点,经度,纬度,烈度) values(14,118.571,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(15,118.621,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(16,118.671,28.2,4)
    insert into #tmpb(点,经度,纬度,烈度) values(17,118.721,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(18,118.771,28.2,1)
    insert into #tmpb(点,经度,纬度,烈度) values(19,118.371,28.15,1)
    insert into #tmpb(点,经度,纬度,烈度) values(20,118.421,28.15,6)
    insert into #tmpb(点,经度,纬度,烈度) values(21,118.471,28.15,1)
    insert into #tmpb(点,经度,纬度,烈度) values(22,118.521,28.15,1)
    insert into #tmpb(点,经度,纬度,烈度) values(23,118.571,28.15,7)
    insert into #tmpb(点,经度,纬度,烈度) values(24,118.621,28.15,1)
    --增加此后三行可以看出效果,数据为#tmpa最后三行
    --insert into #tmpb(点,经度,纬度,烈度) values(25,120.0599,26.6749,111)
    --insert into #tmpb(点,经度,纬度,烈度) values(26,120.1142,26.7169,222)
    --insert into #tmpb(点,经度,纬度,烈度) values(26,120.1339,26.7167,333)
    --select * from #tmpbupdate #tmpa
    set 烈度=e.烈度
    --select e.*        --增加此行,注释掉上面两行可以看出对应#tmpb的哪个点
    from #tmpa c
    left outer join(select a.点,min(square(a.经度-b.经度)+square(a.纬度-b.纬度)) as 最小距离
    from #tmpa a,#tmpb b
    group by a.点) d on c.点=d.点
    left outer join (select a.点 as a点,b.点 as b点,b.烈度,square(a.经度-b.经度)+square(a.纬度-b.纬度) as 距离 from #tmpa a,#tmpb b) e
    on d.点=e.a点 and d.最小距离=e.距离select * from #tmpadrop table #tmpa
    drop table #tmpb