The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



Interface of SDL_GeoDB

const
  MAXLENG_GDBNAME = 59;
  CURRENT_DB_VERSION = 4;
{$IFDEF PAIDVERS}
  SDLVersionInfo = 'geodb_r1050_full';
  IsLightEd = false;
{$ELSE}
  SDLVersionInfo = 'geodb_r1050_lighted';
  IsLightEd = true;
{$ENDIF}
  release = 1050;

type
  ESDLGeoDBError = class(ESDLError);
  TSCoords = record
               Latit  : single;
               Longit : single;
             end;

  TIxLLRec = record
               LLValue : single;
               index   : longint;
             end;
  TIxLLRecArray = array of TIxLLRec;

  TPositionData = record
                    Latit  : double;
                    Longit : double;
                    Height : double;
                  end;

  TIxItemIDRec = record
                   ItemID  : longint;
                   index   : longint;
                 end;
  TIxItemIDRecArray = array of TIxItemIDRec;

  TgdbName = string[MAXLENG_GDBNAME];
  TMetaItem = (miKwd, miCaption, miFilePath, miDescriptor, miComment);
  TMetaInfo = record
                Keywords   : string[255];
                Caption    : string[127];
                FilePath   : string[127];
                Descriptor : string[255];
                Comment    : string[255];
              end;
  TgdbPolygon = array of TSCoords;
  TgdbItem = (gitBorder, gitTown, gitCity, gitLake, gitRiver, gitRoad,
              gitRoute, gitBLOB, gitUndefined);

const
  GDB_ITEMNAMES: array[TgdbItem] of string = ('Border', 'Town', 'City',
              'Lake', 'River', 'Road', 'Route', 'BLOB', 'Undefined');


type
  TgdbData = record
               ItemId     : longint;     // unique item id
               Name       : TgdbName;    // name of item; shortened to 59 chars
                                         // in release 4 to give room for altitude
               Altitude   : single;      // NEW in version 4: altitude
               ClassFlag  : byte;        // class number
               Tag        : longint;     // user tag
               BlobOffset : longint;     // offset into blob data file (GDD);
                                         // -1 if not valid
               Date       : TDateTime;   // date & time (with FileBlob:
                                         // TDateTime of file creation)
               StateFlag  : longint;     // state flag
               LatLow     : single;      // coordinates of extents
               LatHigh    : single;
               LongLow    : single;
               LongHigh   : single;
               case ItemKind: TgdbItem of    // kind of item
                 gitBorder,
                   gitLake,
                   gitCity,
                   gitRoad,
                  gitRoute,
                  gitRiver : (NumPoints : integer;
                              Closed    : boolean);
                   gitBLOB : (Size      : longint);
             end;

  TgdbSystemData = record
                     HighestID  : longint;    // highest available DB identifier
                     DBVersion  : longint;    // system version
                     Description: string[60]; // user defined description
                     Revision   : longint;    // user defined revision
                     Reserved   : array[1..183] of byte;
                   end;

  TGeoDB = class(TComponent)
           private
             FNameGDS           : string;   // file name of summary data
             FNameGDD           : string;   // file name of geo data
             FNameIX            : array[0..4] of string; // file names of indexes:
                                            //  0 ... ItemID index,
                                            // >0 ... Long/Lat indexes
             FSumData           : array of TgdbData;
             FNumSumItems       : integer;
             FLazyWrite         : boolean;  // TRUE: indexes are updated on disk
                                            // only when DB is closed
             FIx0ItemId         : TIxItemIdRecArray;
             FIx1LatLo          : TIxLLRecArray;
             FIx2LatHi          : TIxLLRecArray;
             FIx3LongLo         : TIxLLRecArray;
             FIx4LongHi         : TIxLLRecArray;
             FOnPercentDone     : TOnPercentDoneEvent;
             FOnPercDoneEnabled : boolean;
             FSystemData        : TgdbSystemData;
             procedure SaveIndex (Ix: integer);
             procedure SetLazyWrite (Value: boolean);
             procedure SetGDBName (FName: string);
             procedure SortIxInto (IxArray: TIxLLRecArray; Data: TIxLLRec);
             procedure SortIxItemIDInto (IxArray: TIxItemIdRecArray;
                                         Data: TIxItemIDRec);
             function GetGDBName: string;
             function GetDescription: string;
             procedure SetDescription (Text: string);
             function GetRevision: longint;
             function GetDBVersion: longint;
             procedure SetRevision (Rev: longint);
             function GetSumdata (ix: longint): TgdbData;
             function GetIxItemID (ix: longint): TIxItemIDRec;
             function GetIxLatLow (ix: longint): TIxLLRec;
             function GetIxLatHigh (ix: longint): TIxLLRec;
             function GetIxLongLow (ix: longint): TIxLLRec;
             function GetIxLongHigh (ix: longint): TIxLLRec;
             procedure RemoveIndexEntries (DBEntry: longint);
             procedure InsertIntoIndex (DBEntry: longint; SumData: TgdbData);
           protected
{$IFDEF DOTNET}
             function AddData (Name: TgdbName; Polygon: TgdbPolygon;
                          ClosedLine: boolean; ItemType: TgdbItem; ClassNumber: byte;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; UserTag: longint;
                          MetaInfo: TMetaInfo; PBLOBData: IntPtr;
                          SizeOfBLOBData: integer; DataFromFile: boolean): integer;
             procedure ReplaceData (DBENtry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; ClosedLine: boolean;
                          ItemType: TgdbItem; ClassNumber: byte; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; UserTag: longint; MetaInfo: TMetaInfo;
                          PBLOBData: IntPtr; SizeOfBLOBData: integer;
                          DataFromFile: boolean);
{$ELSE}
             function AddData (Name: TgdbName; Polygon: TgdbPolygon;
                          ClosedLine: boolean; ItemType: TgdbItem; ClassNumber: byte;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; UserTag: longint;
                          MetaInfo: TMetaInfo; PBLOBData: pointer;
                          SizeOfBLOBData: integer; DataFromFile: boolean): integer;
             procedure ReplaceData (DBENtry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; ClosedLine: boolean;
                          ItemType: TgdbItem; ClassNumber: byte; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; UserTag: longint; MetaInfo: TMetaInfo;
                          PBLOBData: pointer; SizeOfBLOBData: integer;
                          DataFromFile: boolean);
{$ENDIF}
           public
             constructor Create (AOwner: TComponent); override;
             destructor  Destroy; override;


{$IFDEF DOTNET}
             function AddBLOB (Name: string; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint; MInfo: TMetaInfo;
                          PBLOBData: IntPtr;
                          SizeOfBLOBData: integer): integer; overload;
{$ELSE}
             function AddBLOB (Name: string; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint; MInfo: TMetaInfo;
                          PBLOBData: pointer;
                          SizeOfBLOBData: integer): integer; overload;
{$ENDIF}
             function AddBLOB (Name: string; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint; MInfo: TMetaInfo;
                          Data: TMemoryStream): integer; overload;
             function AddBLOB (FileName: string; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; ClassNumber: byte; UserTag: longint;
                          MInfo: TMetaInfo): integer; overload;
             function AddBLOB (FileName, FNameInDB: string; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; ClassNumber: byte; UserTag: longint;
                          MInfo: TMetaInfo): integer; overload;
             function AddBLOB  (FileName, FNameInDB, OrgFilePath: string;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; ClassNumber: byte;
                          UserTag: longint; MInfo: TMetaInfo): integer; overload;
             function AddBorder (Name: TgdbName; Polygon: TgdbPolygon;
                          ClosedLine: boolean; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddCity (Name: TgdbName; Polygon: TgdbPolygon;
                          ClosedLine: boolean; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddRiver (Name: TgdbName; Polygon: TgdbPolygon;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddRoad (Name: TgdbName; Polygon: TgdbPolygon;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddRoute (Name: TgdbName; Polygon: TgdbPolygon;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddLake (Name: TgdbName; Polygon: TgdbPolygon;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint): integer;
             function AddTown (Name: TgdbName; Date: TDateTime; StateFlag: longint;
                          Location: TSCoords; Altitude: single; ClassNumber: byte;
                          UserTag: longint): integer;
             procedure DeleteData (DbEntry: longint);
             procedure UpdateBasicData (DbEntry: longint; GdbData: TgdbData);
             function  UpdateMetaInfo (DBEntry: longint;
                          MetaInfo: TMetaInfo): boolean;
             function  GetMetaInfo (DBEntry: longint;
                          var MetaInfo: TMetaInfo): boolean;
             property  Data[DBEntry: longint]: TgdbData read GetSumData;
             property  OnPercDoneEnabled: boolean
                          read FOnPercDoneEnabled write FOnPercDoneEnabled;
             property  Description: string
                          read GetDescription write SetDescription;
             property  Revision: integer
                          read GetRevision write SetRevision;
             property  DBVersion: Integer read GetDBVersion;

             procedure ExportDataDebug (FName: string);
{$IFDEF DOTNET}
             procedure ReplaceBLOB (DBEntry: longint; Name: string;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; ClassNumber: byte;
                          UserTag: longint; MInfo: TMetaInfo;
                          PBLOBData: IntPtr; SizeOfBLOBData: integer); overload;
{$ELSE}
             procedure ReplaceBLOB (DBEntry: longint; Name: string;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint; MInfo: TMetaInfo;
                          PBLOBData: pointer; SizeOfBLOBData: integer); overload;
{$ENDIF}
             procedure ReplaceBLOB (DBEntry: longint; Name: string;
                          Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint; MInfo: TMetaInfo;
                          Data: TMemoryStream); overload;
             procedure ReplaceBLOB (DBEntry: longint; FileName: string;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; ClassNumber: byte;
                          UserTag: longint; MInfo: TMetaInfo); overload;
             procedure ReplaceBorder (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; ClosedLine: boolean;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; ClassNumber: byte;
                          UserTag: longint);
             procedure ReplaceCity (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; ClosedLine: boolean;
                          Date: TDateTime; StateFlag: longint; LatLow, LatHigh,
                          LongLow, LongHigh, Altitude: single; ClassNumber: byte;
                          UserTag: longint);
             procedure ReplaceRiver (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; ClassNumber: byte; UserTag: longint);
             procedure ReplaceRoad (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint);
             procedure ReplaceRoute (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; Date: TDateTime;
                          StateFlag: longint; LatLow, LatHigh, LongLow, LongHigh,
                          Altitude: single; ClassNumber: byte; UserTag: longint);
             procedure ReplaceLake (DBEntry: longint; Name: TgdbName;
                          Polygon: TgdbPolygon; Date: TDateTime; StateFlag: longint;
                          LatLow, LatHigh, LongLow, LongHigh, Altitude: single;
                          ClassNumber: byte; UserTag: longint);
             procedure ReplaceTown (DBEntry: longint; Name: TgdbName;
                          Date: TDateTime; StateFlag: longint; Location: TSCoords;
                          Altitude: single; ClassNumber: byte; UserTag: longint);
             function RetrieveBLOB (DBEntry: integer; Filepath: string;
                          var MetaInfo: TMetaInfo): boolean; overload;
{$IFDEF DOTNET}
             function RetrieveBLOB (DBEntry: integer; var MetaInfo: TMetaInfo;
                          PBLOBData: IntPtr;
                          SizeOfBLOBData: integer): boolean; overload;
{$ELSE}
             function RetrieveBLOB (DBEntry: integer; var MetaInfo: TMetaInfo;
                          PBLOBData: pointer;
                          SizeOfBLOBData: integer): boolean; overload;
{$ENDIF}
             function RetrieveBLOB (DBEntry: integer; var MetaInfo: TMetaInfo;
                          var BlobStream: TMemoryStream): boolean; overload;
             function RetrievePolygon (DBEntry: integer;
                          var Polygon: TgdbPolygon): boolean;
             procedure GarbageCollection;
             function GetClosestItemIDIx (ItemID: longint): longint;
             function GetClosestLatHighIx (Latit: double): longint;
             function GetClosestLatLowIx (Latit: double): longint;
             function GetClosestLongHighIx (Longit: double): longint;
             function GetClosestLongLowIx (Longit: double): longint;
             property IxItemID[ix: longint]: TIxItemIdRec read GetIxItemID;
             property IxLatLow[ix: longint]: TIxLLRec read GetIxLatLow;
             property IxLatHigh[ix: longint]: TIxLLRec read GetIxLatHigh;
             property IxLongLow[ix: longint]: TIxLLRec read GetIxLongLow;
             property IxLongHigh[ix: longint]: TIxLLRec read GetIxLongHigh;
             procedure RecalcIndexes;
             function SearchData (Name: TgdbName; ItemType: TgdbItem;
                          StartSearchAt: integer;
                          ClassNumber: byte): integer; overload;
             function SearchData (Name: TgdbName): integer; overload;
             function SearchForItemID (ItemID: longint): integer;
           published
             property LazyWrite: boolean read FLazyWrite write SetLazyWrite;
             property DBName: string read GetGDBName write SetGDBName;
             property NumEntries: integer read FNumSumItems;
             property OnPercentDone: TOnPercentDoneEvent
                          read FOnPercentDone write FOnPercentDone;
           end;

procedure ClearGdbData (var Data: TgdbData);
procedure ClearMetaInfo (var Data: TMetaInfo);
function ExtractLocation (Data: TGdbData): TSCoords;
function ReadSystemInformation (DBName: string): TgdbSystemData;
function  GeoLatitude
               (innum : double; {location to convert to geographic pos. string }
               format : TDegreeFormat;                      { format of output }
            precision : integer)                    { number of decimal places }
                      : string;                               { geogr.notation }
function  GeoLongitude
               (innum : double; {location to convert to geographic pos. string }
               format : TDegreeFormat;                      { format of output }
            precision : integer)                    { number of decimal places }
                      : string;                               { geogr.notation }






Last Update: 2012-Oct-20