📄 ogrocitablelayer.cpp
字号:
/****************************************************************************** * $Id: ogrocitablelayer.cpp,v 1.32 2005/02/22 12:57:51 fwarmerdam Exp $ * * Project: Oracle Spatial Driver * Purpose: Implementation of the OGROCITableLayer class. This class provides * layer semantics on a table, but utilizing alot of machinery from * the OGROCILayer base class. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com> * * 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. ****************************************************************************** * * $Log: ogrocitablelayer.cpp,v $ * Revision 1.32 2005/02/22 12:57:51 fwarmerdam * use OGRLayer base spatial filter support * * Revision 1.31 2005/02/10 15:46:02 fwarmerdam * added GEOMETRY_NAME layer creation option * * Revision 1.30 2004/11/22 19:24:15 fwarmerdam * added support for a list of tables in the datasource name * * Revision 1.29 2004/11/09 02:49:12 fwarmerdam * Don't add user_sdo_geom_metadata record till finalize (layer load complete) * time as that is when we have all the diminfo details. Inserts of metadata * records with NULL diminfos fails in Oracle 10 due to new constraints. * * Revision 1.28 2004/09/28 17:19:25 fwarmerdam * Added untested support for OCI_FID config variable for FID column name. * * Revision 1.27 2003/09/18 15:32:59 warmerda * Added view support as per bug 394 * * Revision 1.26 2003/09/17 16:36:33 warmerda * fixed setting of dimension for point objects * * Revision 1.25 2003/09/13 03:48:36 warmerda * actually use the papaeFieldInd to write NULL fields properly in bound create * * Revision 1.24 2003/05/21 03:54:01 warmerda * expand tabs * * Revision 1.23 2003/04/22 19:37:51 warmerda * Added sync to disk * * Revision 1.22 2003/04/11 16:27:42 warmerda * add support for bound feature writing in OGROCITableLayer * * Revision 1.21 2003/04/04 06:18:08 warmerda * first pass implementation of loader support * * Revision 1.20 2003/02/06 21:16:37 warmerda * restructure to handle elem_info indirectly like ordinals * * Revision 1.19 2003/01/15 05:47:06 warmerda * fleshed out SRID writing support in newly created geometries * * Revision 1.18 2003/01/15 05:36:14 warmerda * start work on creating feature geometry with SRID * * Revision 1.17 2003/01/14 22:15:02 warmerda * added logic to order rings properly * * Revision 1.16 2003/01/14 16:59:03 warmerda * added field truncation support * * Revision 1.15 2003/01/14 15:31:08 warmerda * added fallback support if no spatial index available * * Revision 1.14 2003/01/14 15:11:00 warmerda * Added layer creation options caching on layer. * Set SRID in spatial query. * Support user override of DIMINFO bounds in FinalizeNewLayer(). * Support user override of indexing options, or disabling of indexing. * * Revision 1.13 2003/01/13 13:50:13 warmerda * dont quote table names, it doesnt seem to work with userid.tablename * * Revision 1.12 2003/01/10 22:31:53 warmerda * no longer encode ordinates into SQL statement when creating features * * Revision 1.11 2003/01/09 21:19:12 warmerda * improved data type support, get/set precision * * Revision 1.10 2003/01/07 22:24:35 warmerda * added SRS support * * Revision 1.9 2003/01/07 21:14:20 warmerda * implement GetFeature() and SetFeature() * * Revision 1.8 2003/01/07 18:16:01 warmerda * implement spatial filtering in Oracle, re-enable index build * * Revision 1.7 2003/01/06 18:00:34 warmerda * Restructure geometry translation ... collections now supported. * Dimension is now a layer wide attribute. * Update dimension info in USER_SDO_GEOM_METADATA on close. * * Revision 1.6 2003/01/02 21:51:05 warmerda * fix quote escaping * * Revision 1.5 2002/12/29 19:43:59 warmerda * avoid some warnings * * Revision 1.4 2002/12/29 03:48:58 warmerda * fixed memory bug in CreateFeature() * * Revision 1.3 2002/12/28 20:06:31 warmerda * minor CreateFeature improvements * * Revision 1.2 2002/12/28 04:38:36 warmerda * converted to unix file conventions * * Revision 1.1 2002/12/28 04:07:27 warmerda * New * */#include "ogr_oci.h"#include "cpl_conv.h"#include "cpl_string.h"CPL_CVSID("$Id: ogrocitablelayer.cpp,v 1.32 2005/02/22 12:57:51 fwarmerdam Exp $");static int nDiscarded = 0;static int nHits = 0;#define HSI_UNKNOWN -2/************************************************************************//* OGROCITableLayer() *//************************************************************************/OGROCITableLayer::OGROCITableLayer( OGROCIDataSource *poDSIn, const char * pszTableName, int nSRIDIn, int bUpdate, int bNewLayerIn ){ poDS = poDSIn; pszQuery = NULL; pszWHERE = CPLStrdup( "" ); pszQueryStatement = NULL; bUpdateAccess = bUpdate; bNewLayer = bNewLayerIn; iNextShapeId = 0; iNextFIDToWrite = 1; bValidTable = FALSE; if( bNewLayerIn ) bHaveSpatialIndex = FALSE; else bHaveSpatialIndex = HSI_UNKNOWN; poFeatureDefn = ReadTableDefinition( pszTableName ); nSRID = nSRIDIn; if( nSRID == -1 ) nSRID = LookupTableSRID(); poSRS = poDSIn->FetchSRS( nSRID ); if( poSRS != NULL ) poSRS->Reference(); hOrdVARRAY = NULL; hElemInfoVARRAY = NULL; poBoundStatement = NULL; nWriteCacheMax = 0; nWriteCacheUsed = 0; pasWriteGeoms = NULL; papsWriteGeomMap = NULL; pasWriteGeomInd = NULL; papsWriteGeomIndMap = NULL; papWriteFields = NULL; papaeWriteFieldInd = NULL; panWriteFIDs = NULL; ResetReading();}/************************************************************************//* ~OGROCITableLayer() *//************************************************************************/OGROCITableLayer::~OGROCITableLayer(){ int i; if( bNewLayer ) FinalizeNewLayer(); CPLFree( panWriteFIDs ); if( papWriteFields != NULL ) { for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { CPLFree( papWriteFields[i] ); CPLFree( papaeWriteFieldInd[i] ); } } CPLFree( papWriteFields ); CPLFree( papaeWriteFieldInd ); if( poBoundStatement != NULL ) delete poBoundStatement; CPLFree( pasWriteGeomInd ); CPLFree( papsWriteGeomIndMap ); CPLFree( papsWriteGeomMap ); CPLFree( pasWriteGeoms ); CPLFree( pszQuery ); CPLFree( pszWHERE ); if( poSRS != NULL && poSRS->Dereference() == 0 ) delete poSRS;}/************************************************************************//* ReadTableDefinition() *//* *//* Build a schema from the named table. Done by querying the *//* catalog. *//************************************************************************/OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ){ OGROCISession *poSession = poDS->GetSession(); sword nStatus; OGRFeatureDefn *poDefn = new OGRFeatureDefn( pszTable ); poDefn->Reference();/* -------------------------------------------------------------------- *//* Do a DescribeAll on the table. *//* -------------------------------------------------------------------- */ OCIParam *hAttrParam = NULL; OCIParam *hAttrList = NULL; nStatus = OCIDescribeAny( poSession->hSvcCtx, poSession->hError, (dvoid *) pszTable, strlen(pszTable), OCI_OTYPE_NAME, OCI_DEFAULT, OCI_PTYPE_TABLE, poSession->hDescribe ); if( poSession->Failed( nStatus, "OCIDescribeAny" ) ) { nStatus = OCIDescribeAny(poSession->hSvcCtx, poSession->hError, (dvoid *)pszTable, strlen(pszTable), OCI_OTYPE_NAME, OCI_DEFAULT, OCI_PTYPE_VIEW, poSession->hDescribe ); if( poSession->Failed( nStatus, "OCIDescribeAny" ) ) return poDefn; } if( poSession->Failed( OCIAttrGet( poSession->hDescribe, OCI_HTYPE_DESCRIBE, &hAttrParam, 0, OCI_ATTR_PARAM, poSession->hError ), "OCIAttrGet(ATTR_PARAM)") ) return poDefn; if( poSession->Failed( OCIAttrGet( hAttrParam, OCI_DTYPE_PARAM, &hAttrList, 0, OCI_ATTR_LIST_COLUMNS, poSession->hError ), "OCIAttrGet(ATTR_LIST_COLUMNS)" ) ) return poDefn;/* -------------------------------------------------------------------- *//* What is the name of the column to use as FID? This defaults *//* to OGR_FID but we allow it to be overridden by a config *//* variable. Ideally we would identify a column that is a *//* primary key and use that, but I'm not yet sure how to *//* accomplish that. *//* -------------------------------------------------------------------- */ const char *pszExpectedFIDName = CPLGetConfigOption( "OCI_FID", "OGR_FID" );/* -------------------------------------------------------------------- *//* Parse the returned table information. *//* -------------------------------------------------------------------- */ for( int iRawFld = 0; TRUE; iRawFld++ ) { OGRFieldDefn oField( "", OFTString); OCIParam *hParmDesc; ub2 nOCIType; ub4 nOCILen; sword nStatus; nStatus = OCIParamGet( hAttrList, OCI_DTYPE_PARAM, poSession->hError, (dvoid**)&hParmDesc, (ub4) iRawFld+1 ); if( nStatus != OCI_SUCCESS ) break; if( poSession->GetParmInfo( hParmDesc, &oField, &nOCIType, &nOCILen ) != CE_None ) return poDefn; if( oField.GetType() == OFTBinary ) { if( nOCIType == 108 && pszGeomName == NULL ) { CPLFree( pszGeomName ); pszGeomName = CPLStrdup( oField.GetNameRef() ); iGeomColumn = iRawFld; } continue; } if( EQUAL(oField.GetNameRef(),pszExpectedFIDName) && oField.GetType() == OFTInteger ) { pszFIDName = CPLStrdup(oField.GetNameRef()); continue; } poDefn->AddFieldDefn( &oField ); } bValidTable = TRUE; return poDefn;}/************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -