Retourner à l’article Un algorithme simplifié de jointure spatiale point-point :

http://www.iag.asso.fr/articles/jointure.htm

 

 

' Nom :  Secteurs.ave

'

' Description:  Calcule les polygones de Thiessen attachés à la distribution

' ponctuelle définie par le thème actif de la vue active. Les polygones sont

' enregistrés dans un nouveau thème.

'

'

' Auteur : Christophe Faivre Duboz

' Date   : 19/11/2000

 

 

 

' Vérification des conditions d'application du script

If ((av.getactivedoc.Is(View).not) or (av.getactivedoc.getactivethemes.count<>1) or

(av.getactivedoc.getactivethemes.get(0).is(ftheme).not) or

(av.getactivedoc.getactivethemes.get(0).getftab.getshapeclass.getclassname<>"Point") )

then exit end

 

 

theview=av.getactivedoc

thetheme=theview.getactivethemes.get(0)

 

 

' Paramètres de la vue

theextent=theview.getdisplay.returnextent

wd=theextent.getwidth

hg=theextent.getheight

 

'Calcul des paramètres caractéristiques de la distribution

lx={}   ly={} ll={lx,ly}

 

for each i in thetheme.getftab

lx.add(thetheme.getftab.returnvalue(thetheme.getftab.findfield("shape"),i).getx)

ly.add(thetheme.getftab.returnvalue(thetheme.getftab.findfield("shape"),i).gety)

end

 

for each l in ll l.sort(true) end

 

dx={} dy={} ld={dx,dy}

for each i in 0..(thetheme.getftab.getnumrecords-2)

for each l in ld l.add(ll.get(ld.find(l)).get(i)-ll.get(ld.find(l)).get(i+1)) end

end

 

for each l in ld

l.RemoveDuplicates

l.sort(true)

If (l.get(0)=0) then l.remove(0) end

end

 

delta=dx.get(0).min(dy.get(0))

 

 

' coefficient de sécurité

h=wd+hg*1000000/delta

 

' Création du ftheme de sortie

 

thedir=av.getproject.getworkdir

 

av.getproject.setworkdir(av.getproject.getfilename.returndir)

thefn=av.getProject.MakeFileName ("sectors", "shp")

av.getproject.setworkdir(thedir)

 

newftab=ftab.makenew(thefn,POLYGON)

newftab.addfields({Field.Make("ID",#FIELD_DOUBLE,8,2)})

 

 

'Calcul des polygones

 

for each i in thetheme.getftab

 

myextent=theextent.aspolygon

firstpoint=thetheme.getftab.returnvalue(

thetheme.getftab.findfield("shape"),i)

 

If ((firstpoint.intersects(theextent.asPolygon).not)) then continue End

 

for each k in thetheme.getftab

 

If (myextent.Isnull) then break end

 

secondpoint=thetheme.getftab.returnvalue(thetheme.getftab.findfield("shape"),k)

 

If ((firstpoint.intersects(secondpoint))or(secondpoint.intersects(theextent.asPolygon).not))

Then continue End

 

theline=line.make(firstpoint,secondpoint)

p1=theline.returncenter

p2=p1.clone

 

a=(secondpoint.getX-firstpoint.getX)

b=(firstpoint.getY-secondpoint.getY)

 

p1.move(-b*h,-a*h)

p2.move(b*h,a*h)

 

l=polyline.make({{p1,p2}})

 

    for each u in myextent.Split (l)

    If (u.intersects(firstpoint)) then myextent=u break end

    end

 

end

 

If (myextent.isnull.not) then r=newftab.AddRecord

newftab.setvalue(newftab.getfields.get(0),r,myextent)

newftab.setvalue(newftab.getfields.get(1),r,i)

end

 

end

 

newftab.SetEditable(false)

 

theview.AddTheme(FTheme.MAke(newftab))

theview.getthemes.shuffle(theview.getthemes.get(0),theview.getthemes.find(theview.getactivethemes.get(0))+1)

theview.invalidateTOC(nil)

theview.invalidate

 

 

www.iag.asso.fr