zhang_0923
路人甲
路人甲
  • 注册日期2004-10-07
  • 发帖数6
  • QQ
  • 铜币127枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1164回复:1

怎样让点自动移动到线上

楼主#
更多 发布于:2004-10-08 16:49
<P>假如有一排点,不是很直,用它的第一个点和最后一个点连一条直线,然后点这条直线运行程序让这些在直线两侧的点都到这条线上来,在相应的位置上自动加上节点。我写了一段代码,可是总出问题,希望高手指点一二,很急!谢谢!</P>
<P>include"mapbasic.def"
declare sub main
sub main
dim temp_buffer as object
dim x1,x2,y1,y2,k1,k2,b1,b2,x0,y0,x3,y3 as float
Set CoordSys nonearth units "m" bounds(0,0)(100000000,100000000)
select * from selection into a  
         Create Object As buffer from a into variable temp_buffer Width 15 Units "m"
  select * from point10kv  where obj Entirely within temp_buffer into PntSelection
  
    update a set 起点X = ObjectNodeX(obj, 1, 1) 'a中已经有起点X,起点y等这些字段
           update a set 起点Y = ObjectNodeY(obj, 1, 1) </P>
<P>           update a set 终点X = ObjectNodeX(obj, 1, 2)
           update a set 终点Y = ObjectNodeY(obj, 1, 2)
                
                  x1 = a.起点X
                  y1 = a.起点Y
                  x2 = a.终点X
                  y2 = a.终点Y</P>
<P>                  
                  k1 = (y1-y2)/(x1-x2)
                  b1 = y1-k1*x1
                  k2 = -1/k1        
fetch first from PntSelection  
do while NOT EOT(PntSelection)</P>
<P>                   x0 = ObjectGeography(PntSelection.obj, OBJ_GEO_POINTX)  '缓冲区中的点的坐标
                   y0 = ObjectGeography(PntSelection.obj, OBJ_GEO_POINTy)</P>
<P>                   b2 = y0-k2*x0
                   x3 = (b2-b1)/(k1-k2)
                   y3 = k2*x3+b2
  Insert Into point10kv (Obj)
  Values (Createpoint(x3, y3))
  
fetch next from PntSelection
loop</P>
<P>end sub</P>


<P>
 </P>
喜欢0 评分0
zx79zxz
路人甲
路人甲
  • 注册日期2004-11-02
  • 发帖数4
  • QQ
  • 铜币109枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-11-16 15:20
<img src="images/post/smile/dvbbs/em05.gif" /> xiao di shi xin shou
举报 回复(0) 喜欢(0)     评分
游客

返回顶部