Skip to content

Commit 712ef50

Browse files
author
mhugent
committed
Also added code to convert geos multipoint to wkb multipoint
git-svn-id: http://svn.osgeo.org/qgis/trunk@8042 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c39d6a9 commit 712ef50

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/core/qgsgeometry.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4122,8 +4122,56 @@ bool QgsGeometry::exportGeosToWkb()
41224122

41234123
case GEOS_GEOM::GEOS_MULTIPOINT: // a collection of points
41244124
{
4125-
// TODO
4126-
break;
4125+
GEOS_GEOM::MultiPoint* theMultiPoint = dynamic_cast<GEOS_GEOM::MultiPoint*>(mGeos);
4126+
if(!theMultiPoint)
4127+
{
4128+
return false;
4129+
}
4130+
4131+
//find out size of geometry
4132+
int geometrySize = 1 + 2 * sizeof(int);
4133+
for(GEOS_SIZE_T i = 0; i < theMultiPoint->getNumGeometries(); ++i)
4134+
{
4135+
geometrySize += (1 + 2 * sizeof(int) + 2 * sizeof(double));
4136+
}
4137+
4138+
mGeometry = new unsigned char[geometrySize];
4139+
mGeometrySize = geometrySize;
4140+
int wkbPosition = 0; //current position in the byte array
4141+
4142+
memcpy(mGeometry, &byteOrder, 1);
4143+
wkbPosition += 1;
4144+
int wkbtype=QGis::WKBMultiPoint;
4145+
memcpy(&mGeometry[wkbPosition],&wkbtype, sizeof(int));
4146+
wkbPosition += sizeof(int);
4147+
int numPoints = theMultiPoint->getNumGeometries();
4148+
memcpy(&mGeometry[wkbPosition], &numPoints, sizeof(int));
4149+
wkbPosition += sizeof(int);
4150+
4151+
int pointType = QGis::WKBPoint;
4152+
double x, y;
4153+
GEOS_GEOM::Point* currentPoint = 0;
4154+
4155+
for(GEOS_SIZE_T i = 0; i < theMultiPoint->getNumGeometries(); ++i)
4156+
{
4157+
//copy endian and point type
4158+
memcpy(&mGeometry[wkbPosition], &byteOrder, 1);
4159+
wkbPosition += 1;
4160+
memcpy(&mGeometry[wkbPosition], &pointType, sizeof(int));
4161+
wkbPosition += sizeof(int);
4162+
4163+
currentPoint = (GEOS_GEOM::Point*)(theMultiPoint->getGeometryN(i));
4164+
//x
4165+
x = currentPoint->getX();
4166+
memcpy(&mGeometry[wkbPosition], &x, sizeof(double));
4167+
wkbPosition += sizeof(double);
4168+
//y
4169+
y = currentPoint->getY();
4170+
memcpy(&mGeometry[wkbPosition], &y, sizeof(double));
4171+
wkbPosition += sizeof(double);
4172+
}
4173+
mDirtyWkb = FALSE;
4174+
return true;
41274175
} // case GEOS_GEOM::GEOS_MULTIPOINT
41284176

41294177
case GEOS_GEOM::GEOS_MULTILINESTRING: // a collection of linestrings

0 commit comments

Comments
 (0)