Summary  Summary

Add to your favorites

Maps  Maps
Portal  Portal
Geomatic  Geomatic
Computers  Computers
Download  Download
Jobs  Jobs

Customize  Customize
Games  Games
Forums  Forums
GuestBook  GuestBook

CW GIS  CW GIS
GeoRezo  GeoRezo
Georama  Georama




18.232.169.110
Web design
Daniel FAIVRE©
|

MakeRelTab

  Français Français 
Introduction
The MakeRelTab script
Source code
Button "Update" script
 Introduction Retour en haut de la page
    Did you ever asked for "the" rivers by counties list ? Or parcels by streets list ? MakeRelTab script export a table of existing spatial relations between two themes entities. For mailing, statistics, ......
 The MakeRelTab script Retour en haut de la page
    Execute many spatial requests (By theme selections). Each entity from source theme is selected one after one to build the list of theme two totaly or partialy enclosed).
    Installation:
    1) Create twoscripts, named dF.View.MakeRelTab, and dF.View.MakeRelTabUpdate, with the following source code.
    2) In GUI project, click on customize, and create a new menu option in the vue menu, with following options (except for HelpTopic: keep it empty):
   
   
 Source code Retour en haut de la page
    MakeRelTab peut aisément être modifié pour d'autres types de relations spatiales (en remplaçant #FTAB_RELTYPE_INTERSECTS par un autre type de relation). Les possibilités d'utilisations sont ainsi très variées.
'---Create  a  table  of  selected  objects  from  one  theme  by  each  object  from  a  second  theme.
'---Copyright  Daniel  FAIVRE  1999  -  www.geomaticien.com  -  Freeware  with  this  notice  only
'---A  newer  version  may  exist  on  the  site.  This  is  dF.View.MakeRelTab  version  1.0
'---No  warranty  of  any  kind.

'Must  be  a  "click"  property  of  a  custom  menu  option  in  GUI  view
'It's  a  good  idea  to  use  the  dF.View.MakeRelTabUpdate  script  as  Update  script  for  this  menu  option.  Work  of  course  only  for  features  themes,  not  for  images  ;-)


theView  =  av.GetActiveDoc
theThemes  =  theView.GetActiveThemes
if  (theThemes.Count  <>  2)  then
   MsgBox.Warning  ("Work  only  if  TWO  themes  selected","")
   return  nil
end
the1stTheme  =  theThemes.Get(0)
the2ndTheme  =  theThemes.Get(1)
theChoiceList  =  {the1stTheme,the2ndTheme}
theChoice  =  MsgBox.Choice  (theChoiceList,"Which  theme  will  be  on  the  ONE  size  of  the  relation  ?  (This  theme  entities  each  contains  several  objects  from  the  other  theme)","Source  choice")
if  (nil=theChoice)  then  return  nil  end
if  (theChoice  =  the2ndTheme)  then
   the1stTheme  =  theThemes.Get(1)
   the2ndTheme  =  theThemes.Get(0)
end    

'---Create  the  new  table:    
rel1  =  the1stTheme.GetName.Left(the1stTheme.GetName.IndexOf(".")).Substitute("  ","_")
relN  =  the2ndTheme.GetName.Left(the2ndTheme.GetName.IndexOf(".")).Substitute("  ","_")                                          
theNewTabName  =  FileDialog.Put(av.GetProject.MakeFileName(Rel1  +  relN,"dbf"),  
                                                 "*.dbf",  
                                                 "New  relation  between"  ++  rel1  ++  "and"  ++  relN)
if  (theNewTabName  =  NIL)  then
   return  nil
end                            
theNewTab  =  VTab.MakeNew(theNewTabName,dBase)

'---Create  fields  from  the  two  attributes  tables  of  the  selected  themes:
the1stTab  =  the1stTheme.GetFTab
for  each  aField  in  the1stTab.GetFields
   if  (aField.GetName  =  "Shape")  then  Continue  end
   theNewTab.AddFields({aField.Clone})
end
theNewTab.AddFields({Field.Make("Num",#FIELD_LONG,16,0)}.Clone)
the2ndTab  =  the2ndTheme.GetFTab
for  each  aField  in  the2ndTab.GetFields
   if  (aField.GetName  =  "Shape")  then  Continue  end
   theNewTab.AddFields({aField.Clone})
end


'---Loop  to  process  selections:
for  each  rec1  in  the1stTab
'---Select  each  record,  one  by  one:
   the1stTab.GetSelection.Set(rec1)
   the1stTab.UpdateSelection
'---Search  entities  from  theme  2  which  intersects  selected  entity  from  theme  1:
   the2ndTheme.SelectByTheme(the1stTheme,  #FTAB_RELTYPE_INTERSECTS,  0,  #VTAB_SELTYPE_NEW)
'--Export  fields  from  selected  entities:
   nb  =  0
   for  each  rec2  in  the2ndTab.GetSelection
       nb  =  nb  +  1
       newRecNo  =  theNewTab.AddRecord    
       for  each  F1  in  the1stTab.GetFields
           if  (F1.GetName  =  "Shape")  then  Continue  end
           theDestField  =  theNewTab.FindField(F1.GetName)        
           theNewTab.SetValue(theDestField,newRecNo,the1stTab.ReturnValue(F1,rec1))
       end
       theNewTab.SetValue(theNewTab.FindField("Num"),newRecNo,nb)
       for  each  F2  in  the2ndTab.GetFields
       if  (F2.GetName  =  "Shape")  then  Continue  end
           theDestField  =  theNewTab.FindField(F2.GetName)        
           theNewTab.SetValue(theDestField,newRecNo,the2ndTab.ReturnValue(F2,rec2))
       end
   end        

'---Unselect  processed  record:  
   the1stTab.GetSelection.Clear(rec1)
   the1stTab.UpdateSelection  
end

 Button "Update" script Retour en haut de la page
    This script is the "Update" property for the new vue menu option. Create relation table will be enabled only if two themes are selected.
'---  Two  themes  must  be  selected

theView  =  av.GetActiveDoc
SELF.SetEnabled((2  =  theView.GetActiveThemes.Count))