Skip to content
Permalink
Browse files
added code to allow line capturing in multiline layers
git-svn-id: http://svn.osgeo.org/qgis/trunk@5479 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 20, 2006
1 parent 45cf9dd commit d1f0c756601cfa29579015484431a6474b0a032b
Showing with 106 additions and 54 deletions.
  1. +99 −54 src/gui/qgsmaptoolcapture.cpp
  2. +5 −0 src/gui/qgsvectorlayer.cpp
  3. +2 −0 src/gui/qgsvectorlayer.h
@@ -205,64 +205,109 @@ QMessageBox::Ok);
char end=vlayer->endian();
if(mTool == CaptureLine)
{
size=1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
wkb= new unsigned char[size];
int wkbtype=QGis::WKBLineString;
int length=mCaptureList.size();
memcpy(&wkb[0],&end,1);
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)
{
QgsPoint savePoint = maybeInversePoint(*it, "adding line");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
if(vlayer->getGeometryType() == QGis::WKBLineString)
{
size=1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
wkb= new unsigned char[size];
int wkbtype=QGis::WKBLineString;
int length=mCaptureList.size();
memcpy(&wkb[0],&end,1);
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[1+sizeof(int)],&length, sizeof(int));
int position=1+2*sizeof(int);
double x,y;
for(std::list<QgsPoint>::iterator it=mCaptureList.begin();it!=mCaptureList.end();++it)
{
QgsPoint savePoint = maybeInversePoint(*it, "adding line");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
}
else if(vlayer->getGeometryType() == QGis::WKBMultiLineString)
{
size = 1+2*sizeof(int)+1+2*sizeof(int)+2*mCaptureList.size()*sizeof(double);
wkb= new unsigned char[size];
int position = 0;
int wkbtype=QGis::WKBMultiLineString;
memcpy(&wkb[position], &end, 1);
position += 1;
memcpy(&wkb[position], &wkbtype, sizeof(int));
position += sizeof(int);
int nlines = 1;
memcpy(&wkb[position], &nlines, sizeof(int));
position += sizeof(int);
memcpy(&wkb[position], &end, 1);
position += 1;
int linewkbtype = QGis::WKBLineString;
memcpy(&wkb[position], &linewkbtype, sizeof(int));
position += sizeof(int);
int length=mCaptureList.size();
memcpy(&wkb[position], &length, sizeof(int));
position += sizeof(int);
double x,y;
for(std::list<QgsPoint>::iterator it=mCaptureList.begin();it!=mCaptureList.end();++it)
{
QgsPoint savePoint = maybeInversePoint(*it, "adding line");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
}
}
else // polygon
{
size=1+3*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
wkb= new unsigned char[size];
int wkbtype=QGis::WKBPolygon;
int length=mCaptureList.size()+1;//+1 because the first point is needed twice
int numrings=1;
memcpy(&wkb[0],&end,1);
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[1+sizeof(int)],&numrings,sizeof(int));
memcpy(&wkb[1+2*sizeof(int)],&length, sizeof(int));
int position=1+3*sizeof(int);
double x,y;
std::list<QgsPoint>::iterator it;
for(it=mCaptureList.begin();it!=mCaptureList.end();++it)
{
QgsPoint savePoint = maybeInversePoint(*it, "adding poylgon");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
// close the polygon
it=mCaptureList.begin();
QgsPoint savePoint = maybeInversePoint(*it, "closing polygon");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);
if(vlayer->getGeometryType() == QGis::WKBPolygon)
{
size=1+3*sizeof(int)+2*(mCaptureList.size()+1)*sizeof(double);
wkb= new unsigned char[size];
int wkbtype=QGis::WKBPolygon;
int length=mCaptureList.size()+1;//+1 because the first point is needed twice
int numrings=1;
memcpy(&wkb[0],&end,1);
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[1+sizeof(int)],&numrings,sizeof(int));
memcpy(&wkb[1+2*sizeof(int)],&length, sizeof(int));
int position=1+3*sizeof(int);
double x,y;
std::list<QgsPoint>::iterator it;
for(it=mCaptureList.begin();it!=mCaptureList.end();++it)
{
QgsPoint savePoint = maybeInversePoint(*it, "adding poylgon");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
position+=sizeof(double);
}
// close the polygon
it=mCaptureList.begin();
QgsPoint savePoint = maybeInversePoint(*it, "closing polygon");
x = savePoint.x();
y = savePoint.y();

memcpy(&wkb[position],&y,sizeof(double));
memcpy(&wkb[position],&x,sizeof(double));
position+=sizeof(double);

memcpy(&wkb[position],&y,sizeof(double));
}
else if(vlayer->getGeometryType() == QGis::WKBMultiPolygon)
{
//todo
}
}
f->setGeometryAndOwnership(&wkb[0],size);

@@ -1263,6 +1263,11 @@ QGis::VectorType QgsVectorLayer::vectorType() const
return QGis::Unknown;
}

QGis::WKBTYPE QgsVectorLayer::getGeometryType() const
{
return (QGis::WKBTYPE)(geometryType);
}

QgsVectorLayerProperties *QgsVectorLayer::propertiesDialog()
{
return m_propertiesDialog;
@@ -208,6 +208,8 @@ public slots:
void setLayerProperties(QgsVectorLayerProperties * properties);
/**Returns point, line or polygon*/
QGis::VectorType vectorType() const;
/**Returns the WKBType or WKBUnknown in case of error*/
QGis::WKBTYPE getGeometryType() const;
/**Returns a pointer to the properties dialog*/
QgsVectorLayerProperties *propertiesDialog();
/**Returns the bounding box of the selected features. If there is no selection, QgsRect(0,0,0,0) is returned*/

0 comments on commit d1f0c75

Please sign in to comment.