本文整理汇总了C++中OGRGeometry::getEnvelope方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeometry::getEnvelope方法的具体用法?C++ OGRGeometry::getEnvelope怎么用?C++ OGRGeometry::getEnvelope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeometry
的用法示例。
在下文中一共展示了OGRGeometry::getEnvelope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetExtent
OGRErr OGRLayer::GetExtent(OGREnvelope *psExtent, int bForce )
{
OGRFeature *poFeature;
OGREnvelope oEnv;
GBool bExtentSet = FALSE;
/* -------------------------------------------------------------------- */
/* If this layer has a none geometry type, then we can */
/* reasonably assume there are not extents available. */
/* -------------------------------------------------------------------- */
if( GetLayerDefn()->GetGeomType() == wkbNone )
{
psExtent->MinX = 0.0;
psExtent->MaxX = 0.0;
psExtent->MinY = 0.0;
psExtent->MaxY = 0.0;
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* If not forced, we should avoid having to scan all the */
/* features and just return a failure. */
/* -------------------------------------------------------------------- */
if( !bForce )
return OGRERR_FAILURE;
/* -------------------------------------------------------------------- */
/* OK, we hate to do this, but go ahead and read through all */
/* the features to collect geometries and build extents. */
/* -------------------------------------------------------------------- */
ResetReading();
while( (poFeature = GetNextFeature()) != NULL )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if (poGeom && !bExtentSet)
{
poGeom->getEnvelope(psExtent);
bExtentSet = TRUE;
}
else if (poGeom)
{
poGeom->getEnvelope(&oEnv);
if (oEnv.MinX < psExtent->MinX)
psExtent->MinX = oEnv.MinX;
if (oEnv.MinY < psExtent->MinY)
psExtent->MinY = oEnv.MinY;
if (oEnv.MaxX > psExtent->MaxX)
psExtent->MaxX = oEnv.MaxX;
if (oEnv.MaxY > psExtent->MaxY)
psExtent->MaxY = oEnv.MaxY;
}
delete poFeature;
}
ResetReading();
return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);
}
示例2: ICreateFeature
OGRErr OGRGeoJSONSeqWriteLayer::ICreateFeature( OGRFeature* poFeature )
{
VSILFILE* fp = m_poDS->GetOutputFile();
std::unique_ptr<OGRFeature> poFeatureToWrite;
if( m_poCT != nullptr )
{
poFeatureToWrite.reset(new OGRFeature(m_poFeatureDefn));
poFeatureToWrite->SetFrom( poFeature );
poFeatureToWrite->SetFID( poFeature->GetFID() );
OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef();
if( poGeometry )
{
const char* const apszOptions[] = { "WRAPDATELINE=YES", nullptr };
OGRGeometry* poNewGeom =
OGRGeometryFactory::transformWithOptions(
poGeometry, m_poCT, const_cast<char**>(apszOptions));
if( poNewGeom == nullptr )
{
return OGRERR_FAILURE;
}
OGREnvelope sEnvelope;
poNewGeom->getEnvelope(&sEnvelope);
if( sEnvelope.MinX < -180.0 || sEnvelope.MaxX > 180.0 ||
sEnvelope.MinY < -90.0 || sEnvelope.MaxY > 90.0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Geometry extent outside of [-180.0,180.0]x[-90.0,90.0] bounds");
return OGRERR_FAILURE;
}
poFeatureToWrite->SetGeometryDirectly( poNewGeom );
}
}
json_object* poObj =
OGRGeoJSONWriteFeature(
poFeatureToWrite.get() ? poFeatureToWrite.get() : poFeature,
m_oWriteOptions );
CPLAssert( nullptr != poObj );
if( m_bRS )
{
VSIFPrintfL( fp, "%c", RS);
}
VSIFPrintfL( fp, "%s\n", json_object_to_json_string( poObj ) );
json_object_put( poObj );
return OGRERR_NONE;
}
示例3: GetExtent
OGRErr OGRLayer::GetExtent(OGREnvelope *psExtent, int bForce )
{
OGRFeature *poFeature;
OGREnvelope oEnv;
GBool bExtentSet = FALSE;
if( !bForce )
return OGRERR_FAILURE;
ResetReading();
while( (poFeature = GetNextFeature()) != NULL )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if (poGeom && !bExtentSet)
{
poGeom->getEnvelope(psExtent);
bExtentSet = TRUE;
}
else if (poGeom)
{
poGeom->getEnvelope(&oEnv);
if (oEnv.MinX < psExtent->MinX)
psExtent->MinX = oEnv.MinX;
if (oEnv.MinY < psExtent->MinY)
psExtent->MinY = oEnv.MinY;
if (oEnv.MaxX > psExtent->MaxX)
psExtent->MaxX = oEnv.MaxX;
if (oEnv.MaxY > psExtent->MaxY)
psExtent->MaxY = oEnv.MaxY;
}
delete poFeature;
}
ResetReading();
return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);
}
示例4: GetFeatureBoundsFunc
void GetFeatureBoundsFunc(const void* hFeature, CPLRectObj* pBounds)
{
OGRFeature* pFeature = (OGRFeature*)hFeature;
if(!pFeature)
return;
OGRGeometry* pGeom = pFeature->GetGeometryRef();
if(!pGeom)
return;
OGREnvelope Env;
pGeom->getEnvelope(&Env);
pBounds->minx = Env.MinX;
pBounds->maxx = Env.MaxX;
pBounds->miny = Env.MinY;
pBounds->maxy = Env.MaxY;
}
示例5: ICreateFeature
OGRErr OGRGeoJSONWriteLayer::ICreateFeature( OGRFeature* poFeature )
{
VSILFILE* fp = poDS_->GetOutputFile();
if( NULL == poFeature )
{
CPLDebug( "GeoJSON", "Feature is null" );
return OGRERR_INVALID_HANDLE;
}
json_object* poObj = OGRGeoJSONWriteFeature( poFeature, bWriteBBOX, nCoordPrecision );
CPLAssert( NULL != poObj );
if( nOutCounter_ > 0 )
{
/* Separate "Feature" entries in "FeatureCollection" object. */
VSIFPrintfL( fp, ",\n" );
}
VSIFPrintfL( fp, "%s", json_object_to_json_string( poObj ) );
json_object_put( poObj );
++nOutCounter_;
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if ( bWriteBBOX && !poGeometry->IsEmpty() )
{
OGREnvelope3D sEnvelope;
poGeometry->getEnvelope(&sEnvelope);
if( poGeometry->getCoordinateDimension() == 3 )
bBBOX3D = TRUE;
sEnvelopeLayer.Merge(sEnvelope);
}
return OGRERR_NONE;
}
示例6: ICreateFeature
OGRErr OGRGeoJSONWriteLayer::ICreateFeature( OGRFeature* poFeature )
{
VSILFILE* fp = poDS_->GetOutputFile();
OGRFeature* poFeatureToWrite;
if( poCT_ != nullptr || bRFC7946_ )
{
poFeatureToWrite = new OGRFeature(poFeatureDefn_);
poFeatureToWrite->SetFrom( poFeature );
poFeatureToWrite->SetFID( poFeature->GetFID() );
OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef();
if( poGeometry )
{
const char* const apszOptions[] = { "WRAPDATELINE=YES", nullptr };
OGRGeometry* poNewGeom =
OGRGeometryFactory::transformWithOptions(
poGeometry, poCT_, const_cast<char**>(apszOptions),
oTransformCache_);
if( poNewGeom == nullptr )
{
delete poFeatureToWrite;
return OGRERR_FAILURE;
}
OGREnvelope sEnvelope;
poNewGeom->getEnvelope(&sEnvelope);
if( sEnvelope.MinX < -180.0 || sEnvelope.MaxX > 180.0 ||
sEnvelope.MinY < -90.0 || sEnvelope.MaxY > 90.0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Geometry extent outside of [-180.0,180.0]x[-90.0,90.0] bounds");
delete poFeatureToWrite;
return OGRERR_FAILURE;
}
poFeatureToWrite->SetGeometryDirectly( poNewGeom );
}
}
else
{
poFeatureToWrite = poFeature;
}
json_object* poObj =
OGRGeoJSONWriteFeature( poFeatureToWrite, oWriteOptions_ );
CPLAssert( nullptr != poObj );
if( nOutCounter_ > 0 )
{
/* Separate "Feature" entries in "FeatureCollection" object. */
VSIFPrintfL( fp, ",\n" );
}
VSIFPrintfL( fp, "%s", json_object_to_json_string( poObj ) );
json_object_put( poObj );
++nOutCounter_;
OGRGeometry* poGeometry = poFeatureToWrite->GetGeometryRef();
if( bWriteFC_BBOX && poGeometry != nullptr && !poGeometry->IsEmpty() )
{
OGREnvelope3D sEnvelope = OGRGeoJSONGetBBox( poGeometry,
oWriteOptions_ );
if( poGeometry->getCoordinateDimension() == 3 )
bBBOX3D = true;
if( !sEnvelopeLayer.IsInit() )
{
sEnvelopeLayer = sEnvelope;
}
else if( oWriteOptions_.bBBOXRFC7946 )
{
const bool bEnvelopeCrossAM = ( sEnvelope.MinX > sEnvelope.MaxX );
const bool bEnvelopeLayerCrossAM =
( sEnvelopeLayer.MinX > sEnvelopeLayer.MaxX );
if( bEnvelopeCrossAM )
{
if( bEnvelopeLayerCrossAM )
{
sEnvelopeLayer.MinX = std::min(sEnvelopeLayer.MinX,
sEnvelope.MinX);
sEnvelopeLayer.MaxX = std::max(sEnvelopeLayer.MaxX,
sEnvelope.MaxX);
}
else
{
if( sEnvelopeLayer.MinX > 0 )
{
sEnvelopeLayer.MinX = std::min(sEnvelopeLayer.MinX,
sEnvelope.MinX);
sEnvelopeLayer.MaxX = sEnvelope.MaxX;
}
else if( sEnvelopeLayer.MaxX < 0 )
{
sEnvelopeLayer.MaxX = std::max(sEnvelopeLayer.MaxX,
sEnvelope.MaxX);
sEnvelopeLayer.MinX = sEnvelope.MinX;
}
else
{
//.........这里部分代码省略.........
示例7: OGR2SQLITEDealWithSpatialColumn
//.........这里部分代码省略.........
wkbHasZ( poLayer->GetGeomType() ) ? "XYZ" : "XY",
nSRSId, static_cast<int>(bCreateSpatialIndex) );
}
}
#endif // HAVE_SPATIALITE
char* pszErrMsg = NULL;
int rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, &pszErrMsg );
if( pszErrMsg != NULL )
{
CPLDebug("SQLITE", "%s -> %s", osSQL.c_str(), pszErrMsg);
sqlite3_free(pszErrMsg);
}
#ifdef HAVE_SPATIALITE
/* -------------------------------------------------------------------- */
/* Should we create a spatial index ?. */
/* -------------------------------------------------------------------- */
if( !bSpatialiteDB || !bCreateSpatialIndex )
return rc == SQLITE_OK;
CPLDebug("SQLITE", "Create spatial index %s", osIdxNameRaw.c_str());
/* ENABLE_VIRTUAL_OGR_SPATIAL_INDEX is not defined */
#ifdef ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" USING "
"VirtualOGRSpatialIndex(%d, '%s', pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str(),
nExtraDS,
OGRSQLiteEscape(oLayerDesc.osLayerName).c_str());
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
if( rc != SQLITE_OK )
{
CPLDebug( "SQLITE",
"Error occurred during spatial index creation : %s",
sqlite3_errmsg(hDB));
}
#else // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
rc = sqlite3_exec( hDB, "BEGIN", NULL, NULL, NULL );
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" "
"USING rtree(pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str());
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
sqlite3_stmt *hStmt = NULL;
if( rc == SQLITE_OK )
{
const char* pszInsertInto = CPLSPrintf(
"INSERT INTO \"%s\" (pkid, xmin, xmax, ymin, ymax) "
"VALUES (?,?,?,?,?)", osIdxNameEscaped.c_str());
rc = sqlite3_prepare(hDB, pszInsertInto, -1, &hStmt, NULL);
}
OGRFeature* poFeature;
OGREnvelope sEnvelope;
OGR2SQLITE_IgnoreAllFieldsExceptGeometry(poLayer);
poLayer->ResetReading();
while( rc == SQLITE_OK &&
(poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && !poGeom->IsEmpty() )
{
poGeom->getEnvelope(&sEnvelope);
sqlite3_bind_int64(hStmt, 1,
(sqlite3_int64) poFeature->GetFID() );
sqlite3_bind_double(hStmt, 2, sEnvelope.MinX);
sqlite3_bind_double(hStmt, 3, sEnvelope.MaxX);
sqlite3_bind_double(hStmt, 4, sEnvelope.MinY);
sqlite3_bind_double(hStmt, 5, sEnvelope.MaxY);
rc = sqlite3_step(hStmt);
if( rc == SQLITE_OK || rc == SQLITE_DONE )
rc = sqlite3_reset(hStmt);
}
delete poFeature;
}
poLayer->SetIgnoredFields(NULL);
sqlite3_finalize(hStmt);
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, "COMMIT", NULL, NULL, NULL );
else
{
CPLDebug( "SQLITE",
"Error occurred during spatial index creation : %s",
sqlite3_errmsg(hDB));
rc = sqlite3_exec( hDB, "ROLLBACK", NULL, NULL, NULL );
}
#endif // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
#endif // HAVE_SPATIALITE
return rc == SQLITE_OK;
}
示例8: ICreateFeature
OGRErr OGRDXFWriterLayer::ICreateFeature( OGRFeature *poFeature )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
OGRwkbGeometryType eGType = wkbNone;
if( poGeom != nullptr )
{
if( !poGeom->IsEmpty() )
{
OGREnvelope sEnvelope;
poGeom->getEnvelope(&sEnvelope);
poDS->UpdateExtent(&sEnvelope);
}
eGType = wkbFlatten(poGeom->getGeometryType());
}
if( eGType == wkbPoint )
{
const char *pszBlockName = poFeature->GetFieldAsString("BlockName");
// We don't want to treat as a blocks ref if the block is not defined
if( pszBlockName
&& poDS->oHeaderDS.LookupBlock(pszBlockName) == nullptr )
{
if( poDS->poBlocksLayer == nullptr
|| poDS->poBlocksLayer->FindBlock(pszBlockName) == nullptr )
pszBlockName = nullptr;
}
if( pszBlockName != nullptr )
return WriteINSERT( poFeature );
else if( poFeature->GetStyleString() != nullptr
&& STARTS_WITH_CI(poFeature->GetStyleString(), "LABEL") )
return WriteTEXT( poFeature );
else
return WritePOINT( poFeature );
}
else if( eGType == wkbLineString
|| eGType == wkbMultiLineString )
return WritePOLYLINE( poFeature );
else if( eGType == wkbPolygon
|| eGType == wkbTriangle
|| eGType == wkbMultiPolygon)
{
if( bWriteHatch )
return WriteHATCH( poFeature );
else
return WritePOLYLINE( poFeature );
}
// Explode geometry collections into multiple entities.
else if( eGType == wkbGeometryCollection )
{
OGRGeometryCollection *poGC =
poFeature->StealGeometry()->toGeometryCollection();
for( auto&& poMember: poGC )
{
poFeature->SetGeometry( poMember );
OGRErr eErr = CreateFeature( poFeature );
if( eErr != OGRERR_NONE )
{
delete poGC;
return eErr;
}
}
poFeature->SetGeometryDirectly( poGC );
return OGRERR_NONE;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"No known way to write feature with geometry '%s'.",
OGRGeometryTypeToName(eGType) );
return OGRERR_FAILURE;
}
}
示例9: GetExtent
OGRErr OGRIngresTableLayer::GetExtent(OGREnvelope *psExtent, int bForce )
{
if( GetLayerDefn()->GetGeomType() == wkbNone )
{
psExtent->MinX = 0.0;
psExtent->MaxX = 0.0;
psExtent->MinY = 0.0;
psExtent->MaxY = 0.0;
return OGRERR_FAILURE;
}
OGREnvelope oEnv;
CPLString osCommand;
GBool bExtentSet = FALSE;
osCommand.Printf( "SELECT Envelope(%s) FROM %s;", pszGeomColumn, pszGeomColumnTable);
if (ingres_query(poDS->GetConn(), osCommand) == 0)
{
INGRES_RES* result = ingres_use_result(poDS->GetConn());
if ( result == NULL )
{
poDS->ReportError( "ingres_use_result() failed on extents query." );
return OGRERR_FAILURE;
}
INGRES_ROW row;
unsigned long *panLengths = NULL;
while ((row = ingres_fetch_row(result)))
{
if (panLengths == NULL)
{
panLengths = ingres_fetch_lengths( result );
if ( panLengths == NULL )
{
poDS->ReportError( "ingres_fetch_lengths() failed on extents query." );
return OGRERR_FAILURE;
}
}
OGRGeometry *poGeometry = NULL;
// Geometry columns will have the first 4 bytes contain the SRID.
OGRGeometryFactory::createFromWkb(((GByte *)row[0]) + 4,
NULL,
&poGeometry,
panLengths[0] - 4 );
if ( poGeometry != NULL )
{
if (poGeometry && !bExtentSet)
{
poGeometry->getEnvelope(psExtent);
bExtentSet = TRUE;
}
else if (poGeometry)
{
poGeometry->getEnvelope(&oEnv);
if (oEnv.MinX < psExtent->MinX)
psExtent->MinX = oEnv.MinX;
if (oEnv.MinY < psExtent->MinY)
psExtent->MinY = oEnv.MinY;
if (oEnv.MaxX > psExtent->MaxX)
psExtent->MaxX = oEnv.MaxX;
if (oEnv.MaxY > psExtent->MaxY)
psExtent->MaxY = oEnv.MaxY;
}
delete poGeometry;
}
}
ingres_free_result(result);
}
return (bExtentSet ? OGRERR_NONE : OGRERR_FAILURE);
}
示例10: PrescanForSchema
int NASReader::PrescanForSchema( int bGetExtents )
{
GMLFeature *poFeature;
if( m_pszFilename == NULL )
return FALSE;
SetClassListLocked( FALSE );
ClearClasses();
if( !SetupParser() )
return FALSE;
std::string osWork;
while( (poFeature = NextFeature()) != NULL )
{
GMLFeatureClass *poClass = poFeature->GetClass();
if( poClass->GetFeatureCount() == -1 )
poClass->SetFeatureCount( 1 );
else
poClass->SetFeatureCount( poClass->GetFeatureCount() + 1 );
#ifdef SUPPORT_GEOMETRY
if( bGetExtents )
{
OGRGeometry *poGeometry = NULL;
const CPLXMLNode* const * papsGeometry = poFeature->GetGeometryList();
if( papsGeometry[0] != NULL )
{
poGeometry = (OGRGeometry*) OGR_G_CreateFromGMLTree(papsGeometry[0]);
}
if( poGeometry != NULL )
{
double dfXMin, dfXMax, dfYMin, dfYMax;
OGREnvelope sEnvelope;
OGRwkbGeometryType eGType = (OGRwkbGeometryType)
poClass->GetGeometryType();
// Merge SRSName into layer.
const char* pszSRSName = GML_ExtractSrsNameFromGeometry(papsGeometry, osWork, FALSE);
// if (pszSRSName != NULL)
// m_bCanUseGlobalSRSName = FALSE;
poClass->MergeSRSName(pszSRSName);
// Merge geometry type into layer.
if( poClass->GetFeatureCount() == 1 && eGType == wkbUnknown )
eGType = wkbNone;
poClass->SetGeometryType(
(int) OGRMergeGeometryTypes(
eGType, poGeometry->getGeometryType() ) );
// merge extents.
poGeometry->getEnvelope( &sEnvelope );
delete poGeometry;
if( poClass->GetExtents(&dfXMin, &dfXMax, &dfYMin, &dfYMax) )
{
dfXMin = MIN(dfXMin,sEnvelope.MinX);
dfXMax = MAX(dfXMax,sEnvelope.MaxX);
dfYMin = MIN(dfYMin,sEnvelope.MinY);
dfYMax = MAX(dfYMax,sEnvelope.MaxY);
}
else
{
dfXMin = sEnvelope.MinX;
dfXMax = sEnvelope.MaxX;
dfYMin = sEnvelope.MinY;
dfYMax = sEnvelope.MaxY;
}
poClass->SetExtents( dfXMin, dfXMax, dfYMin, dfYMax );
}
else
{
if( poClass->GetGeometryType() == (int) wkbUnknown
&& poClass->GetFeatureCount() == 1 )
poClass->SetGeometryType( wkbNone );
}
#endif /* def SUPPORT_GEOMETRY */
}
delete poFeature;
}
CleanupParser();
return GetClassCount() > 0;
}
示例11: ICreateFeature
//.........这里部分代码省略.........
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
else if (nGMLIdIndex >= 0 && poFeature->IsFieldSet( nGMLIdIndex ) )
{
poDS->PrintLine( fp, "%s fid=\"%s\">",
poFeatureDefn->GetName(),
poFeature->GetFieldAsString(nGMLIdIndex) );
}
else
{
poDS->PrintLine( fp, "%s fid=\"%s." CPL_FRMT_GIB "\">",
poFeatureDefn->GetName(),
poFeatureDefn->GetName(),
poFeature->GetFID() );
}
}
for( int iGeomField = 0; iGeomField < poFeatureDefn->GetGeomFieldCount(); iGeomField++ )
{
OGRGeomFieldDefn *poFieldDefn = poFeatureDefn->GetGeomFieldDefn(iGeomField);
// Write out Geometry - for now it isn't indented properly.
/* GML geometries don't like very much the concept of empty geometry */
OGRGeometry* poGeom = poFeature->GetGeomFieldRef(iGeomField);
if( poGeom != NULL && !poGeom->IsEmpty())
{
char *pszGeometry;
OGREnvelope3D sGeomBounds;
int nCoordDimension = poGeom->getCoordinateDimension();
poGeom->getEnvelope( &sGeomBounds );
if( bSameSRS )
poDS->GrowExtents( &sGeomBounds, nCoordDimension );
if (poGeom->getSpatialReference() == NULL && poFieldDefn->GetSpatialRef() != NULL)
poGeom->assignSpatialReference(poFieldDefn->GetSpatialRef());
if (bIsGML3Output && poDS->WriteFeatureBoundedBy())
{
bool bCoordSwap;
char* pszSRSName = GML_GetSRSName(poGeom->getSpatialReference(), poDS->IsLongSRSRequired(), &bCoordSwap);
char szLowerCorner[75], szUpperCorner[75];
if (bCoordSwap)
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinY, sGeomBounds.MinX, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxY, sGeomBounds.MaxX, sGeomBounds.MaxZ, nCoordDimension);
}
else
{
OGRMakeWktCoordinate(szLowerCorner, sGeomBounds.MinX, sGeomBounds.MinY, sGeomBounds.MinZ, nCoordDimension);
OGRMakeWktCoordinate(szUpperCorner, sGeomBounds.MaxX, sGeomBounds.MaxY, sGeomBounds.MaxZ, nCoordDimension);
}
if (bWriteSpaceIndentation)
VSIFPrintfL(fp, " ");
poDS->PrintLine( fp, "<gml:boundedBy><gml:Envelope%s%s><gml:lowerCorner>%s</gml:lowerCorner><gml:upperCorner>%s</gml:upperCorner></gml:Envelope></gml:boundedBy>",
(nCoordDimension == 3) ? " srsDimension=\"3\"" : "",pszSRSName, szLowerCorner, szUpperCorner);
CPLFree(pszSRSName);
}
char** papszOptions = (bIsGML3Output) ? CSLAddString(NULL, "FORMAT=GML3") : NULL;
if (bIsGML3Output && !poDS->IsLongSRSRequired())
papszOptions = CSLAddString(papszOptions, "GML3_LONGSRS=NO");
示例12: ICreateFeature
OGRErr OGRDXFWriterLayer::ICreateFeature( OGRFeature *poFeature )
{
OGRGeometry *poGeom = poFeature->GetGeometryRef();
OGRwkbGeometryType eGType = wkbNone;
if( poGeom != NULL )
{
if( !poGeom->IsEmpty() )
{
OGREnvelope sEnvelope;
poGeom->getEnvelope(&sEnvelope);
poDS->UpdateExtent(&sEnvelope);
}
eGType = wkbFlatten(poGeom->getGeometryType());
}
if( eGType == wkbPoint )
{
const char *pszBlockName = poFeature->GetFieldAsString("BlockName");
// we don't want to treat as a block ref if we are writing blocks layer
if( pszBlockName != NULL
&& poDS->poBlocksLayer != NULL
&& poFeature->GetDefnRef() == poDS->poBlocksLayer->GetLayerDefn())
pszBlockName = NULL;
// We don't want to treat as a blocks ref if the block is not defined
if( pszBlockName
&& poDS->oHeaderDS.LookupBlock(pszBlockName) == NULL )
{
if( poDS->poBlocksLayer == NULL
|| poDS->poBlocksLayer->FindBlock(pszBlockName) == NULL )
pszBlockName = NULL;
}
if( pszBlockName != NULL )
return WriteINSERT( poFeature );
else if( poFeature->GetStyleString() != NULL
&& EQUALN(poFeature->GetStyleString(),"LABEL",5) )
return WriteTEXT( poFeature );
else
return WritePOINT( poFeature );
}
else if( eGType == wkbLineString
|| eGType == wkbMultiLineString )
return WritePOLYLINE( poFeature );
else if( eGType == wkbPolygon
|| eGType == wkbMultiPolygon )
{
if( bWriteHatch )
return WriteHATCH( poFeature );
else
return WritePOLYLINE( poFeature );
}
// Explode geometry collections into multiple entities.
else if( eGType == wkbGeometryCollection )
{
OGRGeometryCollection *poGC = (OGRGeometryCollection *)
poFeature->StealGeometry();
int iGeom;
for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
poFeature->SetGeometry( poGC->getGeometryRef(iGeom) );
OGRErr eErr = CreateFeature( poFeature );
if( eErr != OGRERR_NONE )
return eErr;
}
poFeature->SetGeometryDirectly( poGC );
return OGRERR_NONE;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"No known way to write feature with geometry '%s'.",
OGRGeometryTypeToName(eGType) );
return OGRERR_FAILURE;
}
}
示例13: oMutexHolder
//.........这里部分代码省略.........
"Error occured during spatial index creation : %s",
sqlite3_errmsg(hDB));
}
#else // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
rc = sqlite3_exec( hDB, "BEGIN", NULL, NULL, NULL );
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" "
"USING rtree(pkid, xmin, xmax, ymin, ymax)",
osIdxNameEscaped.c_str());
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, osSQL.c_str(), NULL, NULL, NULL );
sqlite3_stmt *hStmt = NULL;
if( rc == SQLITE_OK )
{
const char* pszInsertInto = CPLSPrintf(
"INSERT INTO \"%s\" (pkid, xmin, xmax, ymin, ymax) "
"VALUES (?,?,?,?,?)", osIdxNameEscaped.c_str());
rc = sqlite3_prepare(hDB, pszInsertInto, -1, &hStmt, NULL);
}
OGRFeature* poFeature;
OGREnvelope sEnvelope;
OGR2SQLITE_IgnoreAllFieldsExceptGeometry(poLayer);
poLayer->ResetReading();
while( rc == SQLITE_OK &&
(poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && !poGeom->IsEmpty() )
{
poGeom->getEnvelope(&sEnvelope);
sqlite3_bind_int64(hStmt, 1,
(sqlite3_int64) poFeature->GetFID() );
sqlite3_bind_double(hStmt, 2, sEnvelope.MinX);
sqlite3_bind_double(hStmt, 3, sEnvelope.MaxX);
sqlite3_bind_double(hStmt, 4, sEnvelope.MinY);
sqlite3_bind_double(hStmt, 5, sEnvelope.MaxY);
rc = sqlite3_step(hStmt);
if( rc == SQLITE_OK || rc == SQLITE_DONE )
rc = sqlite3_reset(hStmt);
}
delete poFeature;
}
poLayer->SetIgnoredFields(NULL);
sqlite3_finalize(hStmt);
if( rc == SQLITE_OK )
rc = sqlite3_exec( hDB, "COMMIT", NULL, NULL, NULL );
else
{
CPLDebug("SQLITE",
"Error occured during spatial index creation : %s",
sqlite3_errmsg(hDB));
rc = sqlite3_exec( hDB, "ROLLBACK", NULL, NULL, NULL );
}
#endif // ENABLE_VIRTUAL_OGR_SPATIAL_INDEX
#endif // HAVE_SPATIALITE
}
示例14: BuildURL
CPLString OGRPLScenesLayer::BuildURL(int nFeatures)
{
CPLString osURL = osBaseURL + CPLSPrintf("?count=%d", nFeatures);
if( bAcquiredAscending == 1 )
osURL += "&order_by=acquired%20asc";
else if( bAcquiredAscending == 0 )
osURL += "&order_by=acquired%20desc";
if( m_poFilterGeom != NULL || poMainFilter != NULL )
{
OGRGeometry* poIntersection = NULL;
OGRGeometry* poFilterGeom = m_poFilterGeom;
if( poFilterGeom )
{
OGREnvelope sEnvelope;
poFilterGeom->getEnvelope(&sEnvelope);
if( sEnvelope.MinX <= -180 && sEnvelope.MinY <= -90 &&
sEnvelope.MaxX >= 180 && sEnvelope.MaxY >= 90 )
poFilterGeom = NULL;
}
if( poFilterGeom && poMainFilter )
poIntersection = poFilterGeom->Intersection(poMainFilter);
else if( poFilterGeom )
poIntersection = poFilterGeom;
else if( poMainFilter )
poIntersection = poMainFilter;
if( poIntersection )
{
char* pszWKT = NULL;
OGREnvelope sEnvelope;
poIntersection->getEnvelope(&sEnvelope);
if( sEnvelope.MinX == sEnvelope.MaxX && sEnvelope.MinY == sEnvelope.MaxY )
{
pszWKT = CPLStrdup(CPLSPrintf("POINT(%.18g %.18g)",
sEnvelope.MinX, sEnvelope.MinY));
}
else
poIntersection->exportToWkt(&pszWKT);
osURL += "&intersects=";
char* pszWKTEscaped = CPLEscapeString(pszWKT, -1, CPLES_URL);
osURL += pszWKTEscaped;
CPLFree(pszWKTEscaped);
CPLFree(pszWKT);
}
if( poIntersection != m_poFilterGeom && poIntersection != poMainFilter )
delete poIntersection;
}
if( osFilterURLPart.size() )
{
if( osFilterURLPart[0] == '&' )
osURL += osFilterURLPart;
else
osURL = osBaseURL + osFilterURLPart;
}
return osURL;
}
示例15: PrescanForSchema
int NASReader::PrescanForSchema( int bGetExtents )
{
GMLFeature *poFeature;
if( m_pszFilename == NULL )
return FALSE;
SetClassListLocked( FALSE );
ClearClasses();
if( !SetupParser() )
return FALSE;
while( (poFeature = NextFeature()) != NULL )
{
GMLFeatureClass *poClass = poFeature->GetClass();
if( poClass->GetFeatureCount() == -1 )
poClass->SetFeatureCount( 1 );
else
poClass->SetFeatureCount( poClass->GetFeatureCount() + 1 );
#ifdef SUPPORT_GEOMETRY
if( bGetExtents )
{
OGRGeometry *poGeometry = NULL;
if( poFeature->GetGeometry() != NULL
&& strlen(poFeature->GetGeometry()) != 0 )
{
poGeometry = (OGRGeometry *) OGR_G_CreateFromGML(
poFeature->GetGeometry() );
}
if( poGeometry != NULL )
{
double dfXMin, dfXMax, dfYMin, dfYMax;
OGREnvelope sEnvelope;
OGRwkbGeometryType eGType = (OGRwkbGeometryType)
poClass->GetGeometryType();
// Merge geometry type into layer.
if( poClass->GetFeatureCount() == 1 && eGType == wkbUnknown )
eGType = wkbNone;
poClass->SetGeometryType(
(int) OGRMergeGeometryTypes(
eGType, poGeometry->getGeometryType() ) );
// merge extents.
poGeometry->getEnvelope( &sEnvelope );
delete poGeometry;
if( poClass->GetExtents(&dfXMin, &dfXMax, &dfYMin, &dfYMax) )
{
dfXMin = MIN(dfXMin,sEnvelope.MinX);
dfXMax = MAX(dfXMax,sEnvelope.MaxX);
dfYMin = MIN(dfYMin,sEnvelope.MinY);
dfYMax = MAX(dfYMax,sEnvelope.MaxY);
}
else
{
dfXMin = sEnvelope.MinX;
dfXMax = sEnvelope.MaxX;
dfYMin = sEnvelope.MinY;
dfYMax = sEnvelope.MaxY;
}
poClass->SetExtents( dfXMin, dfXMax, dfYMin, dfYMax );
}
else
{
if( poClass->GetGeometryType() == (int) wkbUnknown
&& poClass->GetFeatureCount() == 1 )
poClass->SetGeometryType( wkbNone );
}
#endif /* def SUPPORT_GEOMETRY */
}
delete poFeature;
}
CleanupParser();
return GetClassCount() > 0;
}