Skip to content
Permalink
Browse files
A tool to add polygons to multipolygon features
git-svn-id: http://svn.osgeo.org/qgis/trunk@6963 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 26, 2007
1 parent ed41e1f commit 68510607ec7e3401374b9049ee128028c1038a38
Binary file not shown.
@@ -27,6 +27,7 @@ qgslinestyledialog.cpp
qgslinestylewidget.cpp
qgsludialog.cpp
qgsmaptooladdfeature.cpp
qgsmaptooladdisland.cpp
qgsmaptooladdring.cpp
qgsmaptoolcapture.cpp
qgsmaptoolidentify.cpp
@@ -145,6 +145,7 @@
// Map tools
//
#include "qgsmaptooladdfeature.h"
#include "qgsmaptooladdisland.h"
#include "qgsmaptooladdring.h"
#include "qgsmaptoolidentify.h"
#include "qgsmaptoolpan.h"
@@ -754,6 +755,11 @@ void QgisApp::createActions()
connect(mActionAddRing, SIGNAL(triggered()), this, SLOT(addRing()));
mActionAddRing->setEnabled(false);

mActionAddIsland = new QAction(QIcon(myIconPath+"/mActionAddIsland.png"), tr("Add Island"), this);
mActionAddIsland->setStatusTip(tr("Add Island to multipolygon"));
connect(mActionAddIsland, SIGNAL(triggered()), this, SLOT(addIsland()));
mActionAddIsland->setEnabled(false);

mActionEditCut = new QAction(QIcon(myIconPath+"/mActionEditCut.png"), tr("Cut Features"), this);
mActionEditCut->setStatusTip(tr("Cut selected features"));
connect(mActionEditCut, SIGNAL(triggered()), this, SLOT(editCut()));
@@ -819,6 +825,8 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction(mActionMoveVertex);
mActionAddRing->setCheckable(true);
mMapToolGroup->addAction(mActionAddRing);
mActionAddIsland->setCheckable(true);
mMapToolGroup->addAction(mActionAddIsland);
}

void QgisApp::createMenus()
@@ -974,6 +982,7 @@ void QgisApp::createToolBars()
mDigitizeToolBar->addAction(mActionDeleteVertex);
mDigitizeToolBar->addAction(mActionMoveVertex);
mDigitizeToolBar->addAction(mActionAddRing);
mDigitizeToolBar->addAction(mActionAddIsland);
mDigitizeToolBar->addAction(mActionEditCut);
mDigitizeToolBar->addAction(mActionEditCopy);
mDigitizeToolBar->addAction(mActionEditPaste);
@@ -1231,7 +1240,8 @@ void QgisApp::createCanvas()
mMapTools.mVertexDelete = new QgsMapToolVertexEdit(mMapCanvas, QgsMapToolVertexEdit::DeleteVertex);
mMapTools.mVertexDelete->setAction(mActionDeleteVertex);
mMapTools.mAddRing = new QgsMapToolAddRing(mMapCanvas);
//mMapTools.mAddRing->setAction(mActionAddRing);
mMapTools.mAddRing->setAction(mActionAddRing);
mMapTools.mAddIsland = new QgsMapToolAddIsland(mMapCanvas);
}

void QgisApp::createOverview()
@@ -2612,6 +2622,7 @@ void QgisApp::newVectorLayer()
createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc)myLib->resolve("createEmptyDataSource");
if(createEmptyDataSource)
{
#if 0
if(geometrytype == QGis::WKBPoint)
{
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPoint, attributes);
@@ -2624,13 +2635,18 @@ void QgisApp::newVectorLayer()
{
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPolygon, attributes);
}
#endif
if(geometrytype != QGis::WKBUnknown)
{
createEmptyDataSource(filename,fileformat, enc, geometrytype, attributes);
}
else
{
{
#ifdef QGISDEBUG
qWarning("QgisApp.cpp: geometry type not recognised");
qWarning("QgisApp.cpp: geometry type not recognised");
#endif
return;
}
return;
}
}
else
{
@@ -3433,6 +3449,11 @@ void QgisApp::addRing()
mMapCanvas->setMapTool(mMapTools.mAddRing);
}

void QgisApp::addIsland()
{
mMapCanvas->setMapTool(mMapTools.mAddIsland);
}


void QgisApp::deleteVertex()
{
@@ -4783,6 +4804,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionAddRing->setEnabled(false);
mActionAddIsland->setEnabled(false);
if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
{
mActionMoveVertex->setEnabled(true);
@@ -4802,6 +4824,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
mActionCapturePoint->setEnabled(false);
mActionCapturePolygon->setEnabled(false);
mActionAddRing->setEnabled(false);
mActionAddIsland->setEnabled(false);
}
else if(vlayer->vectorType() == QGis::Polygon)
{
@@ -4826,6 +4849,9 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
if(vlayer->vectorType() == QGis::Polygon)
{
mActionAddRing->setEnabled(true);
//some polygon layers contain also multipolygon features.
//Therefore, the test for multipolygon is done in QgsGeometry
mActionAddIsland->setEnabled(true);
}
}
else
@@ -4849,6 +4875,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
mActionCapturePolygon->setEnabled(false);
mActionDeleteSelected->setEnabled(false);
mActionAddRing->setEnabled(false);
mActionAddIsland->setEnabled(false);
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
@@ -295,6 +295,8 @@ public slots:
void deleteVertex();
//! activates the add ring tool
void addRing();
//! activates the add island tool
void addIsland();

//! activates the selection tool
void select();
@@ -487,6 +489,7 @@ public slots:
QAction *mActionDeleteVertex;
QAction *mActionMoveVertex;
QAction *mActionAddRing;
QAction *mActionAddIsland;
QAction *mActionEditCut;
QAction *mActionEditCopy;
QAction *mActionEditPaste;
@@ -543,6 +546,7 @@ public slots:
QgsMapTool* mVertexMove;
QgsMapTool* mVertexDelete;
QgsMapTool* mAddRing;
QgsMapTool* mAddIsland;
} mMapTools;

//!The name of the active theme
@@ -45,20 +45,19 @@ QgsGeomTypeDialog::~QgsGeomTypeDialog()

QGis::WKBTYPE QgsGeomTypeDialog::selectedType() const
{
if(mPointRadioButton->isChecked())
if(mPointRadioButton->isChecked())
{
return QGis::WKBPoint;
return QGis::WKBPoint;
}
else if(mLineRadioButton->isChecked())
else if(mLineRadioButton->isChecked())
{
return QGis::WKBLineString;
return QGis::WKBLineString;
}
else if(mPolygonRadioButton->isChecked())
else if(mPolygonRadioButton->isChecked())
{
return QGis::WKBPolygon;
return QGis::WKBPolygon;
}

return QGis::WKBUnknown;
return QGis::WKBUnknown;
}

void QgsGeomTypeDialog::on_mAddAttributeButton_clicked()
@@ -46,6 +46,21 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
QObject::tr("The current layer is not a vector layer"));
return;
}

QGis::WKBTYPE layerWKBType = vlayer->geometryType();

//no support for adding features to 2.5D types yet
if(layerWKBType == QGis::WKBLineString25D || layerWKBType == QGis::WKBPolygon25D || \
layerWKBType == QGis::WKBMultiLineString25D || layerWKBType == QGis::WKBPoint25D || layerWKBType == QGis::WKBMultiPoint25D)
{
QMessageBox::critical(0, QObject::tr("2.5D shape type not supported"), QObject::tr("Adding features to 2.5D shapetypes is not supported yet"));
delete mRubberBand;
mRubberBand = NULL;
mCapturing = FALSE;
mCaptureList.clear();
mCanvas->refresh();
return;
}

QgsVectorDataProvider* provider = vlayer->getDataProvider();

@@ -64,6 +79,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
return;
}


double tolerance = QgsProject::instance()->readDoubleEntry("Digitizing","/Tolerance",0);

// POINT CAPTURING
@@ -110,7 +126,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
double x = savePoint.x();
double y = savePoint.y();

if(vlayer->geometryType() == QGis::WKBPoint)
if(layerWKBType == QGis::WKBPoint)
{
size=1+sizeof(int)+2*sizeof(double);
wkb = new unsigned char[size];
@@ -120,7 +136,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
memcpy(&wkb[5], &x, sizeof(double));
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
}
else if(vlayer->geometryType() == QGis::WKBMultiPoint)
else if(layerWKBType == QGis::WKBMultiPoint)
{
size = 2+3*sizeof(int)+2*sizeof(double);
wkb = new unsigned char[size];
@@ -212,9 +228,10 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
unsigned char* wkb;
int size;
char end=QgsApplication::endian();

if(mTool == CaptureLine)
{
if(vlayer->geometryType() == QGis::WKBLineString)
if(layerWKBType == QGis::WKBLineString)
{
size=1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
wkb= new unsigned char[size];
@@ -238,7 +255,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
position+=sizeof(double);
}
}
else if(vlayer->geometryType() == QGis::WKBMultiLineString)
else if(layerWKBType == QGis::WKBMultiLineString)
{
size = 1+2*sizeof(int)+1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
wkb= new unsigned char[size];
@@ -272,11 +289,16 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
}
}
else
{
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
return; //unknown wkbtype
}
}
else // polygon
{
if(vlayer->geometryType() == QGis::WKBPolygon)
if(layerWKBType == QGis::WKBPolygon)
{
size=1+3*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
wkb= new unsigned char[size];
@@ -313,7 +335,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)

memcpy(&wkb[position],&y,sizeof(double));
}
else if(vlayer->geometryType() == QGis::WKBMultiPolygon)
else if(layerWKBType == QGis::WKBMultiPolygon)
{
size = 2+5*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
wkb = new unsigned char[size];
@@ -360,6 +382,11 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
position+=sizeof(double);
memcpy(&wkb[position],&y,sizeof(double));
}
else
{
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
return; //unknown wkbtype
}
}
f->setGeometryAndOwnership(&wkb[0],size);

Loading

0 comments on commit 6851060

Please sign in to comment.