• support@ifer.cz
  • +420 2 4195 0607

Working with Field-Map data – scan and locate table records

By Martin Cerny / Oct 9, 2016

Data in the Field-Map project are organized in layers arranged into relational database. Data table of each layer has number of various attributes (columns) and records (rows). Layers and attributes and accessed by names, records are accessed sequentially when passing-scanning through the table or by locating record by specific values of any attribute (excluding BLOB and MEMO attributes).

Lookup list attributes are linked to lookup tables. The link is based on Layer.Attribute=LookupList.ID,  or Layer.Attribute1=LookupList.MasterID AND Layer.Attribute2=LookupList.ID for so called conditional lookup tables. Lookup table has Value1, Value2, Value3 attributes that contains text description of lookup list items. Usually Value2 and Value3 are used for multilingual lookup lists, but it can be used for additional information on lookup items as well.

Data of the Field-Map database are easily accessible by the name of layer and attribute. LayerName[AttributeName] returns value from the current record of respective data table of Field-Map database. For lookup list attributes it is possible to access text description of particular attribute value by adding _lkp or _lkp2 or _lkp3 to the attribute name. Trees[‘Species’] returns species code whereas Trees[‘Species_lkp’] returns species name from lookup list.

Scan through or navigation between records of the data table is possible using several basic commands and properties: First, Last, Next, BOF, EOF, Locate.

Typical sequential scan through the table may looks as follow:

Trees.First;
while not Trees.EOF do begin
  … processing of Trees table record here …
  Trees.Next;
end;

Sequential scan through the table works with “visible” part of the table. In relational database of Field-Map only that part of the table which is related to the current record of parent table is visible. Therefore, when necessary to scan through all records of underlying table it is necessary to do it for every record of parent table (nested scanning):

Trees.First;
while not Trees.EOF do begin
  Shoots.First;
  while not Shoots.EOF do begin
    … processing of Shoots table record here …
    Shoots.Next;
  end;
  Trees.Next;
end;

Locate command enables direct scrolling to specific record which is found by values of its attributes.

if Trees.Locate(‘ID’,5,false,false) then begin
  … processing of Trees table record here …
end;

And again, even Locate command must respect relations of the database.

if Trees.Locate(‘ID’,5,false,false) then begin
  if Shoots.Locate(‘ID’,3,false,false) then begin
    … processing of Shoots table record here …
  end;
end;

or the same is:

if Trees.Locate(‘ID’,5,false,false) and Shoots.Locate(‘ID’,3,false,false) then
  … processing of Shoots table record here …

Locate command can be based on one or more searching attributes. In case of several searching attributes an array of variant values is used instead of single value:

if Trees.Locate(‘Species;DBH_mm’,VarArrayOf([1,345]),false,false) then begin
  … processing of Trees table record here …
end;

When going through the table of Plots (root layer of the Field-Map project) it is necessary to use special functions enabling to open Plot. There are two different functions available:
Project.OpenPlot(PlotID)
Project.OpenPlotUsingDataCollector(PlotID)

The first one is useful when access to the database tables is sufficient, the second one enables also access to map layers and all other features which are available when opening plot using Field-Map Data Collector.
In order to scan table of Plots it is either necessary to disable so called deep filter on Plots or use simple query:

with Project.GetQueryResult('SELECT ID FROM Plots') do
try
  First;
  while not EOF do begin
    Project.OpenPlotUsingDataCollector(Value[‘ID’]);
    … here process data of current plot …
    Next;
  end;
finally
  Free;
end;

Download scripting example 002 (Field-Map Project)


You must be logged in to post a comment