ogrfmedatasource.cpp
来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 1,716 行 · 第 1/5 页
CPP
1,716 行
&& (int) eNewBestGeomType != 500 ) { eNewBestGeomType = (OGRwkbGeometryType)(((int) eBestGeomType) | wkb25DBit); } eBestGeomType = eNewBestGeomType;}/************************************************************************//* ReadFMEFeature() *//* *//* Internal working function to read an FME feature into the *//* poFMEFeature object, and increment the nPreviousFeature *//* counter. Returns FALSE on end of input, or on error. *//************************************************************************/int OGRFMEDataSource::ReadFMEFeature(){ FME_Boolean eEndOfSchema; FME_MsgNum err; poFMEFeature->resetFeature(); err = poReader->read( *poFMEFeature, eEndOfSchema ); if( err ) { CPLFMEError( poSession, "Error while reading feature." ); return FALSE; } if( eEndOfSchema == FME_TRUE ) { return FALSE; } return TRUE;}/************************************************************************//* ProcessGeometry() *//* *//* Translate an FME geometry into an OGR geometry. *//************************************************************************/OGRGeometry *OGRFMEDataSource::ProcessGeometry( OGRFMELayer * poLayer, IFMEFeature * poGeomFeat, OGRwkbGeometryType eDesiredType ){ FME_GeometryType eGeomType = poGeomFeat->getGeometryType(); int bForceToMulti = FALSE; if( wkbFlatten(eDesiredType) == wkbGeometryCollection || wkbFlatten(eDesiredType) == wkbMultiPolygon ) bForceToMulti = TRUE;/* -------------------------------------------------------------------- *//* Point *//* -------------------------------------------------------------------- */ if( eGeomType == FME_GEOM_POINT ) { return new OGRPoint(poGeomFeat->getXCoordinate(0), poGeomFeat->getYCoordinate(0), poGeomFeat->getZCoordinate(0)); }/* -------------------------------------------------------------------- *//* Line *//* -------------------------------------------------------------------- */ else if( eGeomType == FME_GEOM_LINE ) { OGRLineString *poLine = new OGRLineString(); poLine->setNumPoints( poGeomFeat->numCoords() ); for( int iPoint = 0; iPoint < (int) poGeomFeat->numCoords(); iPoint++ ) { poLine->setPoint( iPoint, poGeomFeat->getXCoordinate(iPoint), poGeomFeat->getYCoordinate(iPoint), poGeomFeat->getZCoordinate(iPoint) ); } return poLine; }/* -------------------------------------------------------------------- *//* Polygon *//* -------------------------------------------------------------------- */ else if( eGeomType == FME_GEOM_POLYGON ) { OGRLinearRing *poLine = new OGRLinearRing(); OGRPolygon *poPolygon = new OGRPolygon(); poLine->setNumPoints( poGeomFeat->numCoords() ); for( int iPoint = 0; iPoint < (int)poGeomFeat->numCoords(); iPoint++ ) { poLine->setPoint( iPoint, poGeomFeat->getXCoordinate(iPoint), poGeomFeat->getYCoordinate(iPoint), poGeomFeat->getZCoordinate(iPoint) ); } poPolygon->addRingDirectly( poLine ); if( !bForceToMulti ) return poPolygon; OGRMultiPolygon *poMP = new OGRMultiPolygon(); poMP->addGeometryDirectly( poPolygon ); return poMP; }/* -------------------------------------------------------------------- *//* Donut *//* -------------------------------------------------------------------- */ else if( eGeomType == FME_GEOM_DONUT ) { OGRPolygon *poPolygon = new OGRPolygon(); IFMEFeatureVector *poFeatVector; IFMEFeature *poFMERing = NULL; poFeatVector = poSession->createFeatureVector(); poGeomFeat->getDonutParts( *poFeatVector ); for( int iPart = 0; iPart < (int)poFeatVector->entries(); iPart++ ) { OGRLinearRing *poRing; poFMERing = (*poFeatVector)(iPart); if( poFMERing == NULL ) continue; poRing = new OGRLinearRing(); poRing->setNumPoints( poFMERing->numCoords() ); for( int iPoint=0; iPoint < (int)poFMERing->numCoords(); iPoint++ ) { poRing->setPoint( iPoint, poFMERing->getXCoordinate(iPoint), poFMERing->getYCoordinate(iPoint), poFMERing->getZCoordinate(iPoint) ); } poPolygon->addRingDirectly( poRing ); } poFeatVector->clearAndDestroy(); poSession->destroyFeatureVector( poFeatVector ); if( !bForceToMulti ) return poPolygon; OGRMultiPolygon *poMP = new OGRMultiPolygon(); poMP->addGeometryDirectly( poPolygon ); return poMP; }/* -------------------------------------------------------------------- *//* Aggregate *//* -------------------------------------------------------------------- */ else if( eGeomType == FME_GEOM_AGGREGATE ) { OGRGeometryCollection *poCollection; IFMEFeatureVector *poFeatVector; OGRwkbGeometryType eSubType = wkbUnknown; if( bForceToMulti && eDesiredType == wkbMultiPolygon ) { poCollection = new OGRMultiPolygon(); eSubType = wkbPolygon; } else poCollection = new OGRGeometryCollection(); poFeatVector = poSession->createFeatureVector(); poGeomFeat->splitAggregate( *poFeatVector ); for( int iPart = 0; iPart < (int)poFeatVector->entries(); iPart++ ) { OGRGeometry *poOGRPart; IFMEFeature *poFMEPart; poFMEPart = (*poFeatVector)(iPart); if( poFMEPart == NULL ) continue; poOGRPart = ProcessGeometry( poLayer, poFMEPart, eSubType ); if( poOGRPart == NULL ) continue; poCollection->addGeometryDirectly( poOGRPart ); } poSession->destroyFeatureVector( poFeatVector ); return poCollection; } else if( eGeomType == FME_GEOM_UNDEFINED ) { return NULL; } else { CPLDebug( kPROVIDERNAME, "unable to translate unsupported geometry type: %d\n", eGeomType ); return NULL; }} /************************************************************************//* ProcessFeature() *//* *//* Process the current fme feature into an OGR feature of the *//* passed layer types. *//************************************************************************/OGRFeature *OGRFMEDataSource::ProcessFeature( OGRFMELayer *poLayer, IFMEFeature *poSrcFeature ){ OGRFeatureDefn *poDefn = poLayer->GetLayerDefn(); OGRFeature *poFeature = new OGRFeature( poDefn ); int iAttr;/* -------------------------------------------------------------------- *//* Transfer attributes ... for numeric values assume the string *//* representation is appropriate, and automatically *//* translatable. Eventually we will need special handling for *//* array style fields. *//* -------------------------------------------------------------------- */ for( iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ ) { OGRFieldDefn *poField = poDefn->GetFieldDefn(iAttr); if( poSrcFeature->getAttribute( poField->GetNameRef(), *poFMEString ) == FME_TRUE ) { poFeature->SetField( iAttr, poFMEString->data() ); } }/* -------------------------------------------------------------------- *//* Translate the geometry. *//* -------------------------------------------------------------------- */ OGRGeometry *poOGRGeom = NULL; poOGRGeom = ProcessGeometry( poLayer, poSrcFeature, poLayer->GetLayerDefn()->GetGeomType() ); if( poOGRGeom != NULL ) poFeature->SetGeometryDirectly( poOGRGeom ); return poFeature;}/************************************************************************//* TestCapability() *//************************************************************************/int OGRFMEDataSource::TestCapability( const char * ){ return FALSE;}/************************************************************************//* OfferForConnectionCaching() *//* *//* Sometimes we want to keep a prototype reader open to *//* maintain a connection, for instance to SDE where creating *//* the connection is pretty expensive. *//************************************************************************/void OGRFMEDataSource::OfferForConnectionCaching(IFMEUniversalReader *poReader, const char *pszReaderType, const char *pszDataset){/* -------------------------------------------------------------------- *//* For now we only cache SDE readers. *//* -------------------------------------------------------------------- */ if( !EQUALN(pszReaderType,"SDE",3) && !EQUALN(pszReaderType,"ORACLE",6) ) return;/* -------------------------------------------------------------------- *//* We want to build a definition of this connection that *//* indicates a unique connection. For now we base it on the *//* Server, UserName, Password, and Instance values. We will *//* pick these all out of the RUNTIME_MACROS if present. *//* *//* First find the runtime macros. *//* -------------------------------------------------------------------- */ const char *pszRuntimeMacros = NULL; int i; for( i = 0; i < (int) poUserDirectives->entries()-1; i += 2 ) { if( EQUALN((const char *) (*poUserDirectives)(i),"RUNTIME_MACROS",14) ) pszRuntimeMacros = (*poUserDirectives)(i+1); } /* -------------------------------------------------------------------- *//* Break into name/value pairs. *//* -------------------------------------------------------------------- */ char **papszTokens = NULL; if( pszRuntimeMacros != NULL ) papszTokens = CSLTokenizeStringComplex( pszRuntimeMacros, ",", TRUE, TRUE);/* -------------------------------------------------------------------- *//* Look for Name values we want, and append them to the *//* definition string. *//* -------------------------------------------------------------------- */ char szDefinition[5000]; sprintf( szDefinition, "%s::", pszDataset ); for( i = 0; i < CSLCount(papszTokens)-1; i += 2 ) { if( strstr(papszTokens[i],"Server") != NULL || strstr(papszTokens[i],"Service") != NULL || strstr(papszTokens[i],"UserName") != NULL || strstr(papszTokens[i],"Password") != NULL || strstr(papszTokens[i],"Instance") != NULL ) { if( strlen(papszTokens[i+1]) + strlen(papszTokens[i]) + 20 < sizeof(szDefinition) - strlen(szDefinition) ) { sprintf( szDefinition + strlen(szDefinition), "%s=%s;",
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?