本文整理汇总了C++中OGRLayer::GetExtent方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetExtent方法的具体用法?C++ OGRLayer::GetExtent怎么用?C++ OGRLayer::GetExtent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::GetExtent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetExtent
OGRErr OGRSQLiteSelectLayerCommonBehaviour::GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce)
{
if( iGeomField < 0 || iGeomField >= poLayer->GetLayerDefn()->GetGeomFieldCount() ||
poLayer->GetLayerDefn()->GetGeomFieldDefn(iGeomField)->GetType() == wkbNone )
{
if( iGeomField != 0 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid geometry field index : %d", iGeomField);
}
return OGRERR_FAILURE;
}
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
if( iGeomField == 0 )
{
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
osSQLCommand.ifind("SELECT ", 1) == std::string::npos && /* Ensure there's no sub SELECT that could confuse our heuristics */
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(iGeomField, psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr;
if( iGeomField == 0 )
eErr = poLayer->BaseGetExtent(psExtent, bForce);
else
eErr = poLayer->BaseGetExtent(iGeomField, psExtent, bForce);
if (iGeomField == 0 && eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例2: VectortoRaster
int Raster::VectortoRaster(const char * sVectorSourcePath,
const char * sRasterOutputPath,
double dCellWidth,
const char * psFieldName){
OGRRegisterAll();
OGRDataSource * pDSVectorInput;
pDSVectorInput = OGRSFDriverRegistrar::Open( sVectorSourcePath, FALSE );
if (pDSVectorInput == NULL)
return INPUT_FILE_ERROR;
// Get the extents of the file before passing it off to the function that actually burns
// the geometries
// -------------------------------------------------------
// Note: we're just grabbing the first layer here. If we get into needing multiple layers
// Then we'll need to re-think this.
OGRLayer * poLayer = pDSVectorInput->GetLayer(0);
if (poLayer == NULL)
return VECTOR_LAYER_NOT_FOUND;
OGREnvelope psExtent;
poLayer->GetExtent(&psExtent, TRUE);
double dMaxY, dMaxX, dMinY, dMinX;
double cellWidth = fabs(dCellWidth);
dMaxY = ceil(psExtent.MaxY / cellWidth) * cellWidth;
dMaxX = ceil(psExtent.MaxX / cellWidth) * cellWidth;
dMinY = floor(psExtent.MinY / cellWidth) * cellWidth;
dMinX = floor(psExtent.MinX / cellWidth) * cellWidth;
int nRows = (int)((dMaxY - dMinY) / cellWidth);
int nCols = (int)((dMaxX - dMinX) / cellWidth);
\
// We're going to create them without projections. The projections get set later.
double fNoDataValue = (double) -std::numeric_limits<float>::max();
GDALDataType nDType = GDT_Float32;
double dCellHeight = -dCellWidth;
RasterMeta TemplateRaster(psExtent.MaxY, psExtent.MinX, nRows, nCols, &dCellHeight, &dCellWidth, &fNoDataValue, "GTiff", &nDType, "");
pDSVectorInput->Release();
return VectortoRaster(sVectorSourcePath, sRasterOutputPath, psFieldName, &TemplateRaster);
}
示例3: GetExtent
OGRErr OGRSQLiteSelectLayer::GetExtent(OGREnvelope *psExtent, int bForce)
{
if (GetGeomType() == wkbNone)
return OGRERR_FAILURE;
/* Caching of extent by SQL string is interesting to speed-up the */
/* establishment of the WFS GetCapabilities document for a MapServer mapfile */
/* which has several layers, only differing by scale rules */
const OGREnvelope* psCachedExtent = poDS->GetEnvelopeFromSQL(osSQLBase);
if (psCachedExtent)
{
memcpy(psExtent, psCachedExtent, sizeof(*psCachedExtent));
return OGRERR_NONE;
}
CPLString osSQLCommand = osSQLBase;
/* ORDER BY are costly to evaluate and are not necessary to establish */
/* the layer extent. */
size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
if( osSQLCommand.ifind("SELECT ") == 0 &&
nOrderByPos != std::string::npos &&
osSQLCommand.ifind(" LIMIT ") == std::string::npos &&
osSQLCommand.ifind(" UNION ") == std::string::npos &&
osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
osSQLCommand.ifind(" EXCEPT ") == std::string::npos)
{
osSQLCommand.resize(nOrderByPos);
OGRLayer* poTmpLayer = poDS->ExecuteSQL(osSQLCommand.c_str(), NULL, NULL);
if (poTmpLayer)
{
OGRErr eErr = poTmpLayer->GetExtent(psExtent, bForce);
poDS->ReleaseResultSet(poTmpLayer);
return eErr;
}
}
OGRErr eErr = OGRSQLiteLayer::GetExtent(psExtent, bForce);
if (eErr == OGRERR_NONE && poDS->GetUpdate() == FALSE)
poDS->SetEnvelopeForSQL(osSQLBase, *psExtent);
return eErr;
}
示例4: open
bool rspfOgrVectorTileSource::open()
{
const char* MODULE = "rspfOgrVectorTileSource::open";
if (isOgrVectorDataSource() == false)
{
close();
return false;
}
if(isOpen())
{
close();
}
theDataSource = OGRSFDriverRegistrar::Open(theImageFile,
false);
if (theDataSource)
{
int layerCount = theDataSource->GetLayerCount();
theLayerVector.resize(layerCount);
if(layerCount)
{
for(int i = 0; i < layerCount; ++i)
{
OGRLayer* layer = theDataSource->GetLayer(i);
if(layer)
{
OGRSpatialReference* spatialReference = layer->GetSpatialRef();
if(!spatialReference)
{
if(traceDebug())
{
rspfNotify(rspfNotifyLevel_NOTICE)
<< MODULE
<< " No spatial reference given, assuming geographic"
<< endl;
}
}
}
else
{
if(traceDebug())
{
rspfNotify(rspfNotifyLevel_NOTICE)
<< MODULE
<< " layer " << i << " is null." << endl;
}
}
if (layer)
{
layer->GetExtent(&theBoundingExtent, true);
rspfRefPtr<rspfProjection> proj = createProjFromReference(layer->GetSpatialRef());
rspfRefPtr<rspfImageGeometry> imageGeometry = 0;
bool isDefaultProjection = false;
if(proj.valid())
{
imageGeometry = new rspfImageGeometry(0, proj.get());
}
rspfMapProjection* mapProj = 0;
if(imageGeometry.valid())
{
mapProj = PTR_CAST(rspfMapProjection, imageGeometry->getProjection());
}
else
{
mapProj = createDefaultProj();
imageGeometry = new rspfImageGeometry(0, mapProj);
isDefaultProjection = true;
}
if(mapProj)
{
rspfDrect rect(theBoundingExtent.MinX,
theBoundingExtent.MaxY,
theBoundingExtent.MaxX,
theBoundingExtent.MinY,
RSPF_RIGHT_HANDED);
std::vector<rspfGpt> points;
if (isDefaultProjection || mapProj->isGeographic())
{
rspfGpt g1(rect.ul().y, rect.ul().x);
rspfGpt g2(rect.ur().y, rect.ur().x);
rspfGpt g3(rect.lr().y, rect.lr().x);
rspfGpt g4(rect.ll().y, rect.ll().x);
points.push_back(g1);
points.push_back(g2);
points.push_back(g3);
points.push_back(g4);
}
else
{
rspfGpt g1 = mapProj->inverse(rect.ul());
rspfGpt g2 = mapProj->inverse(rect.ur());
rspfGpt g3 = mapProj->inverse(rect.lr());
rspfGpt g4 = mapProj->inverse(rect.ll());
points.push_back(g1);
points.push_back(g2);
points.push_back(g3);
points.push_back(g4);
}
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
/* XXX - Should those pointers be checked against NULL? */
assert(NULL != poField);
assert(NULL != poFieldCur);
if( poField->GetType() != poFieldCur->GetType()
|| poField->GetWidth() != poFieldCur->GetWidth()
|| poField->GetPrecision() != poFieldCur->GetPrecision()
|| !EQUAL( poField->GetNameRef(), poFieldCur->GetNameRef() ) )
{
fprintf( stderr, "Schema of attributes of layer %s of %s does not match ... skipping it.\n",
poLayer->GetLayerDefn()->GetName(), papszArgv[nFirstSourceDataset]);
if (bFirstWarningForNonMatchingAttributes)
{
fprintf( stderr, "Note : you can override this behaviour with -accept_different_schemas option\n"
"but this may result in a tileindex incompatible with MapServer\n");
bFirstWarningForNonMatchingAttributes = FALSE;
}
bSkip = TRUE;
break;
}
}
if (bSkip)
continue;
}
/* -------------------------------------------------------------------- */
/* Get layer extents, and create a corresponding polygon */
/* geometry. */
/* -------------------------------------------------------------------- */
OGREnvelope sExtents;
OGRPolygon oRegion;
OGRLinearRing oRing;
if( poLayer->GetExtent( &sExtents, TRUE ) != OGRERR_NONE )
{
fprintf( stderr, "GetExtent() failed on layer %s of %s, skipping.\n",
poLayer->GetLayerDefn()->GetName(),
papszArgv[nFirstSourceDataset] );
continue;
}
oRing.addPoint( sExtents.MinX, sExtents.MinY );
oRing.addPoint( sExtents.MinX, sExtents.MaxY );
oRing.addPoint( sExtents.MaxX, sExtents.MaxY );
oRing.addPoint( sExtents.MaxX, sExtents.MinY );
oRing.addPoint( sExtents.MinX, sExtents.MinY );
oRegion.addRing( &oRing );
/* -------------------------------------------------------------------- */
/* Add layer to tileindex. */
/* -------------------------------------------------------------------- */
char szLocation[5000];
OGRFeature oTileFeat( poDstLayer->GetLayerDefn() );
sprintf( szLocation, "%s,%d",
fileNameToWrite, iLayer );
oTileFeat.SetGeometry( &oRegion );
oTileFeat.SetField( iTileIndexField, szLocation );
if( poDstLayer->CreateFeature( &oTileFeat ) != OGRERR_NONE )
{
fprintf( stderr, "Failed to create feature on tile index ... terminating." );
OGRDataSource::DestroyDataSource( poDstDS );
exit( 1 );
}
}
/* -------------------------------------------------------------------- */
/* Cleanup this data source. */
/* -------------------------------------------------------------------- */
CPLFree(fileNameToWrite);
OGRDataSource::DestroyDataSource( poDS );
}
/* -------------------------------------------------------------------- */
/* Close tile index and clear buffers. */
/* -------------------------------------------------------------------- */
OGRDataSource::DestroyDataSource( poDstDS );
OGRFeatureDefn::DestroyFeatureDefn( poFeatureDefn );
if (alreadyExistingSpatialRef != NULL)
OGRSpatialReference::DestroySpatialReference( alreadyExistingSpatialRef );
CPLFree(current_path);
if (nExistingLayers)
{
int i;
for(i=0;i<nExistingLayers;i++)
{
CPLFree(existingLayersTab[i]);
}
CPLFree(existingLayersTab);
}
return 0;
}
示例6: VectorMetaDataInfo
void ShpReader::VectorMetaDataInfo(OGRDataSource* OGRDataset, StudyControllerPtr studyController, VectorMapControllerPtr vectorMapController)
{
vFileMetaData* vHeader = vectorMapController->GetVectorMapModel()->GetVectorMetaData();
OGRLayer *poLayer = OGRDataset->GetLayer( 0 );
char *originalWkt = NULL;
char *destinationWkt = NULL;
OGREnvelope psEnvelope;
poLayer->GetExtent( &psEnvelope );
vHeader->originalExtents.x = psEnvelope.MinX;
vHeader->originalExtents.dx = psEnvelope.MaxX;
vHeader->originalExtents.y = psEnvelope.MinY;
vHeader->originalExtents.dy = psEnvelope.MaxY;
Log::Inst().Write("Original Extents: ");
Log::Inst().Write(_T("Lower, Left (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.x, 2).c_str()) + _T(", ")
+ wxString(StringTools::ToStringW(vHeader->originalExtents.y, 2).c_str()));
Log::Inst().Write(_T("Upper, Right (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.dx, 2).c_str()) + _T(", ")
+ wxString(StringTools::ToStringW(vHeader->originalExtents.dy, 2).c_str()));
vHeader->numFeatures= poLayer->GetFeatureCount();
Log::Inst().Write("Number of Features: " + StringTools::ToString(vHeader->numFeatures));
std::string type;
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPoint || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPoint )
type="Point";
else if ( wkbFlatten(poFDefn->GetGeomType() ) == wkbLineString || wkbFlatten(poFDefn->GetGeomType() ) == wkbMultiLineString )
type="Polyline";
else if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPolygon || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPolygon )
type="Polygon";
else
type="Unknown";
vHeader->geometryType=type;
Log::Inst().Write("Geometry Type: "+ type);
OGRSpatialReference* originalShpSR = poLayer->GetSpatialRef();
if (originalShpSR != NULL)
{
originalShpSR->exportToWkt(&originalWkt);
vHeader->originalProjection = std::string(originalWkt);
}
Log::Inst().Write("Original Projection: " + vHeader->originalProjection);
Log::Inst().Write("");
ProjectionToolPtr projTool = studyController->GetProjectionTool();
if (projTool != NULL)
{
OGRSpatialReference *destinationCS= projTool->GetTargetCS ();
destinationCS->exportToWkt(&destinationWkt);
vHeader->destinationProjection = std::string(destinationWkt);
}
vHeader->currentExtents.x = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinX();
vHeader->currentExtents.y = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinY();
vHeader->currentExtents.dx = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxX();
vHeader->currentExtents.dy = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxY();
//Log::Inst().Write("Upper, Right (x,y): " +
// StringTools::ToString(vHeader->currentExtents.dx) + ", " +
//StringTools::ToString(vHeader->currentExtents.dy));
}
示例7: Open
bool ShpReader::Open(std::wstring fullPath, StudyControllerPtr studyController,
VectorMapControllerPtr vectorMapController, ProgressDlgPtr progressDlg)
{
// Registers all format drivers built into GDAL/OGR.
OGRRegisterAll();
OGRDataSource *OGRDataset;
// Open vector file path
std::string tempStr( fullPath.begin(), fullPath.end() );
OGRDataset = OGRSFDriverRegistrar::Open( tempStr.c_str(), FALSE );
// Return if no vector files are found
if( OGRDataset == NULL )
{
Log::Inst().Warning("(Warning) Failed to open file at " + tempStr + ".");
return false;
}
if ( App::Inst().GetLayerTreeController()->GetNumMapLayers() >0 )
MapControllerPtr mapController= App::Inst().GetLayerTreeController()->GetLayerTreeModel()->GetStudy(0)->GetMapLayer(0)->GetMapController();
// It appears that shapefiles (*.SHP) only support up to one layer per file
// This will need to be further investigated for other vector filetypes (e.g., KML)
// For now just grab layer at position 0
OGRLayer *poLayer = OGRDataset->GetLayer( 0 );
// Determine the XY boundaries for the entire vector dataset
OGREnvelope psEnvelope;
VectorMapModelPtr vectorMapModel = vectorMapController->GetVectorMapModel();
poLayer->GetExtent( &psEnvelope );
vectorMapModel->SetVectorBoundary(psEnvelope);
if(!SetupVectorProjection(OGRDataset,studyController,poLayer,vectorMapController ))
{
OGRDataset->DestroyDataSource(OGRDataset);
return false;
}
if(progressDlg)
{
if(!progressDlg->Update(0, _T("Reading Vector Map Information...")))
{
OGRDataset->DestroyDataSource(OGRDataset);
return false;
}
}
GLdouble minX, minY, maxX, maxY;
minX = minY = std::numeric_limits<float>::max();
maxX = maxY = -std::numeric_limits<float>::max();
// Retrieve features from the dataset
OGRFeature *poFeature;
poLayer->ResetReading();
int numFeatures = poLayer->GetFeatureCount();
int count=0;
//Log::Inst().Write("Loading shapefile with the following meta data:");
while ( ( poFeature = poLayer->GetNextFeature() ) != NULL )
{
/////////////////////////////////////////////////
// PHASE 1: Retrieve METADATA from the dataset //
/////////////////////////////////////////////////
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int iField;
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
//if( poFieldDefn->GetType() == OFTInteger )
// printf( "%d,", poFeature->GetFieldAsInteger( iField ) );
//else if( poFieldDefn->GetType() == OFTReal )
// printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
//else if( poFieldDefn->GetType() == OFTString )
// printf( "%s,", poFeature->GetFieldAsString(iField) );
//else
// printf( "%s,", poFeature->GetFieldAsString(iField) );
//ofs << poFeature->GetFieldAsString(iField) << ",";
std::string metaData = poFeature->GetFieldAsString(iField);
// do something with the meta data...
//Log::Inst().Write(metaData);
}
count++;
if(progressDlg)
{
if(!progressDlg->Update(int(50 + (float(count)/numFeatures)*50)))
return false;
}
///////////////////////////////////////////////////
// PHASE 2: Retrieve GEOMETRIES from the dataset //
///////////////////////////////////////////////////
OGRGeometry *poGeometry;
poGeometry = poFeature->GetGeometryRef();
//.........这里部分代码省略.........
示例8: bind
//.........这里部分代码省略.........
s << "None (no layers were found in dataset)";
}
throw datasource_exception(s.str());
}
if (! layer_.is_valid())
{
std::string s("OGR Plugin: ");
if (layer_by_name)
{
s += "cannot find layer by name '" + *layer_by_name;
}
else if (layer_by_index)
{
s += "cannot find layer by index number '" + *layer_by_index;
}
else if (layer_by_sql)
{
s += "cannot find layer by sql query '" + *layer_by_sql;
}
s += "' in dataset '" + dataset_name_ + "'";
throw datasource_exception(s);
}
// work with real OGR layer
OGRLayer* layer = layer_.layer();
// initialize envelope
OGREnvelope envelope;
layer->GetExtent(&envelope);
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
// scan for index file
// TODO - layer names don't match dataset name, so this will break for
// any layer types of ogr than shapefiles, etc
// fix here and in ogrindex
size_t breakpoint = dataset_name_.find_last_of(".");
if (breakpoint == std::string::npos)
{
breakpoint = dataset_name_.length();
}
index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex";
std::ifstream index_file(index_name_.c_str(), std::ios::in | std::ios::binary);
if (index_file)
{
indexed_ = true;
index_file.close();
}
#if 0
// TODO - enable this warning once the ogrindex tool is a bit more stable/mature
else
{
std::clog << "### Notice: no ogrindex file found for " << dataset_name_
<< ", use the 'ogrindex' program to build an index for faster rendering"
<< std::endl;
}
#endif
// deal with attributes descriptions
OGRFeatureDefn* def = layer->GetLayerDefn();
if (def != 0)
示例9: init
//.........这里部分代码省略.........
std::ostringstream s;
s << "OGR Plugin: ";
if (layer_by_name)
{
s << "cannot find layer by name '" << *layer_by_name;
}
else if (layer_by_index)
{
s << "cannot find layer by index number '" << *layer_by_index;
}
else if (layer_by_sql)
{
s << "cannot find layer by sql query '" << *layer_by_sql;
}
s << "' in dataset '" << dataset_name_ << "'";
throw datasource_exception(s.str());
}
// work with real OGR layer
OGRLayer* layer = layer_.layer();
// initialize envelope
boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext && !ext->empty())
{
extent_.from_string(*ext);
}
else
{
OGREnvelope envelope;
OGRErr e = layer->GetExtent(&envelope);
if (e == OGRERR_FAILURE)
{
if (layer->GetFeatureCount() == 0)
{
MAPNIK_LOG_ERROR(ogr) << "could not determine extent, layer '" << layer->GetLayerDefn()->GetName() << "' appears to have no features";
}
else
{
std::ostringstream s;
s << "OGR Plugin: Cannot determine extent for layer '" << layer->GetLayerDefn()->GetName() << "'. Please provide a manual extent string (minx,miny,maxx,maxy).";
throw datasource_exception(s.str());
}
}
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
}
// scan for index file
// TODO - layer names don't match dataset name, so this will break for
// any layer types of ogr than shapefiles, etc
// fix here and in ogrindex
size_t breakpoint = dataset_name_.find_last_of(".");
if (breakpoint == std::string::npos)
{
breakpoint = dataset_name_.length();
}
index_name_ = dataset_name_.substr(0, breakpoint) + ".ogrindex";
#if defined (_WINDOWS)
std::ifstream index_file(mapnik::utf8_to_utf16(index_name_), std::ios::in | std::ios::binary);
#else
std::ifstream index_file(index_name_.c_str(), std::ios::in | std::ios::binary);
#endif
示例10: GetExtent
virtual OGRErr GetExtent( OGREnvelope *psExtent, int bForce )
{ return poBaseLayer->GetExtent(psExtent, bForce); }
示例11: ogrInfo
//.........这里部分代码省略.........
// delete poFeature;
}
uninstallErrorHandlerAndTriggerError();
if (i == INT_MAX) {
error("ogrInfo: undeclared feature count overflow");
} else {
nFIDs = i;
warning("ogrInfo: feature count not given; %d counted", nFIDs);
}
installErrorHandler();
poLayer->ResetReading();
uninstallErrorHandlerAndTriggerError();
INTEGER(vec1)[0]=nFIDs;
}
SET_VECTOR_ELT(ans,0,vec1);
// store other stuff....
installErrorHandler();
poDefn = poLayer->GetLayerDefn();
nFields = poDefn->GetFieldCount();
uninstallErrorHandlerAndTriggerError();
// store number of fields
PROTECT(vec2=allocVector(INTSXP,1));
pc++;
INTEGER(vec2)[0]=nFields;
SET_VECTOR_ELT(ans,1,vec2);
installErrorHandler();
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE) {
PROTECT(dvec=allocVector(REALSXP,4));
pc++;
REAL(dvec)[0] = oExt.MinX;
REAL(dvec)[1] = oExt.MinY;
REAL(dvec)[2] = oExt.MaxX;
REAL(dvec)[3] = oExt.MaxY;
SET_VECTOR_ELT(ans,4,dvec);
}
uninstallErrorHandlerAndTriggerError();
PROTECT(itemnames=allocVector(STRSXP,nFields));
pc++;
PROTECT(itemtype=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemwidth=allocVector(INTSXP,nFields));
pc++;
// try List types
PROTECT(itemlistmaxcount=allocVector(INTSXP,nFields));
pc++;
PROTECT(itemTypeNames=allocVector(STRSXP,nFields));
pc++;
int listFieldCount=0;
installErrorHandler();
for(iField=0; iField<nFields; iField++) {
OGRFieldDefn *poField = poDefn->GetFieldDefn(iField);
SET_STRING_ELT(itemnames,iField,mkChar(poField->GetNameRef()));
INTEGER(itemtype)[iField]=poField->GetType();
if (INTEGER(itemtype)[iField] == OFTIntegerList ||
INTEGER(itemtype)[iField] == OFTRealList ||
INTEGER(itemtype)[iField] == OFTStringList) listFieldCount++;
INTEGER(itemwidth)[iField]=poField->GetWidth();
示例12: featuredetect
void DrawShape::featuredetect(int XPoint,int YPoint)
{
if(!sfile.empty() && XPoint>=(x_pos_shift-increase_width/2)*6.40 && XPoint<=(x_pos_shift-increase_width/2)*6.40+(100+increase_width)*6.4 && YPoint>=(y_pos_shift-increase_height/2)*4.8 && YPoint<=(y_pos_shift-increase_height/2)*4.8+(100+increase_height)*4.8 )//check if point is inside the view area
{
OGRDataSource *poDS;
string dfile = sfile + ".shp";
string shp = "g_4326/" + sfile + ".shp";
poDS = OGRSFDriverRegistrar::Open(shp.c_str(), FALSE ); //comment till here
if( poDS == NULL )
{
WApplication::instance()->doJavaScript("alert('Open failed')");
cout << "Open failed";
}
OGRLayer *poLayer;
poLayer = poDS->GetLayerByName( sfile.c_str() ); // comment here
OGRFeature *poFeature;
OGREnvelope * psExtent = new OGREnvelope();
poLayer->GetExtent(psExtent);
double xMin = psExtent->MinX;
double yMin = psExtent->MinY;
double xMax = psExtent->MaxX;
double yMax = psExtent->MaxY;
stringstream strm;
strm << xMin;
string exp;
double scaleFactor;
string bound_string = strm.str();
int size = bound_string.size();
size_t found=bound_string.find("+");
if (found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
if(exp.empty()) {
stringstream strExtent;
strExtent << yMin;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
if(exp.empty()) {
stringstream strExtent;
strExtent << xMax;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
if(exp.empty()) {
stringstream strExtent;
strExtent << yMax;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
if(!exp.empty()) {
int exponent = boost::lexical_cast<int>(exp);
exponent-=3;
scaleFactor = pow (10,exponent);
}
else
{
scaleFactor = 1;
}
xMin/=scaleFactor;
xMax/=scaleFactor;
yMin/=scaleFactor;
yMax/=scaleFactor;
double gWidth = xMax - xMin;
double gHeight = yMax - yMin;
double widthFactor = 1;
double pwidth = abs(gWidth-gHeight);
double s = gWidth - gHeight;
if(s<0.16)
gWidth = gHeight + 0.16;
double scaledX=(XPoint*(gWidth* widthFactor*(100-increase_width)/100)/640 + (xMin+(-x_pos_shift+increase_width/2)/100*gWidth* widthFactor))*scaleFactor;
double scaledY=(YPoint*(gHeight*widthFactor*(-1+increase_height/100))/480 + (yMax+(y_pos_shift-increase_height/2)/100*gHeight*widthFactor))*scaleFactor;
OGRPoint *poPoint =new OGRPoint();
poPoint->setX(scaledX);
poPoint->setY(scaledY);
poLayer->ResetReading();
//.........这里部分代码省略.........
示例13: paintMap
void DrawShape::paintMap(WPaintDevice *paintDevice)
{
WPainter painter(paintDevice);
painter.setRenderHint(WPainter::LowQualityShadows);
painter.save();
if(!sfile.empty()) {
vector<LABELS> label_list;
OGRDataSource *poDS,*PointDS;
string dfile = sfile + ".shp";
string shp = "g_4326/" + sfile + ".shp";
poDS = OGRSFDriverRegistrar::Open(shp.c_str(), FALSE ); //comment till here
if(poDS==NULL)
{
printf( "Open failed.\n" );
exit( 1 );
}
OGRLayer *poLayer;
poLayer = poDS->GetLayerByName( sfile.c_str() ); // comment here
OGRFeature *poFeature;
OGREnvelope * psExtent = new OGREnvelope();
poLayer->GetExtent(psExtent);
double xMin = psExtent->MinX;
double yMin = psExtent->MinY;
double xMax = psExtent->MaxX;
double yMax = psExtent->MaxY;
stringstream strm;
strm << xMin;
string exp;
double scaleFactor;
string bound_string = strm.str();
int size = bound_string.size();
size_t found=bound_string.find("+");
if (found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
if(exp.empty()) {
stringstream strExtent;
strExtent << yMin;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
if(exp.empty()) {
stringstream strExtent;
strExtent << xMax;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
if(exp.empty()) {
stringstream strExtent;
strExtent << yMax;
bound_string = strExtent.str();
size = bound_string.size();
found = bound_string.find("+");
if(found!=string::npos) {
exp = bound_string.substr(found+1,size);
}
}
//cout << "EXXP: " << exp << endl;
if(!exp.empty()) {
int exponent = boost::lexical_cast<int>(exp);
exponent-=3;
scaleFactor = pow (10,exponent);
}
else
{
//cout << "EXXP is empty " << exp << endl;
scaleFactor = 1;
}
xMin/=scaleFactor;
xMax/=scaleFactor;
yMin/=scaleFactor;
yMax/=scaleFactor;
double gWidth = xMax - xMin;
double gHeight = yMax - yMin;
double widthFactor = 1;
double pwidth = abs(gWidth-gHeight);
double s = gWidth - gHeight;
if(s<0.16)
gWidth = gHeight + 0.16;
double ratio=gWidth/gHeight;
//for zoom n pan
if(increase_width<100 && increase_height<100){
//.........这里部分代码省略.........