mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
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:
parent
2b17ddeba2
commit
fe280e3f37
@ -19,6 +19,7 @@
|
||||
#include "../../src/qgsfeature.h"
|
||||
#include "../../src/qgsfield.h"
|
||||
#include "../../src/qgsrect.h"
|
||||
#include "../../src/qgis.h"
|
||||
#ifdef WIN32
|
||||
#define QGISEXTERN extern "C" __declspec( dllexport )
|
||||
#else
|
||||
@ -570,20 +571,31 @@ bool QgsShapeFileProvider::addFeature(QgsFeature* f)
|
||||
bool returnValue = true;
|
||||
OGRFeatureDefn* fdef=ogrLayer->GetLayerDefn();
|
||||
OGRFeature* feature=new OGRFeature(fdef);
|
||||
/*double x;
|
||||
double y;
|
||||
memcpy(&x,(f->getGeometry()+5),sizeof(double));
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("x: "+QString::number(x,'f'));
|
||||
#endif
|
||||
memcpy(&y,(f->getGeometry()+5+sizeof(double)),sizeof(double));
|
||||
#ifdef QGISDEBUG
|
||||
qWarning("y: "+QString::number(y,'f'));
|
||||
#endif
|
||||
OGRPoint* p=new OGRPoint(x,y,0);*/
|
||||
QGis::WKBTYPE ftype;
|
||||
memcpy(&ftype, (f->getGeometry()+1), sizeof(int));
|
||||
switch(ftype)
|
||||
{
|
||||
case QGis::WKBPoint:
|
||||
{
|
||||
OGRPoint* p=new OGRPoint();
|
||||
p->importFromWkb(f->getGeometry(),21);
|
||||
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
|
||||
qWarning("length: "+QString::number(length));
|
||||
#endif
|
||||
l->importFromWkb(f->getGeometry(),1+2*sizeof(int)+2*length*sizeof(double));
|
||||
feature->SetGeometry(l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ogrLayer->CreateFeature(feature)!=OGRERR_NONE)
|
||||
{
|
||||
//writing failed
|
||||
|
@ -35,7 +35,8 @@ namespace QGis
|
||||
Identify,
|
||||
Table,
|
||||
Select,
|
||||
CapturePoint
|
||||
CapturePoint,
|
||||
CaptureLine
|
||||
};
|
||||
//! Used for symbology operations
|
||||
// Featuure types
|
||||
|
@ -1650,6 +1650,11 @@ void QgisApp::capturePoint()
|
||||
mMapCanvas->setCursor(*mMapCursor);
|
||||
}
|
||||
|
||||
void QgisApp::captureLine()
|
||||
{
|
||||
mMapCanvas->setMapTool(QGis::CaptureLine);
|
||||
}
|
||||
|
||||
void QgisApp::select()
|
||||
{
|
||||
|
||||
|
@ -195,6 +195,8 @@ private:
|
||||
void about();
|
||||
//! activates the capture point tool
|
||||
void capturePoint();
|
||||
//! activates the capture line tool
|
||||
void captureLine();
|
||||
//! activates the selection tool
|
||||
void select();
|
||||
//! 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
@ -243,3 +243,9 @@ void QgisAppBase::showAllLayers()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void QgisAppBase::captureLine()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -962,6 +962,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
|
||||
break;
|
||||
|
||||
case QGis::CapturePoint:
|
||||
{
|
||||
QgsPoint idPoint = mCanvasProperties->coordXForm->toMapCoordinates(e->x(), e->y());
|
||||
emit xyClickCoordinates(idPoint);
|
||||
|
||||
@ -992,6 +993,56 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
|
||||
#ifdef QGISDEBUG
|
||||
std::cout << "CapturePoint : " << idPoint.x() << "," << idPoint.y() << std::endl;
|
||||
#endif
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1084,6 +1135,7 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)
|
||||
void QgsMapCanvas::setMapTool(int tool)
|
||||
{
|
||||
mCanvasProperties->mapTool = tool;
|
||||
mCaptureList.clear();
|
||||
} // setMapTool
|
||||
|
||||
|
||||
|
@ -242,6 +242,9 @@ private:
|
||||
/// Handle pattern for implementation object
|
||||
std::auto_ptr<CanvasProperties> mCanvasProperties;
|
||||
|
||||
/**List to store the points of digitised lines and polygons*/
|
||||
std::list<QgsPoint> mCaptureList;
|
||||
|
||||
//! Overridden mouse move event
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user