Resource

Resource Basics

Resource Name Assign Overlapping GEO Catalog Labels
Resource Version 1.0
Category Catalog
Downloads 650
Release Date 7/30/2022 7:40:58 PM
 

Resource Details

Description This script will assign Catalog Labels that have GEO coordinates to images which GEO coordinates overlap with catalog labels.
Installation Instructions Select the script from a thumb's context menu->Run Script from Repository->Catalog in Photo Supreme
Usage Instructions n.a.
Changes in this version initial version
Special Requirements
 

Author Information

Author Name Assembled from code parts by various authors
 

Script

{
  Assign Overlapping Place Labels to Images based on GEO Coordinates
}

var
  AAssignAll: TvxCheckBox;
  AHit: Integer;

function BuildForm: TvxSceneForm;
begin
  result := TvxSceneForm.Create(nil);
  result.Caption  := 'Assign Catalog Label from GEO';
  result.Position := poScreenCenter;
  result.Width := 400 * result.DPIFactor;
  result.Height := 150 * result.DPIFactor;

  AAssignAll := TvxCheckBox.Create(result.Root);
  result.Root.AddObject(AAssignAll);
  AAssignAll.Align := alTop;
  AAssignAll.Padding.Left := 20;
  AAssignAll.Padding.Top := 20;
  AAssignAll.Padding.Right := 20;
  AAssignAll.Width := 400;

  AAssignAll.Text := 'Assign all overlapping GEO Catalog Labels';
  AAssignAll.TextAlign := vgTextAlignNear;
end;

function HandleItem (AImage: TImageItem; AMaxResults: Integer): Boolean;
// return true when at least one catalog label is assigned
var
  AXmp: TXMP;
  ALat, ALon, AAlt: Double;
  AStamp: TDateTime;
  AProps: TCatalogItemProps;
  i: Integer;
  ACatItem: TCatalogItem;
begin
  result := False;

  ACatItem := TCatalogItem.Create(nil);
  AXmp := TXMP.Create(nil);
  AProps := TCatalogItemProps.Create(TCatalogItemProp, '');
  try
    PublicCatalog.LoadXMPForImage(AImage, AXmp, PublicOptions.CachedXMP);
    if PublicCatalog.FindImageCombined(AImage, ACatItem, True, vptNone) then
    begin
      ALat := 0.0; ALon := 0.0; AAlt := 0.0; AStamp := 0.0;
      AXmp.GetGPSStamp(ALat, Alon, AAlt, AStamp);

      PublicCatalog.EnumPropsOverlappingGeoLocation(ALat, ALon, AProps, AMaxResults);

      if AProps.Count > 0 then
      begin
        result := True;
        for i := 0 to AProps.Count - 1 do
          PublicCatalog.AddPropToItem (ACatItem, AProps.Items[i], False, False);
      end;
    end;
  finally
    AProps.Free;
    AXmp.Free;
    ACatItem.Free;
  end;
end;

var
  AForm: TvxSceneForm;
  i: Integer;
  AProgress: TxomProgress;
  AMaxResults: Integer;
begin
  if Selected.Count = 0 then
  begin
    Say('No images selected. Please select at least 1 thumbnail.');
    exit;
  end;

  AForm := BuildForm;

  AProgress := TxomProgress.Create(nil);
  try
    AAssignAll.IsChecked := Boolean(ReadFromRegistry ('Scripts', 'GEOToCatalogLabel_Check', AAssignAll.IsChecked));

    AForm.PrepareModal([mbOk]);
    AForm.ShowModal;
    if (AForm.ModalResult = mrOk) then
    begin
      AMaxResults := iif(AAssignAll.IsChecked, 0, 1);  // 0 = all; 1 = max1; 2=max2; etc...
      WriteToRegistry('Scripts', 'GEOToCatalogLabel_Check', AAssignAll.IsChecked);

      AProgress.Cancel := False;
      AProgress.Max := Selected.Count;
      AProgress.Pos := 0;
      AProgress.Show;

      AHit := 0;
      for i := 0 to Selected.Count - 1 do
      begin
        AProgress.Pos := i + 1;

        if AProgress.Cancel then
          break;

        if HandleItem(Selected.Items[i], AMaxResults) then
          Inc(AHit);
      end;

      if Progress.Cancel then
        Say ('Cancelled')
      else
        SayItOnce ('scriptGEOToCatalogLabel', 'Finished', IntToStr(AHit) + ' images got GEO labels assigned', '', 0, '-', mtInformation);
    end;
  finally
    AProgress.Free;
    AForm.Free;
  end;
end;