ogridblayer.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 463 行 · 第 1/2 页
CPP
463 行
/****************************************************************************** * $Id: ogridblayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: Implements OGRIDBLayer class, code shared between * the direct table access, and the generic SQL results * (based on ODBC and PG drivers). * Author: Oleg Semykin, oleg.semykin@gmail.com * ****************************************************************************** * Copyright (c) 2006, Oleg Semykin * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************/#include "cpl_conv.h"#include "ogr_idb.h"#include "cpl_string.h"CPL_CVSID("$Id: ogridblayer.cpp 10646 2007-01-18 02:38:10Z warmerdam $");/************************************************************************//* OGRIDBLayer() *//************************************************************************/OGRIDBLayer::OGRIDBLayer(){ poDS = NULL; bGeomColumnWKB = FALSE; pszFIDColumn = NULL; pszGeomColumn = NULL; poCurr = NULL; iNextShapeId = 0; poSRS = NULL; nSRSId = -2; // we haven't even queried the database for it yet. }/************************************************************************//* ~OGRIDBLayer() *//************************************************************************/OGRIDBLayer::~OGRIDBLayer(){ if( poCurr != NULL ) { poCurr->Close(); delete poCurr; poCurr = NULL; } if( pszGeomColumn ) CPLFree( pszGeomColumn ); if(pszFIDColumn) CPLFree( pszFIDColumn ); if( poFeatureDefn ) { poFeatureDefn->Release(); poFeatureDefn = NULL; } if( poSRS ) poSRS->Release();}/************************************************************************//* BuildFeatureDefn() *//* *//* Build feature definition from a set of column definitions *//* set on a statement. Sift out geometry and FID fields. *//************************************************************************/CPLErr OGRIDBLayer::BuildFeatureDefn( const char *pszLayerName, ITCursor *poCurr ){ poFeatureDefn = new OGRFeatureDefn( pszLayerName ); const ITTypeInfo * poInfo = poCurr->RowType(); int nRawColumns = poInfo->ColumnCount(); poFeatureDefn->Reference(); for( int iCol = 0; iCol < nRawColumns; iCol++ ) { const char * pszColName = poInfo->ColumnName(iCol); const ITTypeInfo * poTI = poInfo->ColumnType(iCol); const char * pszTypName = poTI->Name(); OGRFieldDefn oField( pszColName, OFTString ); oField.SetWidth( MAX(0,poTI->Bound()) ); if ( pszGeomColumn != NULL && EQUAL(pszColName,pszGeomColumn) ) continue; if ( EQUALN("st_", pszTypName, 3) && pszGeomColumn == NULL ) { // We found spatial column! pszGeomColumn = CPLStrdup(pszColName); if ( EQUAL("st_point", pszTypName) ) poFeatureDefn->SetGeomType( wkbPoint ); else if ( EQUAL("st_linestring", pszTypName) ) poFeatureDefn->SetGeomType( wkbLineString ); else if ( EQUAL("st_polygon", pszTypName) ) poFeatureDefn->SetGeomType( wkbPolygon ); else if ( EQUAL("st_multipoint", pszTypName) ) poFeatureDefn->SetGeomType( wkbMultiPoint ); else if ( EQUAL("st_multilinestring", pszTypName) ) poFeatureDefn->SetGeomType( wkbMultiLineString ); else if ( EQUAL("st_multipolygon", pszTypName) ) poFeatureDefn->SetGeomType( wkbMultiPolygon ); continue; } // Check other field types if ( EQUAL( pszTypName, "blob" ) || EQUAL( pszTypName, "byte" ) || EQUAL( pszTypName, "opaque" ) || EQUAL( pszTypName, "text" ) || EQUALN( pszTypName, "list", 4 ) || EQUALN( pszTypName, "collection", 10 ) || EQUALN( pszTypName, "row", 3 ) || EQUALN( pszTypName, "set", 3 ) ) { CPLDebug( "OGR_IDB", "'%s' column type not supported yet. Column '%s'", pszTypName, pszColName ); continue; } if ( EQUALN( pszTypName, "st_", 3 ) ) { oField.SetType( OFTBinary ); } else if ( EQUAL( pszTypName, "date" ) ) { oField.SetType( OFTDate ); } else if ( EQUAL( pszTypName, "datetime" ) ) { oField.SetType( OFTDateTime ); } else if ( EQUAL( pszTypName, "decimal" ) || EQUAL( pszTypName, "money" ) || EQUAL( pszTypName, "float" ) || EQUAL( pszTypName, "smallfloat" ) ) { oField.SetType( OFTReal ); oField.SetPrecision( MAX( 0, poTI->Scale() ) ); // -1 for numeric } else if ( EQUAL( pszTypName, "integer" ) || EQUAL( pszTypName, "serial" ) ) { oField.SetType( OFTInteger ); // 10 as hardcoded max int32 value length + 1 sig bit oField.SetWidth( 11 ); } else if ( EQUAL( pszTypName, "smallint" ) ) { oField.SetType( OFTInteger ); // 5 as hardcoded max int16 value length + 1 sig bit oField.SetWidth( 6 ); } else { // leave as string: // *char, character, character varing, *varchar // interval. int8, serial8 } poFeatureDefn->AddFieldDefn( &oField ); }/* -------------------------------------------------------------------- *//* If we don't already have an FID, check if there is a special *//* FID named column available. *//* -------------------------------------------------------------------- */ if( pszFIDColumn == NULL ) { const char *pszOGR_FID = CPLGetConfigOption("IDB_OGR_FID","OGR_FID"); if( poFeatureDefn->GetFieldIndex( pszOGR_FID ) != -1 ) pszFIDColumn = CPLStrdup(pszOGR_FID); } if( pszFIDColumn != NULL ) CPLDebug( "OGR_IDB", "Using column %s as FID for table %s.", pszFIDColumn, poFeatureDefn->GetName() ); else CPLDebug( "OGR_IDB", "Table %s has no identified FID column.", poFeatureDefn->GetName() ); return CE_None;}/************************************************************************//* ResetReading() *//************************************************************************/void OGRIDBLayer::ResetReading(){ iNextShapeId = 0;}/************************************************************************//* GetNextFeature() *//************************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?