Resource

Resource Basics

Resource Name Find Place Catalog Labels without GEO Details
Resource Version 1.0
Category Catalog
Downloads 738
Release Date 9/14/2018 9:12:09 AM
 

Resource Details

Description This script will search for catalog labels in the Places top category that have no GEO details configured.
Then it asks if the found list should be saved to file, displayed as a message on-screen, or if they should be deleted from the catalog
Installation Instructions Download the script to your hard drive
Usage Instructions 1. Select Tools -> Scripter
2. Load the downloaded script
3. Run the script with the Run button in the Scripter's toolbar
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 cat-lbls-no-geo.png
 

Script

{
  this script will search for all catalog labels in the Places category
  that have no GEO details marked for it or without longitude defined.

  author: IDimager
  initial date: 2018-09-14

  1.0; 2018-09-14; initial version
}

var
  AProps: TCatalogItemProps;
  AProp: TCatalogItemProp;
  i: Integer;
  AList: TTntStringList;
  ASl: TTntStringList;
  AResult: Integer;
  ACheck: Boolean;
  ADoAsk: Boolean;
  AHit: Integer;
begin
  Progress.Cancel := False;

  AProps := TCatalogItemProps.Create(TCatalogItemProp, '');
  AList := TTntStringList.Create;

  Progress.Caption := 'Finding catalog labels in database...';
  Progress.Show;
  Application.ProcessMessages;

  PublicCatalog.EnumPropsForParent(PlacesGUID, AProps, True, False);

  Progress.Max := AProps.Count;
  Progress.Pos := 0;

  for i := 0 to AProps.Count - 1 do
  begin
    Progress.Pos := i + 1;
    Progress.ProgressText := IntToStr(MulDiv (i, 100, AProps.Count)) + '%; Found ' + IntToStr(AList.Count) + ' empty labels';

    AProp := AProps.Items[i];
    if AProp.PropValue = AutoPropValue then    // skip auto-props
      Continue;

    if (not AProp.GPSGeoTag) or   // not marked for GEO tagging?
       (AProp.GPSLon = cNoGPSLatLon)  // no Longitude?
    then
    begin
      AList.AddObject (PublicCatalog.PathNameForProp(AProp, '::', True), AProp);
    end;

    // for testing
    //if AList.Count = 100 then
    //  break;

    if Progress.Cancel then
      break;
  end;

  Progress.Hide;

  ASaved := False;
  ASl := TTntStringList.Create;
  ASl.Add('Save results to file');
  ASl.Add('Show results on-screen');
  ASl.Add('Delete all ' + IntToStr(AList.Count) + ' place catalog labels');
  ASl.Add('Cancel');

  ADoAsk := AList.Count > 0;
  while ADoAsk do
  begin
    ACheck := False;
    AResult := AskCustom ('What would you like to do?', 'There are ' + IntToStr(AList.Count) + ' place catalog labels without GEO details found.', '', '', ACheck, ASl);
    case AResult of
      0:      // save to file
      begin
        SaveDialog.FileName := WideIncludeTrailingBackslash(WindowsDesktopDir) + 'place labels without GEO.txt';
        if SaveDialog.Execute then
        begin
          AList.SaveToFile (SaveDialog.FileName);
          Say ('The results are saved to file ' + SaveDialog.FileName);
          ADoAsk := False;
        end;
      end;
      1:      // show on screen
      begin
        Say2 ('Place catalog labels without GEO details', AList.Text);
        ADoAsk := True;
      end;
      2:      // delete empty labels
      begin
        if Ask ('Are you sure you want to permanently delete these ' + IntToStr(AList.Count) + ' place catalog labels without GEO details?') then
        begin
          Progress.Cancel := False;
          Progress.Max := AList.Count;
          Progress.Pos := 0;
          Progress.Show;

          AHit := 0;
          for i := 0 to AList.Count - 1 do
          begin
            Progress.Pos := i + i;
            Progress.ProgressText := IntToStr(MulDiv (i, 100, AList.Count)) + ' %';

            AProp := AList.Objects[i];

            //Say (AProp.PropName);
            PublicCatalog.DeleteProp (AProp);
            Inc(AHit);

            if Progress.Cancel then
              break;
          end;

          Progress.Hide;

          Say (IntToStr(AHit) + ' place catalog labels were deleted from the catalog');
          ADoAsk := not Progress.Cancel;
        end;
      end;
      3:      // cancel
      begin
        ADoAsk := False;
      end;
    end;
  end;

  AList.Free;
  AProps.Free;
end;