added digitising for lines. As this is highly experimental, backup your data before you use this tool. The icon for the button is not very nice. Feel free to change the icon if you have a nicer one

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1772 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2004-07-16 18:38:16 +00:00
parent 2b17ddeba2
commit fe280e3f37
8 changed files with 167 additions and 58 deletions

View File

@ -19,6 +19,7 @@
#include "../../src/qgsfeature.h" #include "../../src/qgsfeature.h"
#include "../../src/qgsfield.h" #include "../../src/qgsfield.h"
#include "../../src/qgsrect.h" #include "../../src/qgsrect.h"
#include "../../src/qgis.h"
#ifdef WIN32 #ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport ) #define QGISEXTERN extern "C" __declspec( dllexport )
#else #else
@ -568,29 +569,40 @@ bool QgsShapeFileProvider::isValid()
bool QgsShapeFileProvider::addFeature(QgsFeature* f) bool QgsShapeFileProvider::addFeature(QgsFeature* f)
{ {
bool returnValue = true; bool returnValue = true;
OGRFeatureDefn* fdef=ogrLayer->GetLayerDefn(); OGRFeatureDefn* fdef=ogrLayer->GetLayerDefn();
OGRFeature* feature=new OGRFeature(fdef); OGRFeature* feature=new OGRFeature(fdef);
/*double x; QGis::WKBTYPE ftype;
double y; memcpy(&ftype, (f->getGeometry()+1), sizeof(int));
memcpy(&x,(f->getGeometry()+5),sizeof(double)); switch(ftype)
{
case QGis::WKBPoint:
{
OGRPoint* p=new OGRPoint();
p->importFromWkb(f->getGeometry(),1+sizeof(int)+2*sizeof(double));
feature->SetGeometry(p);
break;
}
case QGis::WKBLineString:
{
OGRLineString* l=new OGRLineString();
int length;
memcpy(&length,f->getGeometry()+5,sizeof(int));
#ifdef QGISDEBUG #ifdef QGISDEBUG
qWarning("x: "+QString::number(x,'f')); qWarning("length: "+QString::number(length));
#endif #endif
memcpy(&y,(f->getGeometry()+5+sizeof(double)),sizeof(double)); l->importFromWkb(f->getGeometry(),1+2*sizeof(int)+2*length*sizeof(double));
#ifdef QGISDEBUG feature->SetGeometry(l);
qWarning("y: "+QString::number(y,'f')); break;
#endif }
OGRPoint* p=new OGRPoint(x,y,0);*/ }
OGRPoint* p=new OGRPoint();
p->importFromWkb(f->getGeometry(),21); if(ogrLayer->CreateFeature(feature)!=OGRERR_NONE)
feature->SetGeometry(p); {
if(ogrLayer->CreateFeature(feature)!=OGRERR_NONE) //writing failed
{ QMessageBox::warning (0, "Warning", "Writing of the feature failed", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton );
//writing failed returnValue = false;
QMessageBox::warning (0, "Warning", "Writing of the feature failed", QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton ); }
returnValue = false; ogrLayer->SyncToDisk();
}
ogrLayer->SyncToDisk();
return returnValue; return returnValue;
} }

View File

@ -35,7 +35,8 @@ namespace QGis
Identify, Identify,
Table, Table,
Select, Select,
CapturePoint CapturePoint,
CaptureLine
}; };
//! Used for symbology operations //! Used for symbology operations
// Featuure types // Featuure types

View File

@ -1650,6 +1650,11 @@ void QgisApp::capturePoint()
mMapCanvas->setCursor(*mMapCursor); mMapCanvas->setCursor(*mMapCursor);
} }
void QgisApp::captureLine()
{
mMapCanvas->setMapTool(QGis::CaptureLine);
}
void QgisApp::select() void QgisApp::select()
{ {

View File

@ -195,6 +195,8 @@ private:
void about(); void about();
//! activates the capture point tool //! activates the capture point tool
void capturePoint(); void capturePoint();
//! activates the capture line tool
void captureLine();
//! activates the selection tool //! activates the selection tool
void select(); void select();
//! check to see if file is dirty and if so, prompt the user th save it //! check to see if file is dirty and if so, prompt the user th save it

File diff suppressed because one or more lines are too long

View File

@ -243,3 +243,9 @@ void QgisAppBase::showAllLayers()
{ {
} }
void QgisAppBase::captureLine()
{
}

View File

@ -962,6 +962,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
break; break;
case QGis::CapturePoint: case QGis::CapturePoint:
{
QgsPoint idPoint = mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y()); QgsPoint idPoint = mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y());
emit xyClickCoordinates(idPoint); emit xyClickCoordinates(idPoint);
@ -992,7 +993,57 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
#ifdef QGISDEBUG #ifdef QGISDEBUG
std::cout << "CapturePoint : " << idPoint.x() << "," << idPoint.y() << std::endl; std::cout << "CapturePoint : " << idPoint.x() << "," << idPoint.y() << std::endl;
#endif #endif
}
break; break;
case QGis::CaptureLine:
mCaptureList.push_back(mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y()));
if(mCaptureList.size()>1)
{
QPainter paint(this);
paint.setPen(QPen(QColor(255,0,0),4,Qt::DashLine));
std::list<QgsPoint>::iterator it=mCaptureList.end();
--it;
--it;
QgsPoint lastpoint = mCanvasProperties->coordXForm->transform(it->x(),it->y());
paint.drawLine(lastpoint.x(),lastpoint.y(),e->x(),e->y());
}
if(e->button()==Qt::RightButton)
{
QgsVectorLayer* vlayer=dynamic_cast<QgsVectorLayer*>(mCanvasProperties->mapLegend->currentLayer());
if(vlayer)
{
//create QgsFeature with wkb representation
QgsFeature f(0,"WKBLineString");
int size=1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
unsigned char *wkb= new unsigned char[size];
int wkbtype=QGis::WKBLineString;
int length=mCaptureList.size();
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[5],&length, sizeof(int));
int position=1+2*sizeof(int);
double x,y;
for(std::list<QgsPoint>::iterator it=mCaptureList.begin();it!=mCaptureList.end();++it)
{
x=it->x();
memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);
y=it->y();
memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
f.setGeometry(&wkb[0],size);
vlayer->addFeature(&f);
mCaptureList.clear();
refresh();
}
else
{
//not a vector layer
}
}
break;
} }
} }
} // mouseReleaseEvent } // mouseReleaseEvent
@ -1084,6 +1135,7 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)
void QgsMapCanvas::setMapTool(int tool) void QgsMapCanvas::setMapTool(int tool)
{ {
mCanvasProperties->mapTool = tool; mCanvasProperties->mapTool = tool;
mCaptureList.clear();
} // setMapTool } // setMapTool

View File

@ -242,6 +242,9 @@ private:
/// Handle pattern for implementation object /// Handle pattern for implementation object
std::auto_ptr<CanvasProperties> mCanvasProperties; std::auto_ptr<CanvasProperties> mCanvasProperties;
/**List to store the points of digitised lines and polygons*/
std::list<QgsPoint> mCaptureList;
//! Overridden mouse move event //! Overridden mouse move event
void mouseMoveEvent(QMouseEvent * e); void mouseMoveEvent(QMouseEvent * e);