Skip to content

Commit

Permalink
A tool to add polygons to multipolygon features
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6963 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 26, 2007
1 parent 0898c53 commit d98e427
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 38 deletions.
Binary file added images/themes/default/mActionAddIsland.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -27,6 +27,7 @@ qgslinestyledialog.cpp
qgslinestylewidget.cpp
qgsludialog.cpp
qgsmaptooladdfeature.cpp
qgsmaptooladdisland.cpp
qgsmaptooladdring.cpp
qgsmaptoolcapture.cpp
qgsmaptoolidentify.cpp
Expand Down
37 changes: 32 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -145,6 +145,7 @@
// Map tools
//
#include "qgsmaptooladdfeature.h"
#include "qgsmaptooladdisland.h"
#include "qgsmaptooladdring.h"
#include "qgsmaptoolidentify.h"
#include "qgsmaptoolpan.h"
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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
{
Expand Down Expand Up @@ -3433,6 +3449,11 @@ void QgisApp::addRing()
mMapCanvas->setMapTool(mMapTools.mAddRing);
}

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


void QgisApp::deleteVertex()
{
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand All @@ -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
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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();
Expand Down Expand Up @@ -487,6 +489,7 @@ public slots:
QAction *mActionDeleteVertex;
QAction *mActionMoveVertex;
QAction *mActionAddRing;
QAction *mActionAddIsland;
QAction *mActionEditCut;
QAction *mActionEditCopy;
QAction *mActionEditPaste;
Expand Down Expand Up @@ -543,6 +546,7 @@ public slots:
QgsMapTool* mVertexMove;
QgsMapTool* mVertexDelete;
QgsMapTool* mAddRing;
QgsMapTool* mAddIsland;
} mMapTools;

//!The name of the active theme
Expand Down
15 changes: 7 additions & 8 deletions src/app/qgsgeomtypedialog.cpp
Expand Up @@ -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()
Expand Down
41 changes: 34 additions & 7 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -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();

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


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

// POINT CAPTURING
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d98e427

Please sign in to comment.