ezsdlimport.pas
来自「很管用的GIS控件」· PAS 代码 · 共 670 行 · 第 1/2 页
PAS
670 行
End;
SDLPtList.Clear;
end;
procedure TEzSDLImport.AddSourceFieldData(DestLayer: TEzBaseLayer; DestRecno: Integer);
begin
If (DestLayer.DBTable = Nil) Or (LastPointCount <= 0) Then Exit;
DestLayer.DBTable.Recno:= DestRecno;
DestLayer.DBTable.BeginTrans;
Try
with DestLayer.DBTable do
begin
Edit;
StringPut( 'TYPE', Columninfo[0] );
StringPut( 'NAME', Columninfo[1] );
StringPut( 'KEY', Columninfo[2] );
StringPut( 'URLLINK', Columninfo[3] );
StringPut( 'NUMPTS', Columninfo[4] );
Post;
EndTrans;
end;
Except
DestLayer.DBTable.RollbackTrans;
raise;
End;
end;
function TEzSDLImport.GetSourceExtension: TEzRect;
begin
Result:= Rect2d(minx,miny,maxx,maxy);
end;
procedure TEzSDLImport.GetSourceFieldList(FieldList: TStrings);
begin
FieldList.Add('UID;N;12;0');
FieldList.Add('TYPE;C;1;0');
FieldList.Add('NAME;C;255;0');
FieldList.Add('KEY;C;255;0');
FieldList.Add('URLLINK;C;255;0');
FieldList.Add('NUMPTS;N;5;0');
end;
procedure TEzSDLImport.ImportEnd;
begin
CloseFile( SDLInputFile );
end;
{ TSDLPointList }
constructor TSDLPointList.Create;
begin
Inherited Create;
FPoints:= TEzVector.Create(1000);
FVectorList:= TList.Create;
end;
Destructor TSDLPointList.Destroy;
begin
FPoints.free;
ClearVectorList;
FVectorList.Free;
inherited;
end;
procedure TSDLPointList.Clear;
begin
FPoints.clear;
ClearVectorList;
end;
procedure TSDLPointList.ClearVectorList;
var
I: Integer;
Begin
for I:= 0 to FVectorList.Count-1 do
TEzVector(FVectorList[I]).Free;
FVectorList.Clear;
End;
function TSDLPointList.ArrangePartPos: integer;
var
partStart: TEzPoint;
isPartStart: Boolean;
I: integer;
TempV: TEzVector;
begin
ClearVectorList;
isPartStart := False;
TempV:= Nil;
for i := 0 to FPoints.Count - 1 do
begin
if not isPartStart then
begin
TempV:= TEzVector.Create(10);
FVectorList.Add( TempV );
partStart:= FPoints[i];
TempV.Add( partStart );
isPartStart := True;
end
else if EqualPoint2d(partStart, FPoints[i]) then
begin
If FType = soPolygon then
TempV.Add( FPoints[i] );
isPartStart := False;
end else
begin
TempV.Add( FPoints[i] );
end;
end;
Result := FVectorList.Count;
end;
{ TEzSDLExport }
constructor TEzSDLExport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCoordList := TStringList.Create;
end;
destructor TEzSDLExport.Destroy;
begin
FCoordList.Free;
inherited;
end;
procedure TEzSDLExport.ExportInitialize;
var
S: string;
procedure writeHeader(var Txt: Textfile);
begin
writeln(Txt, '; Lines starting with "#" are header data generated by SDF Loader.');
writeln(Txt, '; Do not edit these lines.');
writeln(Txt, '#VERSION=2.1');
writeln(Txt, '#METADATA_BEGIN=CoordinateSystem');
writeln(Txt, '#GEOGCS["LL84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,0],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0],UNIT["Degrees",1]]');
writeln(Txt, '#METADATA_END');
end;
begin
s := ChangeFileExt(FileName, '.');
{$I-}
AssignFile(SDLOutfileL, FileName + '_L.SDL');
AssignFile(SDLOutfileM, FileName + '_M.SDL');
AssignFile(SDLOutfileP, FileName + '_P.SDL');
Rewrite(SDLOutfileL);
Rewrite(SDLOutfileM);
Rewrite(SDLOutfileP);
{$I+}
FCanceled := IOResult <> 0;
If FCanceled Then Exit;
WriteHeader(SDLOutfileL);
WriteHeader(SDLOutfileM);
WriteHeader(SDLOutfileP);
end;
procedure TEzSDLExport.ExportEnd;
begin
CloseFile(SDLOutfileL);
CloseFile(SDLOutfileM);
CloseFile(SDLOutfileP);
end;
procedure TEzSDLExport.ExportEntity(SourceLayer: TEzBaseLayer; Entity: TEzEntity);
var
SDLType: TSDLObjType;
s: string;
ENTPointCount: integer;
function GetNumPTS(SDL: TSDLObjType; ENT: TEzEntity): integer;
begin
Result := 0;
if ENT.Points.Parts.Count > 0 then
case SDL of
soPoint: Result := ENT.Points.Count;
// Result := 1;
soLine: Result := ENT.Points.Count + ENT.Points.Parts.Count - 1;
soPolygon: Result := ENT.Points.Count;
end
else
Result := ENT.Points.Count;
end;
procedure WriteCoord(var Txt: TextFile; coordList: TStringList);
var
i: integer;
begin
for i := 0 to CoordList.Count - 1 do
Writeln(Txt, CoordList.Strings[i]);
end;
Procedure SetCoordListForWrite(Ent: TEzEntity);
var
i, PointCount, PartCount: integer;
tmpList: TStringList;
partStartCoord: string;
NextPartNewStart: string;
insertCount : integer;
begin
tmpList := TStringList.Create;
try
FCoordList.Clear;
PointCount := ENT.Points.Count;
PartCount := ENT.Points.Parts.Count;
for i := 0 to PointCount - 1 do
tmpList.Add(FloatToStr(ENT.Points[i].Y) + ',' + FloatToStr(ENT.Points[i].X));
if ((SDLType = soline) and (PartCount > 0)) then
begin
insertCount := 0;
for i := 1 to PartCount - 1 do
begin
partStartCoord := FloatToStr(ENT.Points[ENT.Points.Parts[i - 1]].Y) + ',' +
FloatToStr(ENT.Points[ENT.Points.Parts[i - 1]].X);
NextPartNewStart := FloatToStr(ENT.Points[ENT.Points.Parts[i] - 2].Y) + ',' +
FloatToStr(ENT.Points[ENT.Points.Parts[i] - 1].X);
if tmpList.Strings[ENT.Points.Parts[i] + insertCount - 1] = partStartCoord then
begin
tmpList.Insert(ENT.Points.Parts[i] + insertCount, partStartCoord);
inc(insertCount);
tmpList.Insert(ENT.Points.Parts[i] + insertCount, NextPartNewStart);
inc(insertCount);
end;
tmpList.Insert(ENT.Points.Parts[i] + insertCount, partStartCoord);
inc(insertCount);
end;
end;
FCoordList.Add(tmpList.Strings[0]);
for i := 1 to tmpList.Count - 1 do
begin
if ((FCoordList.Strings[0] = tmpList.Strings[i]) and (PartCount < 2) and (i <> tmpList.Count - 1)) then
case SDLType of
soLine:
begin
FCoordList.Add(tmpList.Strings[i]);
FCoordList.Add(tmpList.Strings[i - 1]);
end;
soPolygon:
FCoordList.Add(FCoordList.Strings[0]);
end;
FCoordList.Add(tmpList.Strings[i]);
end;
finally
tmpList.Free;
end;
end;
begin
case Entity.EntityID of
idPlace, idTrueTypeText: SDLType := soPoint;
idPolyline: SDLType := soLine;
idPolygon: SDLType := soPolygon;
idRectangle: SDLType := soPolygon;
idArc: SDLType := soline;
idEllipse: SDLType := soPolygon;
idPictureRef, idBandsBitmap, idPersistBitmap: SDLType := soPolygon;
idSpline: SDLType := soline;
idTable: SDLType := soPolygon;
else
exit;
end;
S := '';
case SDLType of
soPoint: s := 'M,';
soLine: s := 'L,';
soPolygon: s := 'P,';
end;
SetCoordListForWrite(Entity);
ENTPointCount := FCoordList.Count;
// ENTPointCount := GetNumPts(SDLType, ENT);
// if FLayer.EntHeader.UseDBF = false then
// begin
S := S + '"","' + InttoStr(SourceLayer.Recno) + '","",' + inttostr(ENTPointCount);
{ end else begin
FLayer.DataSet.RecNo := idx;
Fld_Name := FLayer.DataSet.FieldByName('NAME');
FLD_KEY := FLayer.DataSet.FieldByName('KEY');
FLD_URLLink := FLayer.DataSet.FieldByName('URLLINK');
// Name of Feature in Mapguide SDL Field
if FLD_NAME <> nil then S := S + '"' + Fld_Name.AsString + '"'
else S := S + '""';
// KEY of Feature in Mapguide SDL Field
if FLD_KEY <> nil then S := S + ',"' + Fld_KEY.AsString + '"'
else S := S + ',"' + FLayer.DataSet.fieldbyname('IDMAP').asString + '"';
// KEY of Feature in Mapguide SDL Field
if FLD_URLLink <> nil then S := S + ',"' + Fld_URLLink.AsString + '",'
else S := S + ',"",';
S := S + inttostr(EntPointCount);
end; // end of UseDBF
}
case SDLType of
soPoint:
begin
Writeln(SDLOutfileM, S);
WriteCoord(SDLOutFileM, FCoordList);
end;
soLine:
begin
Writeln(SDLOutfileL, S);
WriteCoord(SDLOutFileL, FCoordList);
end;
soPolygon:
begin
Writeln(SDLOutfileP, S);
WriteCoord(SDLOutFileP, FCoordList);
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?