TSHPFeatureFoundEvent = procedure (NewFeature: TSimpleFeature) of object;
TShapeReaderThread = class(TThread)
private
FFileName: String;
FBoundingBoxMaxX: Double;
FBoundingBoxMaxY: Double;
FBoundingBoxMinX: Double;
FBoundingBoxMinY: Double;
FOnFeatureFound: TSHPFeatureFoundEvent;
FSuccess: Boolean;
procedure ReadHeader(fs: TFileStream);
function ReadInt32BE(fs: TFileStream): Integer;
function ReadInt32LE(fs: TFileStream): Integer;
function ReadDoubleLE(fs: TFileStream): Double;
procedure SkipDoubles(fs: TFileStream; Count: Integer);
procedure SyncOnFound;
protected
procedure Execute; override;
public
constructor Create(const FName: String);
// properties to read in OnTerminate
property Success: Boolean read FSuccess;
property ErrorMessage: String read FErrorMessage;
property BoundingBoxMinX: Double read FBoundingBoxMinX;
property BoundingBoxMinY: Double read FBoundingBoxMinY;
property BoundingBoxMaxX: Double read FBoundingBoxMaxX;
property BoundingBoxMaxY: Double read FBoundingBoxMaxY;
// event fires with Synchronize
property OnFeatureFound: TSHPFeatureFoundEvent read FOnFeatureFound write FOnFeatureFound;
// or several features at once; fires in an interval with Synchronize
// property OnFeaturesFound: TSHPFeaturesFoundEvent read FOnFeaturesFound write FOnFeaturesFound;
end;
TSimpleShapefileWithThread = class
private
fFeatures: TObjectList;
FOnLoaded: TNotifyEvent;
// event handler for thread
procedure ShapeReaderFeatureFound(NewFeature: TSimpleFeature);
// or several features at once
// procedure ShapeReaderFeaturesFound(NewFeatureList: TObjectList);
procedure ShapeReaderTerminate(Sender: TObject);
public
BoundingBoxMinX, BoundingBoxMinY, BoundingBoxMaxX, BoundingBoxMaxY: Double;
constructor Create;
destructor Destroy; override;
procedure LoadFromFile(const AFileName: string);
property Features: TObjectList read fFeatures;
property OnLoaded: TNotifyEvent read FOnLoaded write FOnLoaded;
end;