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

Convert plots from local to global and back

By Martin Cerny / Jul 8, 2019

It may take a time to convert plot one by one between global and local coordinates and back, especially in inventory projects with multiple number of inventory plots. The functions ConvertCoordinatesFromGlobalToLocal and ConvertCoordinatesFromLocalToGlobal allowes to convert multiple number of plots in batch.
The following example expect the name of your root layer “Plots” and defined the coordinate system with the name “WGS 1984 UTM Zone 33N” (definition in Georeferencing, hot key F9).

This function is available since Field-Map version X8.0.10171

Global to local

var vlst :TVariantListWrapper;
    tb :TTableWrapper;
    P :integer;
    ErrorMessage_ :string;
begin
  tb := Project.GetQueryResult(‘SELECT ID,Name,CoordSysName FROM Plots WHERE MapProjection=1’);
  try
    if tb.RecordCount=0 then begin
      ShowInformation(‘No plots for global-to-local co-ordinate conversion available.’);
      exit;
    end;

    vlst := InputFromCheckListTab( ‘Plots for co-ordinate conversion’,’Select plots’,
                                   tb,
                                   ‘%s (%s) [%s]’,
                                   ‘ID;Name;CoordSysName’,
                                   ‘ID’,’ID’);
    if vlst<>nil then
    try
      OpenLog(‘Convert co-ordinates from global to local ‘);
      StartProgressBarCycle(vlst.Count+1);
      for P := 0 to vlst.Count-1 do begin
        StepProgressBar;
        Project.OpenPlotUsingDataCollector(vlst.Value[P]);
        Log(format(‘Processing plot %d (%s)’,[Plots.ValueAsInteger[‘ID’],Plots.ValueAsString[‘Name’]]));
        if Project.ConvertCoordinatesFromGlobalToLocal(ErrorMessage_)<>0 then
          Log(#9+ErrorMessage_);
      end;
      ResetProgressBar;
      Log(”);
      Log(‘Conversion successfully finished.’);
    finally
      vlst.Free;
    end;
  finally
    tb.Free;
  end;
end.

Local to global

var vlst :TVariantListWrapper;
    tb :TTableWrapper;
    P :integer;
    ErrorMessage_ :string;
begin
  tb := Project.GetQueryResult(‘SELECT ID,Name,CoordSysName FROM Plots WHERE MapProjection=0’);
  try
    if tb.RecordCount=0 then begin
      ShowInformation(‘No plots for local-to-global co-ordinate conversion available.’);
      exit;
    end;

    vlst := InputFromCheckListTab( ‘Plots for co-ordinate conversion’,’Select plots’,
                                   tb,
                                   ‘%s (%s) [%s]’,
                                   ‘ID;Name;CoordSysName’,
                                   ‘ID’,’ID’);
    if vlst<>nil then
    try
      OpenLog(‘Convert co-ordinates from local to global’);
      StartProgressBarCycle(vlst.Count+1);
      for P := 0 to vlst.Count-1 do begin
        StepProgressBar;
        Project.OpenPlotUsingDataCollector(vlst.Value[P]);
        Log(format(‘Processing plot %d (%s)’,[Plots.ValueAsInteger[‘ID’],Plots.ValueAsString[‘Name’]]));
        Project.MapProjection:=’WGS 1984 UTM Zone 33N’; //name of the coordinate system prepared in Georeferencing
        if Project.ConvertCoordinatesFromLocalToGlobal(true,ErrorMessage_)<>0 then
          Log(#9+ErrorMessage_);
      end;
      ResetProgressBar;
      Log(”);
      Log(‘Conversion successfully finished.’);
    finally
      vlst.Free;
    end;
  finally
    tb.Free;
  end;
end.