本文整理汇总了C++中QgsVectorLayer::extent方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::extent方法的具体用法?C++ QgsVectorLayer::extent怎么用?C++ QgsVectorLayer::extent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::extent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: boundingBoxOfLayers
QgsRectangle QgsInterpolationDialog::boundingBoxOfLayers()
{
int nLayers = mLayersTreeWidget->topLevelItemCount();
QgsRectangle combinedLayerExtent;
for ( int i = 0; i < nLayers; ++i )
{
QString layerName = mLayersTreeWidget->topLevelItem( i )->text( 0 );
QgsVectorLayer* theVectorLayer = vectorLayerFromName( layerName );
if ( !theVectorLayer )
{
continue;
}
QgsVectorDataProvider* theProvider = theVectorLayer->dataProvider();
if ( !theProvider )
{
continue;
}
//update extent
QgsRectangle currentLayerExtent = theVectorLayer->extent();
if ( combinedLayerExtent.isEmpty() )
{
combinedLayerExtent = currentLayerExtent;
}
else
{
combinedLayerExtent.combineExtentWith( ¤tLayerExtent );
}
}
return combinedLayerExtent;
}
示例2: estimateRadius
/*
* Estimate a good default radius for the heatmap, based on the
* bounding box size of the layer
*/
double HeatmapGui::estimateRadius()
{
QgsVectorLayer *inputLayer = inputVectorLayer();
// No input layer? Default to radius of 100
if ( !inputLayer )
return 100;
// Find max dimension of layer bounding box
QgsRectangle mExtent = inputLayer->extent();
double maxExtent = max( mExtent.width(), mExtent.height() );
// Return max dimension divided by 30. This is fairly arbitrary
// but approximately corresponds to the default value chosen by ArcMap
// TODO - a better solution is to let the data define the radius
// choice by setting the radius equal to the average Nearest
// Neighbour Index for the closest n points
double estimate = maxExtent / 30;
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
// layer units selected, so convert estimate from map units
QgsCoordinateReferenceSystem layerCrs = inputLayer->crs();
estimate /= mapUnitsOf( 1, layerCrs );
}
// Make estimate pretty by rounding off to first digit only (eg 356->300, 0.567->0.5)
double tens = pow( 10, floor( log10( estimate ) ) );
return floor( estimate / tens + 0.5 ) * tens;
}
示例3: updateBBox
void HeatmapGui::updateBBox()
{
// Set the row/cols and cell sizes here
QgsVectorLayer *inputLayer = inputVectorLayer();
if ( !inputLayer )
return;
mBBox = inputLayer->extent();
QgsCoordinateReferenceSystem layerCrs = inputLayer->crs();
double radiusInMapUnits = 0.0;
if ( mRadiusFieldCheckBox->isChecked() )
{
int idx = inputLayer->fields().indexFromName( mRadiusFieldCombo->currentField() );
double maxInField = inputLayer->maximumValue( idx ).toDouble();
if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radiusInMapUnits = mapUnitsOf( maxInField, layerCrs );
}
else if ( mRadiusFieldUnitCombo->currentIndex() == HeatmapGui::MapUnits )
{
radiusInMapUnits = maxInField;
}
}
else
{
double radiusValue = mBufferSizeLineEdit->text().toDouble();
if ( mBufferUnitCombo->currentIndex() == HeatmapGui::LayerUnits )
{
radiusInMapUnits = mapUnitsOf( radiusValue, layerCrs );
}
else if ( mBufferUnitCombo->currentIndex() == HeatmapGui::MapUnits )
{
radiusInMapUnits = radiusValue;
}
}
// get the distance converted into map units
mBBox.setXMinimum( mBBox.xMinimum() - radiusInMapUnits );
mBBox.setYMinimum( mBBox.yMinimum() - radiusInMapUnits );
mBBox.setXMaximum( mBBox.xMaximum() + radiusInMapUnits );
mBBox.setYMaximum( mBBox.yMaximum() + radiusInMapUnits );
// Leave number of rows the same, and calculate new corresponding cell size and number of columns
mYcellsize = mBBox.height() / ( mRows - 1 );
mXcellsize = mYcellsize;
mColumns = max( mBBox.width() / mXcellsize + 1, 1 );
updateSize();
}
示例4: main
int main(int argc, char ** argv)
{
// Start the Application
QgsApplication app(argc, argv, true);
QString myPluginsDir = "/home/timlinux/apps/lib/qgis";
QString myLayerPath = "/home/timlinux/gisdata/brazil/BR_Cidades/";
QString myLayerBaseName = "Brasil_Cap";
QString myProviderName = "ogr";
// Instantiate Provider Registry
QgsProviderRegistry::instance(myPluginsDir);
// create a maplayer instance
QgsVectorLayer * mypLayer =
new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
QgsSingleSymbolRenderer *mypRenderer = new QgsSingleSymbolRenderer(mypLayer->geometryType());
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
}
// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer, TRUE));
// Create the Map Canvas
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(mypLayer->extent());
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
// Set the Map Canvas Layer Set
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->refresh();
// Start the Application Event Loop
return app.exec();
}
示例5: addLayer
void MainWindow::addLayer()
{
QString myLayerPath = "../data";
QString myLayerBaseName = "test";
QString myProviderName = "ogr";
QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
if (mypLayer->isValid())
{
qDebug("Layer is valid");
}
else
{
qDebug("Layer is NOT valid");
return;
}
//set up a renderer for the layer
QgsSingleSymbolRenderer *mypRenderer = new QgsSingleSymbolRenderer(mypLayer->geometryType());
QList<QgsMapCanvasLayer> myLayerSet;
mypLayer->setRenderer(mypRenderer);
//
//set up labelling for the layer
//
//get the label instance associated with the layer
QgsLabel * mypLabel;
mypLabel = mypLayer->label();
//and the label attributes associated with the label
QgsLabelAttributes * mypLabelAttributes;
mypLabelAttributes = mypLabel->layerAttributes();
//note in QGIS 1.4 and up you should use mypLabel->labelAttributes rather
//get the field list associated with the layer
//we'll print the names out to console for diagnostic purposes
QgsFieldMap myFields = mypLayer->dataProvider()->fields();
for (unsigned int i = 0; i < myFields.size(); i++ )
{
qDebug("Field Name: " + QString(myFields[i].name()).toLocal8Bit() );
}
//just use the last field's name in the fields list as the label field!
qDebug("set label field to " + QString(myFields[myFields.size()-1].name()).toLocal8Bit());
mypLabel->setLabelField( QgsLabel::Text, myFields.size()-1);
//set the colour of the label text
mypLabelAttributes->setColor(Qt::black);
//create a 'halo' effect around each label so it
//can still be read on dark backgrounds
mypLabelAttributes->setBufferEnabled(true);
mypLabelAttributes->setBufferColor(Qt::yellow);
int myType = QgsLabelAttributes::PointUnits;
mypLabelAttributes->setBufferSize(1,myType);
/*
* Here are a bunch of other things you can set based on values on a database field
* the second parameter in each case would be the field name from which the
* attribute can be retrieved.
mypLabel->setLabelField( QgsLabel::Family, "fontFamily" );
mypLabel->setLabelField( QgsLabel::Bold, "fontIsBold" );
mypLabel->setLabelField( QgsLabel::Italic, "fontIsItalic" );
mypLabel->setLabelField( QgsLabel::Underline, "fontIsUnderlined" );
mypLabel->setLabelField( QgsLabel::Size, "fontSize" );
mypLabel->setLabelField( QgsLabel::BufferSize,"fontBufferSize" );
mypLabel->setLabelField( QgsLabel::XCoordinate, "labelX" );
mypLabel->setLabelField( QgsLabel::YCoordinate, "labelY");
mypLabel->setLabelField( QgsLabel::XOffset, "labelXOffset");
mypLabel->setLabelField( QgsLabel::YOffset, "labelYOffset");
mypLabel->setLabelField( QgsLabel::Alignment, "labelAlignment" );
mypLabel->setLabelField( QgsLabel::Angle, "labelAngle");
*/
//lastly we enable labelling!
mypLayer->enableLabels(true);
// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer( mypLayer ) );
// set teh canvas to the extent of our layer
mpMapCanvas->setExtent(mypLayer->extent());
// Set the Map Canvas Layer Set
mpMapCanvas->setLayerSet(myLayerSet);
}
示例6: getFeature
int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format )
{
QgsDebugMsg( "Info format is:" + format );
//read TYPENAME
QMap<QString, QString>::const_iterator type_name_it = mParameterMap.find( "TYPENAME" );
if ( type_name_it != mParameterMap.end() )
{
mTypeName = type_name_it.value();
}
else
{
return 1;
}
QStringList wfsLayersId = mConfigParser->wfsLayers();
QMap< QString, QMap< int, QString > > aliasInfo = mConfigParser->layerAliasInfo();
QMap< QString, QSet<QString> > hiddenAttributes = mConfigParser->hiddenAttributes();
QList<QgsMapLayer*> layerList;
QgsMapLayer* currentLayer = 0;
layerList = mConfigParser->mapLayerFromStyle( mTypeName, "" );
currentLayer = layerList.at( 0 );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
//is there alias info for this vector layer?
QMap< int, QString > layerAliasInfo;
QMap< QString, QMap< int, QString > >::const_iterator aliasIt = aliasInfo.find( currentLayer->id() );
if ( aliasIt != aliasInfo.constEnd() )
{
layerAliasInfo = aliasIt.value();
}
//hidden attributes for this layer
QSet<QString> layerHiddenAttributes;
QMap< QString, QSet<QString> >::const_iterator hiddenIt = hiddenAttributes.find( currentLayer->id() );
if ( hiddenIt != hiddenAttributes.constEnd() )
{
layerHiddenAttributes = hiddenIt.value();
}
//do a select with searchRect and go through all the features
QgsVectorDataProvider* provider = layer->dataProvider();
if ( !provider )
{
return 2;
}
QgsFeature feature;
QgsAttributeMap featureAttributes;
const QgsFieldMap& fields = provider->fields();
//map extent
QgsRectangle searchRect = layer->extent();
//read FEATUREDID
bool fidOk = false;
QString fid;
QMap<QString, QString>::const_iterator fidIt = mParameterMap.find( "FEATUREID" );
if ( fidIt != mParameterMap.end() )
{
fidOk = true;
fid = fidIt.value();
}
//read FILTER
bool filterOk = false;
QDomDocument filter;
QMap<QString, QString>::const_iterator filterIt = mParameterMap.find( "FILTER" );
if ( filterIt != mParameterMap.end() )
{
try
{
QString errorMsg;
if ( !filter.setContent( filterIt.value(), true, &errorMsg ) )
{
QgsDebugMsg( "soap request parse error" );
QgsDebugMsg( "error message: " + errorMsg );
QgsDebugMsg( "the xml string was:" );
QgsDebugMsg( filterIt.value() );
}
else
{
filterOk = true;
}
}
catch ( QgsMapServiceException& e )
{
Q_UNUSED( e );
filterOk = false;
}
}
bool conversionSuccess;
double minx, miny, maxx, maxy;
bool bboxOk = false;
//.........这里部分代码省略.........