📄 esri_e00_import.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Module Library: //
// Grid_IO //
// //
//-------------------------------------------------------//
// //
// ESRI_E00.cpp //
// //
// Copyright (C) 2003 by //
// Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. SAGA is free software; you //
// can redistribute it and/or modify it under the terms //
// of the GNU General Public License as published by the //
// Free Software Foundation; version 2 of the License. //
// //
// SAGA is distributed in the hope that it will be //
// useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU General Public //
// License for more details. //
// //
// You should have received a copy of the GNU General //
// Public License along with this program; if not, //
// write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// e-mail: oconrad@saga-gis.org //
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include "ESRI_E00_Import.h"
///////////////////////////////////////////////////////////
// //
// Import //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CESRI_E00_Import::CESRI_E00_Import(void)
{
//-----------------------------------------------------
// 1. info_Table...
Set_Name (_TL("Import ESRI E00 File"));
Set_Author (_TL("Copyrights (c) 2004 by Olaf Conrad"));
Set_Description (_TW(
"Import data sets from ESRI's E00 interchange format.\n\n"
"This import filter is based on the E00 format analysis of the GRASS GIS module "
"\'m.in.e00\' written by Michel J. Wurtz. Go to the "
"<a target=\"_blank\" href=\"http://grass.itc.it/\">GRASS GIS Hompage</a> "
"for more information.\n"
"The <a target=\"_blank\" href=\"http://avce00.maptools.org/e00compr/index.html\">\'E00Compr\' library</a> "
"written by Daniel Morissette has been used for e00 file access, so that "
"compressed e00 files also can be read.\n")
);
//-----------------------------------------------------
// 2. Parameters...
Parameters.Add_Grid_Output(
NULL , "GRID" , _TL("Grid"),
_TL("")
);
Parameters.Add_Shapes_Output(
NULL , "ARCS" , _TL("Arcs"),
_TL("")
);
Parameters.Add_Shapes_Output(
NULL , "SITES" , _TL("Sites"),
_TL("")
);
Parameters.Add_Shapes_Output(
NULL , "LABELS" , _TL("Labels"),
_TL("")
);
Parameters.Add_Shapes_Output(
NULL , "BND" , _TL("Boundary"),
_TL("")
);
Parameters.Add_Shapes_Output(
NULL , "TIC" , _TL("Tick Points"),
_TL("")
);
Parameters.Add_Table_Output(
NULL , "TABLE" , _TL("Table"),
_TL("")
);
Parameters.Add_FilePath(
NULL , "FILE" , _TL("File"),
_TL(""),
_TL("ESRI E00 Files|*.e00;*.e0*|All Files|*.*")
);
}
//---------------------------------------------------------
CESRI_E00_Import::~CESRI_E00_Import(void)
{}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CESRI_E00_Import::On_Execute(void)
{
bool bResult;
bResult = false;
hReadPtr = NULL;
if( Open(Parameters("FILE")->asString()) )
{
bResult = Load();
}
if( hReadPtr )
{
E00ReadClose(hReadPtr);
}
return( bResult );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CESRI_E00_Import::E00GotoLine(int iLine)
{
if( hReadPtr )
{
E00ReadRewind(hReadPtr);
while( E00ReadNextLine(hReadPtr) && hReadPtr->nInputLineNo != iLine );
return( hReadPtr->nInputLineNo == iLine );
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CESRI_E00_Import::Open(const SG_Char *FileName)
{
const char *Line;
//-----------------------------------------------------
if( FileName == NULL || (hReadPtr = E00ReadOpen(CSG_String(FileName).b_str())) == NULL )
{
Error_Set(CSG_String::Format(_TL("%s - not found\n"), FileName));
return( false );
}
//-----------------------------------------------------
if( (Line = E00ReadNextLine(hReadPtr)) == NULL )
{
Error_Set(CSG_String::Format(_TL("\"%s\" is not an Arc-info_Table Export file !\n"), FileName));
return( false );
}
//-----------------------------------------------------
if( strncmp(Line, "EXP", 3) )
{
Error_Set(CSG_String::Format(_TL("\"%s\" is not an Arc-info_Table Export file !\n"), FileName));
return( false );
}
//-----------------------------------------------------
e00_Name = FileName;
return( true );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CESRI_E00_Import::Load(void)
{
const char *line;
int prec_grd, prec_arc, prec_lab, prec_pal;
long current_line,
offset_grd = 0,
offset_arc = 0,
offset_lab = 0,
offset_pal = 0;
double scale = 1.0;
TSG_Shape_Type shape_type;
CSG_Grid *pGrid;
CSG_Shapes *pShapes;
//-----------------------------------------------------
pPAT = NULL;
pAAT = NULL;
//-----------------------------------------------------
while( (line = E00ReadNextLine(hReadPtr)) != NULL && strncmp(line, "EOS", 3) )
{
current_line = hReadPtr->nInputLineNo;
// GRID SECTION
if( !strncmp(line, "GRD ", 5) )
{
offset_grd = current_line;
prec_grd = line[5] - '2';
skip("EOG");
continue;
}
// ARC SECTION
if( !strncmp(line, "ARC ", 5) )
{
offset_arc = current_line;
prec_arc = line[5] - '2';
skip_arc(prec_arc);
continue;
}
// POLYGON TOPOLOGY
if( !strncmp(line, "PAL ", 5)
|| !strncmp(line, "PFF ", 5) )
{
offset_pal = current_line;
prec_pal = line[5] - '2';
skip_pal(prec_pal);
continue;
}
// CENTROID SECTION
if( !strncmp(line, "CNT ", 5) )
{
skip_dat();
continue;
}
// LABEL SECTION
if( !strncmp(line, "LAB ", 5))
{
offset_lab = current_line;
prec_lab = line[5] - '2';
skip_lab(prec_lab);
continue;
}
// INFO SECTION
if( !strncmp(line, "IFO ", 5) )
{
info_Get_Tables();
continue;
}
// PROJECTION INFOS
if( !strncmp(line, "PRJ ", 5) )
{
scale = getproj();
continue;
}
// Annotations (text). To be imported ? Does anybody have an idea ?
if( !strncmp(line, "TXT ", 5) )
{
skip_txt(line[5] - '2');
continue;
}
// Mask description ? Noting to do with it
if( !strncmp(line, "MSK ", 5) )
{
skip_msk();
continue;
}
// TOLERANCE SECTION. Should we really use it ?
if( !strncmp(line, "TOL ", 5) )
{
skip_dat();
continue;
}
// UNKNOW KEYWORD SECTION. Don't know what to do with. Does anybody have an idea?
if( !strncmp(line, "LNK ", 5) )
{
skip("END OF LINK DATA");
continue;
}
// SPATIAL INDEX SECTION. Noting to do with it
if( !strncmp(line, "SIN ", 5) )
{
skip("EOX");
continue;
}
// Line pattern and palette. Shade pattern and palette end same as e00 archive !
if( !strncmp(line, "CLN ", 5)
|| !strncmp(line, "CSH ", 5) )
{
skip("EOS");
continue;
}
// Font description ? Noting to do with it
if( !strncmp(line, "FNT ", 5) )
{
skip("EOF");
continue;
}
// PLOT SECTION. Why should we import it ?
if( !strncmp(line, "PLT ", 5) )
{
skip("EOP");
continue;
}
// LOG SECTION. Nothing to do with it
if( !strncmp(line, "LOG ", 5) )
{
skip("EOL");
continue;
}
if( !strncmp(line, "RPL ", 5) // Specific to regions. Contains PAL formated data for each subclass
|| !strncmp(line, "RXP ", 5) // Specific to regions. Seems to link regions IDs to PAL polygons IDs
|| !strncmp(line, "TX6 ", 5) // Other kind of annotations not same termination. Other differences ?
|| !strncmp(line, "TX7 ", 5) ) // Very close from TX6. So same questions and same rules...
{
skip("JABBERWOCKY");
continue;
}
}
//-----------------------------------------------------
switch( pPAT ? (pAAT ? 3 : 2) : (pAAT ? 1 : 0) )
{
case 0: default:
shape_type = offset_arc != 0 ? SHAPE_TYPE_Line : SHAPE_TYPE_Point;
break;
case 1: // pAAT
shape_type = SHAPE_TYPE_Line;
break;
case 2: // pPAT
shape_type = offset_arc != 0 ? SHAPE_TYPE_Polygon : SHAPE_TYPE_Point;
break;
case 3: // pAAT && pPAT
shape_type = offset_pal != 0 || offset_lab != 0 ? SHAPE_TYPE_Polygon : SHAPE_TYPE_Line;
break;
}
//-----------------------------------------------------
// Extracting useful information as noted before...
//-----------------------------------------------------
if( offset_grd > 0 )
{
E00GotoLine(offset_grd);
if( (pGrid = getraster (prec_grd, scale)) != NULL )
{
pGrid->Set_Name(e00_Name);
Parameters("GRID")->Set_Value(pGrid);
}
}
//-----------------------------------------------------
if( offset_arc != 0 )
{
E00GotoLine(offset_arc);
if( (pShapes = getarcs (prec_arc, scale, shape_type)) != NULL )
{
pShapes->Set_Name(e00_Name);
Parameters("ARCS")->Set_Value(pShapes);
}
}
//-----------------------------------------------------
if( offset_lab != 0 && shape_type == SHAPE_TYPE_Point )
{
E00GotoLine(offset_lab);
if( (pShapes = getsites (prec_lab, scale)) != NULL )
{
pShapes->Set_Name(e00_Name);
Parameters("SITES")->Set_Value(pShapes);
}
}
//-----------------------------------------------------
if( offset_lab != 0 && shape_type != SHAPE_TYPE_Point )
{
E00GotoLine(offset_lab);
if( (pShapes = getlabels(prec_lab, scale)) != NULL )
{
pShapes->Set_Name(e00_Name);
Parameters("LABELS")->Set_Value(pShapes);
}
}
//-----------------------------------------------------
return( true );
}
///////////////////////////////////////////////////////////
// //
// Grid //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Grid * CESRI_E00_Import::getraster(int prec, double scale)
{
const char *line;
int x, y, ix;
long rows, cols, depth, p[5];
float f[5];
double xres, yres, xmin, ymin, xmax, ymax, nul_val, d[3];
CSG_Grid *pGrid;
//-----------------------------------------------------
if( (line = E00ReadNextLine(hReadPtr)) == NULL )
return( NULL );
// sscanf(line, "%ld%ld%ld", &cols, &rows, &depth, &nul_val);
sscanf(line, "%ld%ld%ld%lf", &cols, &rows, &depth, &nul_val);
if( (line = E00ReadNextLine(hReadPtr)) == NULL )
return( NULL );
sscanf(line, "%lf%lf", &xres, &yres);
if( (line = E00ReadNextLine(hReadPtr)) == NULL )
return( NULL );
sscanf(line, "%lf%lf", &xmin, &ymin);
if( (line = E00ReadNextLine(hReadPtr)) == NULL )
return( NULL );
sscanf(line, "%lf%lf", &xmax, &ymax);
xmax = xmax * scale;
xmin = xmin * scale;
ymax = ymax * scale;
ymin = ymin * scale;
xres = xres * scale;
yres = yres * scale;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -