46 QList<QgsVectorOverlay*>::iterator overlay_it =
mOverlays.begin();
50 for ( ; overlay_it !=
mOverlays.end(); ++overlay_it )
52 currentOverlay = *overlay_it;
53 if ( !currentOverlay )
58 QMap<int, QgsOverlayObject*>* objectMap = currentOverlay->
overlayObjects();
64 QMap<int, QgsOverlayObject*>::iterator object_it = objectMap->begin();
65 for ( ; object_it != objectMap->end(); ++object_it )
67 if (
findObjectPosition( object_it.value()->geometry()->asWkb(), currentPosition ) == 0 )
69 object_it.value()->addPosition( currentPosition );
78 int currentPosition = 0;
79 double currentX, currentY;
80 bool hasZValue =
false;
83 memcpy( &type, &( wkb[currentPosition] ),
sizeof(
int ) );
84 currentPosition +=
sizeof( int );
90 currentPosition += ( 2 *
sizeof( int ) + 1 );
93 memcpy( ¤tX, &( wkb[currentPosition] ),
sizeof(
double ) );
94 currentPosition +=
sizeof( double );
95 memcpy( ¤tY, &( wkb[currentPosition] ),
sizeof(
double ) );
96 position.
setX( currentX );
97 position.
setY( currentY );
104 memcpy( &numberOfLines, &( wkb[currentPosition] ),
sizeof(
int ) );
105 if ( numberOfLines < 1 )
109 currentPosition += ( 2 *
sizeof( int ) + 1 );
120 memcpy( &numberOfPoints, &( wkb[currentPosition] ),
sizeof(
int ) );
121 currentPosition +=
sizeof( int );
122 if ( numberOfPoints < 1 )
126 if ( numberOfPoints > 2 )
128 int midpoint = ( numberOfPoints - 1 ) / 2 ;
129 for (
int i = 0; i < midpoint; ++i )
131 currentPosition += 2 *
sizeof( double );
134 currentPosition +=
sizeof( double );
139 memcpy( &xPos, &( wkb[currentPosition] ),
sizeof(
double ) );
140 currentPosition +=
sizeof( double );
141 memcpy( &yPos, &( wkb[currentPosition] ),
sizeof(
double ) );
142 position.
setX( xPos );
143 position.
setY( yPos );
150 int numberOfPolygons;
151 memcpy( &numberOfPolygons, &( wkb[currentPosition] ),
sizeof(
int ) );
152 if ( numberOfPolygons < 1 )
156 currentPosition +=
sizeof( int );
157 currentPosition += ( 1 +
sizeof( int ) );
169 memcpy( &numberOfRings, &( wkb[currentPosition] ),
sizeof(
int ) );
170 if ( numberOfRings < 1 )
174 currentPosition +=
sizeof( int );
178 memcpy( &numberOfPoints, &( wkb[currentPosition] ),
sizeof(
int ) );
179 if ( numberOfPoints < 1 )
183 currentPosition +=
sizeof( int );
185 double *x =
new double[numberOfPoints];
186 double *y =
new double[numberOfPoints];
188 for (
int i = 0; i < numberOfPoints; ++i )
190 memcpy( &( x[i] ), &( wkb[currentPosition] ),
sizeof(
double ) );
191 currentPosition +=
sizeof( double );
192 memcpy( &( y[i] ), &( wkb[currentPosition] ),
sizeof(
double ) );
193 currentPosition +=
sizeof( double );
196 currentPosition +=
sizeof( double );
199 double centroidX, centroidY;
210 position.
setX( centroidX );
211 position.
setY( centroidY );
224 double ai, atmp = 0, xtmp = 0, ytmp = 0;
225 if ( numberOfPoints < 3 )
230 for ( i = numberOfPoints - 1, j = 0; j < numberOfPoints; i = j, j++ )
232 ai = x[i] * y[j] - x[j] * y[i];
234 xtmp += ( x[j] + x[i] ) * ai;
235 ytmp += ( y[j] + y[i] ) * ai;
241 centroidX = xtmp / ( 3 * atmp );
242 centroidY = ytmp / ( 3 * atmp );