Skip to content

Commit cb77412

Browse files
author
mhugent
committedMay 22, 2006
Adding features to multipoint shapes is now possible with the digitizing tool
git-svn-id: http://svn.osgeo.org/qgis/trunk@5480 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d1f0c75 commit cb77412

File tree

2 files changed

+99
-12
lines changed

2 files changed

+99
-12
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ QgsPoint QgsGeometry::closestVertex(const QgsPoint& point, QgsGeometryVertexInde
295295
ptr+=sizeof(int);
296296
for(int index=0;index<*npoints;++index)
297297
{
298+
ptr += (1+sizeof(int)); //skip endian and point type
298299
tempx=(double*)ptr;
299300
tempy=(double*)(ptr+sizeof(double));
300301
if(point.sqrDist(*tempx,*tempy)<actdist)
@@ -460,6 +461,21 @@ bool QgsGeometry::moveVertexAt(double x, double y, QgsGeometryVertexIndex atVert
460461
}
461462
}
462463
case QGis::WKBMultiPoint:
464+
{
465+
int* nrPoints = (int*)ptr;
466+
if(vertexnr > *nrPoints || vertexnr < 0)
467+
{
468+
return false;
469+
}
470+
ptr += sizeof(int);
471+
ptr += (2*sizeof(double)+1+sizeof(int))*vertexnr;
472+
ptr += (1+sizeof(int));
473+
memcpy(ptr, &x, sizeof(double));
474+
ptr += sizeof(double);
475+
memcpy(ptr, &y, sizeof(double));
476+
mDirtyGeos = true;
477+
return true;
478+
}
463479
case QGis::WKBLineString:
464480
{
465481
int* nrPoints = (int*)ptr;
@@ -604,6 +620,9 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
604620
break; //cannot remove the only point vertex
605621
}
606622
case QGis::WKBMultiPoint:
623+
{
624+
//todo
625+
}
607626
case QGis::WKBLineString:
608627
{
609628
int* nPoints = (int*)ptr;
@@ -845,7 +864,15 @@ bool QgsGeometry::insertVertexBefore(double x, double y, QgsGeometryVertexIndex
845864
switch(wkbType)
846865
{
847866
case QGis::WKBPoint://cannot insert a vertex before another one on point types
867+
{
868+
delete newbuffer;
869+
return false;
870+
}
848871
case QGis::WKBMultiPoint:
872+
{
873+
//todo
874+
break;
875+
}
849876
case QGis::WKBLineString:
850877
{
851878
int* nPoints = (int*)ptr;
@@ -1127,7 +1154,8 @@ bool QgsGeometry::vertexAt(double &x, double &y,
11271154
{
11281155
return false;
11291156
}
1130-
ptr += atVertex.back()*2*sizeof(double);
1157+
ptr += atVertex.back()*(2*sizeof(double)+1+sizeof(int));
1158+
ptr += 1+sizeof(int);
11311159
memcpy(&x, ptr, sizeof(double));
11321160
ptr += sizeof(double);
11331161
memcpy(&y, ptr, sizeof(double));
@@ -1486,7 +1514,36 @@ QgsRect QgsGeometry::boundingBox() const
14861514
ymax=*y;
14871515
}
14881516
break;
1489-
1517+
case QGis::WKBMultiPoint:
1518+
{
1519+
ptr = mGeometry + 1 + sizeof(int);
1520+
nPoints = (int *) ptr;
1521+
for (idx = 0; idx < *nPoints; idx++)
1522+
{
1523+
ptr += (1+sizeof(int));
1524+
x = (double *) ptr;
1525+
ptr += sizeof(double);
1526+
y = (double *) ptr;
1527+
ptr += sizeof(double);
1528+
if (*x < xmin)
1529+
{
1530+
xmin=*x;
1531+
}
1532+
if (*x > xmax)
1533+
{
1534+
xmax=*x;
1535+
}
1536+
if (*y < ymin)
1537+
{
1538+
ymin=*y;
1539+
}
1540+
if (*y > ymax)
1541+
{
1542+
ymax=*y;
1543+
}
1544+
}
1545+
break;
1546+
}
14901547
case QGis::WKBLineString:
14911548
// get number of points in the line
14921549
ptr = mGeometry + 5;
@@ -1812,6 +1869,7 @@ bool QgsGeometry::exportToWkt(unsigned char * geom) const
18121869
ptr=geom+5+sizeof(int);
18131870
for(idx=0;idx<*nPoints;++idx)
18141871
{
1872+
ptr += (1+sizeof(int));
18151873
if(idx!=0)
18161874
{
18171875
mWkt+=", ";
@@ -2003,6 +2061,7 @@ geos::Geometry* QgsGeometry::geosGeometry() const
20032061
ptr = mGeometry + 1 + 2 * sizeof(int);
20042062
for (idx = 0; idx < *nPoints; idx++)
20052063
{
2064+
ptr += (1 + sizeof(int));
20062065
x = (double *) ptr;
20072066
ptr += sizeof(double);
20082067
y = (double *) ptr;

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,47 @@ QMessageBox::Ok);
119119
// project to layer's SRS
120120
vlayer->snapPoint(savePoint, tolerance);
121121

122-
// create geometry and attach it to feature
123-
int size=5+2*sizeof(double);
124-
unsigned char *wkb = new unsigned char[size];
125-
int wkbtype=QGis::WKBPoint;
122+
int size;
126123
char end=vlayer->endian();
124+
unsigned char *wkb;
125+
int wkbtype;
127126
double x = savePoint.x();
128127
double y = savePoint.y();
129-
memcpy(&wkb[0],&end,1);
130-
memcpy(&wkb[1],&wkbtype, sizeof(int));
131-
memcpy(&wkb[5], &x, sizeof(double));
132-
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
133-
f->setGeometryAndOwnership(&wkb[0],size);
134-
128+
129+
if(vlayer->getGeometryType() == QGis::WKBPoint)
130+
{
131+
size=1+sizeof(int)+2*sizeof(double);
132+
wkb = new unsigned char[size];
133+
wkbtype=QGis::WKBPoint;
134+
memcpy(&wkb[0],&end,1);
135+
memcpy(&wkb[1],&wkbtype, sizeof(int));
136+
memcpy(&wkb[5], &x, sizeof(double));
137+
memcpy(&wkb[5]+sizeof(double), &y, sizeof(double));
138+
}
139+
else if(vlayer->getGeometryType() == QGis::WKBMultiPoint)
140+
{
141+
size = 2+3*sizeof(int)+2*sizeof(double);
142+
wkb = new unsigned char[size];
143+
wkbtype=QGis::WKBMultiPoint;
144+
int position = 0;
145+
memcpy(&wkb[position], &end, 1);
146+
position += 1;
147+
memcpy(&wkb[position], &wkbtype, sizeof(int));
148+
position += sizeof(int);
149+
int npoint = 1;
150+
memcpy(&wkb[position], &npoint, sizeof(int));
151+
position += sizeof(int);
152+
memcpy(&wkb[position], &end, 1);
153+
position += 1;
154+
int pointtype = QGis::WKBPoint;
155+
memcpy(&wkb[position],&pointtype, sizeof(int));
156+
position += sizeof(int);
157+
memcpy(&wkb[position], &x, sizeof(double));
158+
position += sizeof(double);
159+
memcpy(&wkb[position], &y, sizeof(double));
160+
}
161+
162+
f->setGeometryAndOwnership(&wkb[0],size);
135163
// add the fields to the QgsFeature
136164
std::vector<QgsField> fields=vlayer->fields();
137165
for(std::vector<QgsField>::iterator it=fields.begin();it!=fields.end();++it)

0 commit comments

Comments
 (0)
Please sign in to comment.