Skip to content

Commit 6851060

Browse files
author
mhugent
committed
A tool to add polygons to multipolygon features
git-svn-id: http://svn.osgeo.org/qgis/trunk@6963 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent ed41e1f commit 6851060

14 files changed

+371
-38
lines changed
841 Bytes
Loading

src/app/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ qgslinestyledialog.cpp
2727
qgslinestylewidget.cpp
2828
qgsludialog.cpp
2929
qgsmaptooladdfeature.cpp
30+
qgsmaptooladdisland.cpp
3031
qgsmaptooladdring.cpp
3132
qgsmaptoolcapture.cpp
3233
qgsmaptoolidentify.cpp

src/app/qgisapp.cpp

+32-5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
// Map tools
146146
//
147147
#include "qgsmaptooladdfeature.h"
148+
#include "qgsmaptooladdisland.h"
148149
#include "qgsmaptooladdring.h"
149150
#include "qgsmaptoolidentify.h"
150151
#include "qgsmaptoolpan.h"
@@ -754,6 +755,11 @@ void QgisApp::createActions()
754755
connect(mActionAddRing, SIGNAL(triggered()), this, SLOT(addRing()));
755756
mActionAddRing->setEnabled(false);
756757

758+
mActionAddIsland = new QAction(QIcon(myIconPath+"/mActionAddIsland.png"), tr("Add Island"), this);
759+
mActionAddIsland->setStatusTip(tr("Add Island to multipolygon"));
760+
connect(mActionAddIsland, SIGNAL(triggered()), this, SLOT(addIsland()));
761+
mActionAddIsland->setEnabled(false);
762+
757763
mActionEditCut = new QAction(QIcon(myIconPath+"/mActionEditCut.png"), tr("Cut Features"), this);
758764
mActionEditCut->setStatusTip(tr("Cut selected features"));
759765
connect(mActionEditCut, SIGNAL(triggered()), this, SLOT(editCut()));
@@ -819,6 +825,8 @@ void QgisApp::createActionGroups()
819825
mMapToolGroup->addAction(mActionMoveVertex);
820826
mActionAddRing->setCheckable(true);
821827
mMapToolGroup->addAction(mActionAddRing);
828+
mActionAddIsland->setCheckable(true);
829+
mMapToolGroup->addAction(mActionAddIsland);
822830
}
823831

824832
void QgisApp::createMenus()
@@ -974,6 +982,7 @@ void QgisApp::createToolBars()
974982
mDigitizeToolBar->addAction(mActionDeleteVertex);
975983
mDigitizeToolBar->addAction(mActionMoveVertex);
976984
mDigitizeToolBar->addAction(mActionAddRing);
985+
mDigitizeToolBar->addAction(mActionAddIsland);
977986
mDigitizeToolBar->addAction(mActionEditCut);
978987
mDigitizeToolBar->addAction(mActionEditCopy);
979988
mDigitizeToolBar->addAction(mActionEditPaste);
@@ -1231,7 +1240,8 @@ void QgisApp::createCanvas()
12311240
mMapTools.mVertexDelete = new QgsMapToolVertexEdit(mMapCanvas, QgsMapToolVertexEdit::DeleteVertex);
12321241
mMapTools.mVertexDelete->setAction(mActionDeleteVertex);
12331242
mMapTools.mAddRing = new QgsMapToolAddRing(mMapCanvas);
1234-
//mMapTools.mAddRing->setAction(mActionAddRing);
1243+
mMapTools.mAddRing->setAction(mActionAddRing);
1244+
mMapTools.mAddIsland = new QgsMapToolAddIsland(mMapCanvas);
12351245
}
12361246

12371247
void QgisApp::createOverview()
@@ -2612,6 +2622,7 @@ void QgisApp::newVectorLayer()
26122622
createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc)myLib->resolve("createEmptyDataSource");
26132623
if(createEmptyDataSource)
26142624
{
2625+
#if 0
26152626
if(geometrytype == QGis::WKBPoint)
26162627
{
26172628
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPoint, attributes);
@@ -2624,13 +2635,18 @@ void QgisApp::newVectorLayer()
26242635
{
26252636
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPolygon, attributes);
26262637
}
2638+
#endif
2639+
if(geometrytype != QGis::WKBUnknown)
2640+
{
2641+
createEmptyDataSource(filename,fileformat, enc, geometrytype, attributes);
2642+
}
26272643
else
2628-
{
2644+
{
26292645
#ifdef QGISDEBUG
2630-
qWarning("QgisApp.cpp: geometry type not recognised");
2646+
qWarning("QgisApp.cpp: geometry type not recognised");
26312647
#endif
2632-
return;
2633-
}
2648+
return;
2649+
}
26342650
}
26352651
else
26362652
{
@@ -3433,6 +3449,11 @@ void QgisApp::addRing()
34333449
mMapCanvas->setMapTool(mMapTools.mAddRing);
34343450
}
34353451

3452+
void QgisApp::addIsland()
3453+
{
3454+
mMapCanvas->setMapTool(mMapTools.mAddIsland);
3455+
}
3456+
34363457

34373458
void QgisApp::deleteVertex()
34383459
{
@@ -4783,6 +4804,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
47834804
mActionAddVertex->setEnabled(false);
47844805
mActionDeleteVertex->setEnabled(false);
47854806
mActionAddRing->setEnabled(false);
4807+
mActionAddIsland->setEnabled(false);
47864808
if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
47874809
{
47884810
mActionMoveVertex->setEnabled(true);
@@ -4802,6 +4824,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
48024824
mActionCapturePoint->setEnabled(false);
48034825
mActionCapturePolygon->setEnabled(false);
48044826
mActionAddRing->setEnabled(false);
4827+
mActionAddIsland->setEnabled(false);
48054828
}
48064829
else if(vlayer->vectorType() == QGis::Polygon)
48074830
{
@@ -4826,6 +4849,9 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
48264849
if(vlayer->vectorType() == QGis::Polygon)
48274850
{
48284851
mActionAddRing->setEnabled(true);
4852+
//some polygon layers contain also multipolygon features.
4853+
//Therefore, the test for multipolygon is done in QgsGeometry
4854+
mActionAddIsland->setEnabled(true);
48294855
}
48304856
}
48314857
else
@@ -4849,6 +4875,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
48494875
mActionCapturePolygon->setEnabled(false);
48504876
mActionDeleteSelected->setEnabled(false);
48514877
mActionAddRing->setEnabled(false);
4878+
mActionAddIsland->setEnabled(false);
48524879
mActionAddVertex->setEnabled(false);
48534880
mActionDeleteVertex->setEnabled(false);
48544881
mActionMoveVertex->setEnabled(false);

src/app/qgisapp.h

+4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ public slots:
295295
void deleteVertex();
296296
//! activates the add ring tool
297297
void addRing();
298+
//! activates the add island tool
299+
void addIsland();
298300

299301
//! activates the selection tool
300302
void select();
@@ -487,6 +489,7 @@ public slots:
487489
QAction *mActionDeleteVertex;
488490
QAction *mActionMoveVertex;
489491
QAction *mActionAddRing;
492+
QAction *mActionAddIsland;
490493
QAction *mActionEditCut;
491494
QAction *mActionEditCopy;
492495
QAction *mActionEditPaste;
@@ -543,6 +546,7 @@ public slots:
543546
QgsMapTool* mVertexMove;
544547
QgsMapTool* mVertexDelete;
545548
QgsMapTool* mAddRing;
549+
QgsMapTool* mAddIsland;
546550
} mMapTools;
547551

548552
//!The name of the active theme

src/app/qgsgeomtypedialog.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,19 @@ QgsGeomTypeDialog::~QgsGeomTypeDialog()
4545

4646
QGis::WKBTYPE QgsGeomTypeDialog::selectedType() const
4747
{
48-
if(mPointRadioButton->isChecked())
48+
if(mPointRadioButton->isChecked())
4949
{
50-
return QGis::WKBPoint;
50+
return QGis::WKBPoint;
5151
}
52-
else if(mLineRadioButton->isChecked())
52+
else if(mLineRadioButton->isChecked())
5353
{
54-
return QGis::WKBLineString;
54+
return QGis::WKBLineString;
5555
}
56-
else if(mPolygonRadioButton->isChecked())
56+
else if(mPolygonRadioButton->isChecked())
5757
{
58-
return QGis::WKBPolygon;
58+
return QGis::WKBPolygon;
5959
}
60-
61-
return QGis::WKBUnknown;
60+
return QGis::WKBUnknown;
6261
}
6362

6463
void QgsGeomTypeDialog::on_mAddAttributeButton_clicked()

src/app/qgsmaptooladdfeature.cpp

+34-7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
4646
QObject::tr("The current layer is not a vector layer"));
4747
return;
4848
}
49+
50+
QGis::WKBTYPE layerWKBType = vlayer->geometryType();
51+
52+
//no support for adding features to 2.5D types yet
53+
if(layerWKBType == QGis::WKBLineString25D || layerWKBType == QGis::WKBPolygon25D || \
54+
layerWKBType == QGis::WKBMultiLineString25D || layerWKBType == QGis::WKBPoint25D || layerWKBType == QGis::WKBMultiPoint25D)
55+
{
56+
QMessageBox::critical(0, QObject::tr("2.5D shape type not supported"), QObject::tr("Adding features to 2.5D shapetypes is not supported yet"));
57+
delete mRubberBand;
58+
mRubberBand = NULL;
59+
mCapturing = FALSE;
60+
mCaptureList.clear();
61+
mCanvas->refresh();
62+
return;
63+
}
4964

5065
QgsVectorDataProvider* provider = vlayer->getDataProvider();
5166

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

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

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

113-
if(vlayer->geometryType() == QGis::WKBPoint)
129+
if(layerWKBType == QGis::WKBPoint)
114130
{
115131
size=1+sizeof(int)+2*sizeof(double);
116132
wkb = new unsigned char[size];
@@ -120,7 +136,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
120136
memcpy(&wkb[5], &x, sizeof(double));
121137
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
122138
}
123-
else if(vlayer->geometryType() == QGis::WKBMultiPoint)
139+
else if(layerWKBType == QGis::WKBMultiPoint)
124140
{
125141
size = 2+3*sizeof(int)+2*sizeof(double);
126142
wkb = new unsigned char[size];
@@ -212,9 +228,10 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
212228
unsigned char* wkb;
213229
int size;
214230
char end=QgsApplication::endian();
231+
215232
if(mTool == CaptureLine)
216233
{
217-
if(vlayer->geometryType() == QGis::WKBLineString)
234+
if(layerWKBType == QGis::WKBLineString)
218235
{
219236
size=1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
220237
wkb= new unsigned char[size];
@@ -238,7 +255,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
238255
position+=sizeof(double);
239256
}
240257
}
241-
else if(vlayer->geometryType() == QGis::WKBMultiLineString)
258+
else if(layerWKBType == QGis::WKBMultiLineString)
242259
{
243260
size = 1+2*sizeof(int)+1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
244261
wkb= new unsigned char[size];
@@ -272,11 +289,16 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
272289
memcpy(&wkb[position],&y,sizeof(double));
273290
position+=sizeof(double);
274291
}
275-
}
292+
}
293+
else
294+
{
295+
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
296+
return; //unknown wkbtype
297+
}
276298
}
277299
else // polygon
278300
{
279-
if(vlayer->geometryType() == QGis::WKBPolygon)
301+
if(layerWKBType == QGis::WKBPolygon)
280302
{
281303
size=1+3*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
282304
wkb= new unsigned char[size];
@@ -313,7 +335,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
313335

314336
memcpy(&wkb[position],&y,sizeof(double));
315337
}
316-
else if(vlayer->geometryType() == QGis::WKBMultiPolygon)
338+
else if(layerWKBType == QGis::WKBMultiPolygon)
317339
{
318340
size = 2+5*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
319341
wkb = new unsigned char[size];
@@ -360,6 +382,11 @@ void QgsMapToolAddFeature::canvasReleaseEvent(QMouseEvent * e)
360382
position+=sizeof(double);
361383
memcpy(&wkb[position],&y,sizeof(double));
362384
}
385+
else
386+
{
387+
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot add feature. Unknown WKB type"));
388+
return; //unknown wkbtype
389+
}
363390
}
364391
f->setGeometryAndOwnership(&wkb[0],size);
365392

0 commit comments

Comments
 (0)