From 080f2b0ab463559891b6fa240432373f936e3386 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sun, 4 Dec 2011 12:18:14 +0000 Subject: [PATCH] fpvectorial: Starts the las reader git-svn-id: trunk@33950 - --- .gitattributes | 1 + components/fpvectorial/fpvectorial.pas | 4 + components/fpvectorial/fpvectorialpkg.lpk | 10 +- components/fpvectorial/fpvectorialpkg.pas | 2 +- components/fpvectorial/lasvectorialreader.pas | 134 ++++++++++++++++++ 5 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 components/fpvectorial/lasvectorialreader.pas diff --git a/.gitattributes b/.gitattributes index aab83aee13..65d630ea2c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -976,6 +976,7 @@ components/fpvectorial/fpvectorialpkg.lpk svneol=native#text/plain components/fpvectorial/fpvectorialpkg.pas svneol=native#text/plain components/fpvectorial/fpvtocanvas.pas svneol=native#text/plain components/fpvectorial/fpvutils.pas svneol=native#text/plain +components/fpvectorial/lasvectorialreader.pas svneol=native#text/plain components/fpvectorial/pdfvectorialreader.pas svneol=native#text/plain components/fpvectorial/pdfvrlexico.pas svneol=native#text/plain components/fpvectorial/pdfvrsemantico.pas svneol=native#text/plain diff --git a/components/fpvectorial/fpvectorial.pas b/components/fpvectorial/fpvectorial.pas index 3ad6dc96cf..1a424100c7 100644 --- a/components/fpvectorial/fpvectorial.pas +++ b/components/fpvectorial/fpvectorial.pas @@ -35,6 +35,8 @@ type vfPDF, vfSVG, vfCorelDrawCDR, vfWindowsMetafileWMF, { CAD formats } vfDXF, + { Geospatial formats } + vfLAS, { Printing formats } vfPostScript, vfEncapsulatedPostScript, { GCode formats } @@ -50,6 +52,7 @@ const STR_WINMETAFILE_EXTENSION = '.wmf'; STR_AUTOCAD_EXCHANGE_EXTENSION = '.dxf'; STR_ENCAPSULATEDPOSTSCRIPT_EXTENSION = '.eps'; + STR_LAS_EXTENSION = '.las'; type { Pen, Brush and Font } @@ -1299,6 +1302,7 @@ begin else if AnsiCompareText(lExt, STR_WINMETAFILE_EXTENSION) = 0 then Result := vfWindowsMetafileWMF else if AnsiCompareText(lExt, STR_AUTOCAD_EXCHANGE_EXTENSION) = 0 then Result := vfDXF else if AnsiCompareText(lExt, STR_ENCAPSULATEDPOSTSCRIPT_EXTENSION) = 0 then Result := vfEncapsulatedPostScript + else if AnsiCompareText(lExt, STR_LAS_EXTENSION) = 0 then Result := vfLAS else raise Exception.Create('TvVectorialDocument.GetFormatFromExtension: The extension (' + lExt + ') doesn''t match any supported formats.'); end; diff --git a/components/fpvectorial/fpvectorialpkg.lpk b/components/fpvectorial/fpvectorialpkg.lpk index 9eb8097ce7..d1d6427a55 100644 --- a/components/fpvectorial/fpvectorialpkg.lpk +++ b/components/fpvectorial/fpvectorialpkg.lpk @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -61,6 +61,10 @@ + + + + @@ -69,7 +73,7 @@ - + diff --git a/components/fpvectorial/fpvectorialpkg.pas b/components/fpvectorial/fpvectorialpkg.pas index bf0888c216..d22683747d 100644 --- a/components/fpvectorial/fpvectorialpkg.pas +++ b/components/fpvectorial/fpvectorialpkg.pas @@ -10,7 +10,7 @@ uses svgvectorialwriter, fpvtocanvas, fpvectorial, fpvectbuildunit, dxfvectorialreader, cdrvectorialreader, avisozlib, avisocncgcodewriter, avisocncgcodereader, svgvectorialreader, epsvectorialreader, fpvutils, - LazarusPackageIntf; + lasvectorialreader, LazarusPackageIntf; implementation diff --git a/components/fpvectorial/lasvectorialreader.pas b/components/fpvectorial/lasvectorialreader.pas new file mode 100644 index 0000000000..e4daaaa29c --- /dev/null +++ b/components/fpvectorial/lasvectorialreader.pas @@ -0,0 +1,134 @@ +{ +lasvectorialreader.pas + +Reads geospatial data encoded in the ASPRS LASer (LAS) file format version 1.3 + +LAS file format specification obtained from: + +http://www.asprs.org/a/society/committees/standards/lidar_exchange_format.html +LAS 1.3 r11 + +All data is in little-endian format. + +AUTHORS: Felipe Monteiro de Carvalho + +License: The same modified LGPL as the Free Pascal RTL + See the file COPYING.modifiedLGPL for more details +} +unit lasvectorialreader; + +{$ifdef fpc} + {$mode delphi} +{$endif} + +{$define FPVECTORIALDEBUG_LAS} + +interface + +uses + Classes, SysUtils, + //avisozlib, + fpvectorial; + +type + // LAS data types + laschar = Char; // or ShortInt + lasuchar = Byte; + lasshort = Smallint; + lasushort = Word; + laslong = Integer; + lasulong = Cardinal; + laslonglong = Int64; + lasulonglong = QWord; + lasdouble = double; + + // PUBLIC HEADER BLOCK + TLASPublicHeaderBlock = packed record + FileSignatureLASF: array[0..3] of laschar; + FileSourceID: lasushort; + GlobalEncoding: lasushort; + ProjectIDGUIDdata1: lasulong; // Optional + ProjectIDGUIDdata2: lasushort; // Optional + ProjectIDGUIDdata3: lasushort; // Optional + ProjectIDGUIDdata4: array[0..7] of lasuchar;// Optional + VersionMajor: lasuchar; + VersionMinor: lasuchar; + SystemIdentifier: array[0..31] of laschar; + GeneratingSoftware: array[0..31] of laschar; + FileCreationDayofYear: lasushort; + FileCreationYear: lasushort; +{Number of Variable Length Records +Point Data Format ID (0-99 for spec) +Point Data Record Length +Number of point records +Number of points by return +X scale factor +Y scale factor +Z scale factor +X offset +Y offset +Z offset +Max X +Min X +Max Y +Min Y +Max Z +Min Z +Start of Waveform Data Packet Record +Any field in the Public Header Block that is not required and is not used must be zero filled.} + end; + + { TvLASVectorialReader } + + TvLASVectorialReader = class(TvCustomVectorialReader) + private + {$ifdef FPVECTORIALDEBUG_LAS} + procedure DebugOutPublicHeaderBlock(); + {$endif} + public + PublicHeaderBlock: TLASPublicHeaderBlock; + { General reading methods } + procedure ReadFromStream(AStream: TStream; AData: TvVectorialDocument); override; + end; + +implementation + +{$ifdef FPVECTORIALDEBUG_LAS} +procedure TvLASVectorialReader.DebugOutPublicHeaderBlock; +begin + WriteLn(Format('FileSignatureLASF = %s = %x %x %x %x', + [PublicHeaderBlock.FileSignatureLASF, + PublicHeaderBlock.FileSignatureLASF[0], + PublicHeaderBlock.FileSignatureLASF[1], + PublicHeaderBlock.FileSignatureLASF[2], + PublicHeaderBlock.FileSignatureLASF[3]])); + WriteLn(Format('FileSourceID = %x', [PublicHeaderBlock.FileSourceID])); + WriteLn(Format('GlobalEncoding = %x', [PublicHeaderBlock.GlobalEncoding])); + WriteLn(Format('ProjectIDGUIDdata1 = %x', [PublicHeaderBlock.ProjectIDGUIDdata1])); + WriteLn(Format('ProjectIDGUIDdata2 = %x', [PublicHeaderBlock.ProjectIDGUIDdata2])); + WriteLn(Format('ProjectIDGUIDdata3 = %x', [PublicHeaderBlock.ProjectIDGUIDdata3])); +// WriteLn(Format('ProjectIDGUIDdata2 = %x', [ProjectIDGUIDdata2])); + WriteLn(Format('VersionMajor = %x', [PublicHeaderBlock.VersionMajor])); + WriteLn(Format('VersionMinor = %x', [PublicHeaderBlock.VersionMinor])); + WriteLn(Format('SystemIdentifier = %s', [PublicHeaderBlock.SystemIdentifier])); + WriteLn(Format('GeneratingSoftware = %s', [PublicHeaderBlock.GeneratingSoftware])); + WriteLn(Format('FileCreationDayofYear = %x', [PublicHeaderBlock.FileCreationDayofYear])); + WriteLn(Format('FileCreationYear = %x', [PublicHeaderBlock.FileCreationYear])); +end; +{$endif} + +procedure TvLASVectorialReader.ReadFromStream(AStream: TStream; + AData: TvVectorialDocument); +begin + AStream.Read(PublicHeaderBlock, SizeOf(TLASPublicHeaderBlock)); + {$ifdef FPVECTORIALDEBUG_LAS} + DebugOutPublicHeaderBlock(); + {$endif} +end; + +initialization + + RegisterVectorialReader(TvLASVectorialReader, vfLAS); + +end. +