Skip to content
Permalink
Browse files
Adding features to multipoint shapes is now possible with the digitiz…
…ing tool

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5480 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 22, 2006
1 parent 3368244 commit aec20f7eccdfa8491d94018955c774fb17393287
Showing with 99 additions and 12 deletions.
  1. +61 −2 src/core/qgsgeometry.cpp
  2. +38 −10 src/gui/qgsmaptoolcapture.cpp
@@ -295,6 +295,7 @@ QgsPoint QgsGeometry::closestVertex(const QgsPoint& point, QgsGeometryVertexInde
ptr+=sizeof(int);
for(int index=0;index<*npoints;++index)
{
ptr += (1+sizeof(int)); //skip endian and point type
tempx=(double*)ptr;
tempy=(double*)(ptr+sizeof(double));
if(point.sqrDist(*tempx,*tempy)<actdist)
@@ -460,6 +461,21 @@ bool QgsGeometry::moveVertexAt(double x, double y, QgsGeometryVertexIndex atVert
}
}
case QGis::WKBMultiPoint:
{
int* nrPoints = (int*)ptr;
if(vertexnr > *nrPoints || vertexnr < 0)
{
return false;
}
ptr += sizeof(int);
ptr += (2*sizeof(double)+1+sizeof(int))*vertexnr;
ptr += (1+sizeof(int));
memcpy(ptr, &x, sizeof(double));
ptr += sizeof(double);
memcpy(ptr, &y, sizeof(double));
mDirtyGeos = true;
return true;
}
case QGis::WKBLineString:
{
int* nrPoints = (int*)ptr;
@@ -604,6 +620,9 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
break; //cannot remove the only point vertex
}
case QGis::WKBMultiPoint:
{
//todo
}
case QGis::WKBLineString:
{
int* nPoints = (int*)ptr;
@@ -845,7 +864,15 @@ bool QgsGeometry::insertVertexBefore(double x, double y, QgsGeometryVertexIndex
switch(wkbType)
{
case QGis::WKBPoint://cannot insert a vertex before another one on point types
{
delete newbuffer;
return false;
}
case QGis::WKBMultiPoint:
{
//todo
break;
}
case QGis::WKBLineString:
{
int* nPoints = (int*)ptr;
@@ -1127,7 +1154,8 @@ bool QgsGeometry::vertexAt(double &x, double &y,
{
return false;
}
ptr += atVertex.back()*2*sizeof(double);
ptr += atVertex.back()*(2*sizeof(double)+1+sizeof(int));
ptr += 1+sizeof(int);
memcpy(&x, ptr, sizeof(double));
ptr += sizeof(double);
memcpy(&y, ptr, sizeof(double));
@@ -1486,7 +1514,36 @@ QgsRect QgsGeometry::boundingBox() const
ymax=*y;
}
break;

case QGis::WKBMultiPoint:
{
ptr = mGeometry + 1 + sizeof(int);
nPoints = (int *) ptr;
for (idx = 0; idx < *nPoints; idx++)
{
ptr += (1+sizeof(int));
x = (double *) ptr;
ptr += sizeof(double);
y = (double *) ptr;
ptr += sizeof(double);
if (*x < xmin)
{
xmin=*x;
}
if (*x > xmax)
{
xmax=*x;
}
if (*y < ymin)
{
ymin=*y;
}
if (*y > ymax)
{
ymax=*y;
}
}
break;
}
case QGis::WKBLineString:
// get number of points in the line
ptr = mGeometry + 5;
@@ -1812,6 +1869,7 @@ bool QgsGeometry::exportToWkt(unsigned char * geom) const
ptr=geom+5+sizeof(int);
for(idx=0;idx<*nPoints;++idx)
{
ptr += (1+sizeof(int));
if(idx!=0)
{
mWkt+=", ";
@@ -2003,6 +2061,7 @@ geos::Geometry* QgsGeometry::geosGeometry() const
ptr = mGeometry + 1 + 2 * sizeof(int);
for (idx = 0; idx < *nPoints; idx++)
{
ptr += (1 + sizeof(int));
x = (double *) ptr;
ptr += sizeof(double);
y = (double *) ptr;
@@ -119,19 +119,47 @@ QMessageBox::Ok);
// project to layer's SRS
vlayer->snapPoint(savePoint, tolerance);

// create geometry and attach it to feature
int size=5+2*sizeof(double);
unsigned char *wkb = new unsigned char[size];
int wkbtype=QGis::WKBPoint;
int size;
char end=vlayer->endian();
unsigned char *wkb;
int wkbtype;
double x = savePoint.x();
double y = savePoint.y();
memcpy(&wkb[0],&end,1);
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[5], &x, sizeof(double));
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
f->setGeometryAndOwnership(&wkb[0],size);


if(vlayer->getGeometryType() == QGis::WKBPoint)
{
size=1+sizeof(int)+2*sizeof(double);
wkb = new unsigned char[size];
wkbtype=QGis::WKBPoint;
memcpy(&wkb[0],&end,1);
memcpy(&wkb[1],&wkbtype, sizeof(int));
memcpy(&wkb[5], &x, sizeof(double));
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
}
else if(vlayer->getGeometryType() == QGis::WKBMultiPoint)
{
size = 2+3*sizeof(int)+2*sizeof(double);
wkb = new unsigned char[size];
wkbtype=QGis::WKBMultiPoint;
int position = 0;
memcpy(&wkb[position], &end, 1);
position += 1;
memcpy(&wkb[position], &wkbtype, sizeof(int));
position += sizeof(int);
int npoint = 1;
memcpy(&wkb[position], &npoint, sizeof(int));
position += sizeof(int);
memcpy(&wkb[position], &end, 1);
position += 1;
int pointtype = QGis::WKBPoint;
memcpy(&wkb[position],&pointtype, sizeof(int));
position += sizeof(int);
memcpy(&wkb[position], &x, sizeof(double));
position += sizeof(double);
memcpy(&wkb[position], &y, sizeof(double));
}

f->setGeometryAndOwnership(&wkb[0],size);
// add the fields to the QgsFeature
std::vector<QgsField> fields=vlayer->fields();
for(std::vector<QgsField>::iterator it=fields.begin();it!=fields.end();++it)

0 comments on commit aec20f7

Please sign in to comment.