33 #define DEFAULT_QUADRANT_SEGMENTS 8
35 #define CATCH_GEOS(r) \
36 catch (GEOSException &e) \
39 QgsDebugMsg("GEOS: " + QString( e.what() ) ); \
48 if ( theMsg ==
"Unknown exception thrown" &&
lastMsg.isNull() )
89 vsnprintf( buffer,
sizeof buffer, fmt, ap );
92 QgsDebugMsg( QString(
"GEOS exception encountered: %1" ).arg( buffer ) );
99 #if defined(QGISDEBUG)
104 vsnprintf( buffer,
sizeof buffer, fmt, ap );
107 QgsDebugMsg( QString(
"GEOS notice: %1" ).arg( QString::fromUtf8( buffer ) ) );
128 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
129 #define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
130 #define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
131 #define GEOSGetNumInteriorRings(g) GEOSGetNumInteriorRings( (GEOSGeometry *)g )
132 #define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i )
133 #define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 )
134 #define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 )
135 #define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s )
136 #define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a )
137 #define GEOSSimplify(g, t) GEOSSimplify( (GEOSGeometry*) g, t )
138 #define GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g )
140 #define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
141 #define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
142 #define GEOSCoordSeq_getY(cs,i,y) GEOSCoordSeq_getY( (GEOSCoordSequence *)cs, i, y )
146 static GEOSGeometry *cloneGeosGeom(
const GEOSGeometry *geom )
150 int type = GEOSGeomTypeId(( GEOSGeometry * ) geom );
152 if ( type == GEOS_MULTIPOINT || type == GEOS_MULTILINESTRING || type == GEOS_MULTIPOLYGON )
154 QVector<GEOSGeometry *> geoms;
159 for (
int i = 0; i < GEOSGetNumGeometries(( GEOSGeometry * )geom ); ++i )
160 geoms << GEOSGeom_clone(( GEOSGeometry * ) GEOSGetGeometryN(( GEOSGeometry * ) geom, i ) );
167 for (
int i = 0; i < geoms.count(); i++ )
168 GEOSGeom_destroy( geoms[i] );
175 return GEOSGeom_clone(( GEOSGeometry * ) geom );
179 #define GEOSGeom_clone(g) cloneGeosGeom(g)
193 mGeometrySize( rhs.mGeometrySize ),
194 mDirtyWkb( rhs.mDirtyWkb ),
195 mDirtyGeos( rhs.mDirtyGeos )
224 GEOSGeom_destroy(
mGeos );
231 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom );
232 GEOSCoordSeq_getSize( cs, &n );
238 GEOSCoordSequence *coord = GEOSCoordSeq_create( 1, 2 );
239 GEOSCoordSeq_setX( coord, 0, point.
x() );
240 GEOSCoordSeq_setY( coord, 0, point.
y() );
241 return GEOSGeom_createPoint( coord );
246 GEOSCoordSequence *coord = 0;
250 coord = GEOSCoordSeq_create( points.count(), 2 );
252 for ( i = 0; i < points.count(); i++ )
254 GEOSCoordSeq_setX( coord, i, points[i].x() );
255 GEOSCoordSeq_setY( coord, i, points[i].y() );
270 GEOSGeometry **geomarr =
new GEOSGeometry*[ geoms.size()];
274 for (
int i = 0; i < geoms.size(); i++ )
275 geomarr[i] = geoms[i];
277 GEOSGeometry *geom = 0;
281 geom = GEOSGeom_createCollection( typeId, geomarr, geoms.size() );
295 GEOSCoordSequence *coord = 0;
300 return GEOSGeom_createLineString( coord );
314 GEOSCoordSequence *coord = 0;
316 if ( polyline.count() == 0 )
321 if ( polyline[0] != polyline[polyline.size()-1] )
333 return GEOSGeom_createLinearRing( coord );
347 GEOSGeometry *shell = rings[0];
348 GEOSGeometry **holes = NULL;
350 if ( rings.size() > 1 )
352 holes =
new GEOSGeometry*[ rings.size()-1 ];
356 for (
int i = 0; i < rings.size() - 1; i++ )
357 holes[i] = rings[i+1];
360 GEOSGeometry *geom = GEOSGeom_createPolygon( shell, holes, rings.size() - 1 );
375 if ( polygon.count() == 0 )
378 QVector<GEOSGeometry *> geoms;
382 for (
int i = 0; i < polygon.count(); i++ )
390 for (
int i = 0; i < geoms.count(); i++ )
391 GEOSGeom_destroy( geoms[i] );
410 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR>=3)
411 GEOSWKTReader *reader = GEOSWKTReader_create();
413 GEOSWKTReader_destroy( reader );
416 return fromGeosGeom( GEOSGeomFromWKT( wkt.toLocal8Bit().data() ) );
443 QVector<GEOSGeometry *> geoms;
447 for (
int i = 0; i < multipoint.size(); ++i )
457 for (
int i = 0; i < geoms.size(); ++i )
458 GEOSGeom_destroy( geoms[i] );
466 QVector<GEOSGeometry *> geoms;
470 for (
int i = 0; i < multiline.count(); i++ )
478 for (
int i = 0; i < geoms.count(); i++ )
479 GEOSGeom_destroy( geoms[i] );
487 if ( multipoly.count() == 0 )
490 QVector<GEOSGeometry *> geoms;
494 for (
int i = 0; i < multipoly.count(); i++ )
502 for (
int i = 0; i < geoms.count(); i++ )
503 GEOSGeom_destroy( geoms[i] );
519 polygon.append( ring );
541 GEOSGeom_destroy(
mGeos );
567 GEOSGeom_destroy(
mGeos );
614 unsigned char *geom =
asWkb();
618 memcpy( &wkbType, ( geom + 1 ),
sizeof( wkbType ) );
677 GEOSGeom_destroy(
mGeos );
707 int vertexcounter = 0;
712 double *tempx, *tempy;
713 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
716 bool hasZValue =
false;
724 y = *((
double * )(
mGeometry + 5 +
sizeof(
double ) ) );
725 actdist = point.
sqrDist( x, y );
737 int* npoints = (
int* )ptr;
738 ptr +=
sizeof( int );
739 for (
int index = 0; index < *npoints; ++index )
741 tempx = (
double* )ptr;
742 ptr +=
sizeof( double );
743 tempy = (
double* )ptr;
744 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
748 actdist = point.
sqrDist( *tempx, *tempy );
756 beforeVertex = index - 1;
758 if ( index == ( *npoints - 1 ) )
764 afterVertex = index + 1;
767 ptr +=
sizeof( double );
770 ptr +=
sizeof( double );
782 for (
int index = 0; index < *nrings; ++index )
784 npoints = (
int* )ptr;
785 ptr +=
sizeof( int );
786 for (
int index2 = 0; index2 < *npoints; ++index2 )
788 tempx = (
double* )ptr;
789 ptr +=
sizeof( double );
790 tempy = (
double* )ptr;
791 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
795 actdist = point.
sqrDist( *tempx, *tempy );
796 vertexnr = vertexcounter;
800 beforeVertex = vertexcounter + ( *npoints - 2 );
801 afterVertex = vertexcounter + 1;
803 else if ( index2 == ( *npoints - 1 ) )
805 beforeVertex = vertexcounter - 1;
806 afterVertex = vertexcounter - ( *npoints - 2 );
810 beforeVertex = vertexcounter - 1;
811 afterVertex = vertexcounter + 1;
814 ptr +=
sizeof( double );
817 ptr +=
sizeof( double );
829 int* npoints = (
int* )ptr;
830 ptr +=
sizeof( int );
831 for (
int index = 0; index < *npoints; ++index )
833 ptr += ( 1 +
sizeof( int ) );
834 tempx = (
double* )ptr;
835 tempy = (
double* )( ptr +
sizeof(
double ) );
836 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
840 actdist = point.
sqrDist( *tempx, *tempy );
843 ptr += ( 2 *
sizeof( double ) );
846 ptr +=
sizeof( double );
856 int* nlines = (
int* )ptr;
858 ptr +=
sizeof( int );
859 for (
int index = 0; index < *nlines; ++index )
861 ptr += (
sizeof( int ) + 1 );
862 npoints = (
int* )ptr;
863 ptr +=
sizeof( int );
864 for (
int index2 = 0; index2 < *npoints; ++index2 )
866 tempx = (
double* )ptr;
867 ptr +=
sizeof( double );
868 tempy = (
double* )ptr;
869 ptr +=
sizeof( double );
870 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
874 actdist = point.
sqrDist( *tempx, *tempy );
875 vertexnr = vertexcounter;
883 beforeVertex = vertexnr - 1;
885 if ( index2 == ( *npoints ) - 1 )
891 afterVertex = vertexnr + 1;
896 ptr +=
sizeof( double );
908 int* npolys = (
int* )ptr;
911 ptr +=
sizeof( int );
912 for (
int index = 0; index < *npolys; ++index )
914 ptr += ( 1 +
sizeof( int ) );
915 nrings = (
int* )ptr;
916 ptr +=
sizeof( int );
917 for (
int index2 = 0; index2 < *nrings; ++index2 )
919 npoints = (
int* )ptr;
920 ptr +=
sizeof( int );
921 for (
int index3 = 0; index3 < *npoints; ++index3 )
923 tempx = (
double* )ptr;
924 ptr +=
sizeof( double );
925 tempy = (
double* )ptr;
926 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
930 actdist = point.
sqrDist( *tempx, *tempy );
931 vertexnr = vertexcounter;
936 beforeVertex = vertexcounter + ( *npoints - 2 );
937 afterVertex = vertexcounter + 1;
939 else if ( index3 == ( *npoints - 1 ) )
941 beforeVertex = vertexcounter - 1;
942 afterVertex = vertexcounter - ( *npoints - 2 );
946 beforeVertex = vertexcounter - 1;
947 afterVertex = vertexcounter + 1;
950 ptr +=
sizeof( double );
953 ptr +=
sizeof( double );
987 int vertexcounter = 0;
990 bool hasZValue =
false;
992 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
1005 int* npoints = (
int* ) ptr;
1007 const int index = atVertex;
1017 beforeVertex = index - 1;
1020 if ( index == ( *npoints - 1 ) )
1026 afterVertex = index + 1;
1035 int* nrings = (
int* )(
mGeometry + 5 );
1041 for (
int index0 = 0; index0 < *nrings; ++index0 )
1043 npoints = (
int* )ptr;
1044 ptr +=
sizeof( int );
1046 for (
int index1 = 0; index1 < *npoints; ++index1 )
1048 ptr +=
sizeof( double );
1049 ptr +=
sizeof( double );
1052 ptr +=
sizeof( double );
1054 if ( vertexcounter == atVertex )
1058 beforeVertex = vertexcounter + ( *npoints - 2 );
1059 afterVertex = vertexcounter + 1;
1061 else if ( index1 == ( *npoints - 1 ) )
1063 beforeVertex = vertexcounter - 1;
1064 afterVertex = vertexcounter - ( *npoints - 2 );
1068 beforeVertex = vertexcounter - 1;
1069 afterVertex = vertexcounter + 1;
1090 int* nlines = (
int* )ptr;
1092 ptr +=
sizeof( int );
1094 for (
int index0 = 0; index0 < *nlines; ++index0 )
1096 ptr += (
sizeof( int ) + 1 );
1097 npoints = (
int* )ptr;
1098 ptr +=
sizeof( int );
1100 for (
int index1 = 0; index1 < *npoints; ++index1 )
1102 ptr +=
sizeof( double );
1103 ptr +=
sizeof( double );
1106 ptr +=
sizeof( double );
1109 if ( vertexcounter == atVertex )
1118 beforeVertex = vertexcounter - 1;
1120 if ( index1 == ( *npoints ) - 1 )
1126 afterVertex = vertexcounter + 1;
1139 int* npolys = (
int* )ptr;
1142 ptr +=
sizeof( int );
1144 for (
int index0 = 0; index0 < *npolys; ++index0 )
1146 ptr += ( 1 +
sizeof( int ) );
1147 nrings = (
int* )ptr;
1148 ptr +=
sizeof( int );
1150 for (
int index1 = 0; index1 < *nrings; ++index1 )
1152 npoints = (
int* )ptr;
1153 ptr +=
sizeof( int );
1155 for (
int index2 = 0; index2 < *npoints; ++index2 )
1157 ptr +=
sizeof( double );
1158 ptr +=
sizeof( double );
1161 ptr +=
sizeof( double );
1163 if ( vertexcounter == atVertex )
1170 beforeVertex = vertexcounter + ( *npoints - 2 );
1171 afterVertex = vertexcounter + 1;
1173 else if ( index2 == ( *npoints - 1 ) )
1175 beforeVertex = vertexcounter - 1;
1176 afterVertex = vertexcounter - ( *npoints - 2 );
1180 beforeVertex = vertexcounter - 1;
1181 afterVertex = vertexcounter + 1;
1201 const GEOSCoordSequence* old_sequence,
1202 GEOSCoordSequence** new_sequence )
1206 if ( beforeVertex < 0 )
1212 unsigned int numPoints;
1213 GEOSCoordSeq_getSize( old_sequence, &numPoints );
1215 *new_sequence = GEOSCoordSeq_create( numPoints + 1, 2 );
1216 if ( !*new_sequence )
1219 bool inserted =
false;
1220 for (
unsigned int i = 0, j = 0; i < numPoints; i++, j++ )
1223 if ( beforeVertex == static_cast<int>( i ) )
1225 GEOSCoordSeq_setX( *new_sequence, j, x );
1226 GEOSCoordSeq_setY( *new_sequence, j, y );
1232 GEOSCoordSeq_getX( old_sequence, i, &aX );
1233 GEOSCoordSeq_getY( old_sequence, i, &aY );
1235 GEOSCoordSeq_setX( *new_sequence, j, aX );
1236 GEOSCoordSeq_setY( *new_sequence, j, aY );
1243 GEOSCoordSeq_setX( *new_sequence, numPoints, x );
1244 GEOSCoordSeq_setY( *new_sequence, numPoints, y );
1253 int vertexnr = atVertex;
1268 bool hasZValue =
false;
1270 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1278 if ( vertexnr == 0 )
1280 memcpy( ptr, &x,
sizeof(
double ) );
1281 ptr +=
sizeof( double );
1282 memcpy( ptr, &y,
sizeof(
double ) );
1295 int* nrPoints = (
int* )ptr;
1296 if ( vertexnr > *nrPoints || vertexnr < 0 )
1300 ptr +=
sizeof( int );
1303 ptr += ( 3 *
sizeof( double ) + 1 +
sizeof(
int ) ) * vertexnr;
1307 ptr += ( 2 *
sizeof( double ) + 1 +
sizeof(
int ) ) * vertexnr;
1309 ptr += ( 1 +
sizeof( int ) );
1310 memcpy( ptr, &x,
sizeof(
double ) );
1311 ptr +=
sizeof( double );
1312 memcpy( ptr, &y,
sizeof(
double ) );
1320 int* nrPoints = (
int* )ptr;
1321 if ( vertexnr > *nrPoints || vertexnr < 0 )
1325 ptr +=
sizeof( int );
1326 ptr += 2 *
sizeof( double ) * vertexnr;
1329 ptr +=
sizeof( double ) * vertexnr;
1331 memcpy( ptr, &x,
sizeof(
double ) );
1332 ptr +=
sizeof( double );
1333 memcpy( ptr, &y,
sizeof(
double ) );
1341 int* nrLines = (
int* )ptr;
1342 ptr +=
sizeof( int );
1345 for (
int linenr = 0; linenr < *nrLines; ++linenr )
1347 ptr +=
sizeof( int ) + 1;
1348 nrPoints = (
int* )ptr;
1349 ptr +=
sizeof( int );
1350 if ( vertexnr >= pointindex && vertexnr < pointindex + ( *nrPoints ) )
1352 ptr += ( vertexnr - pointindex ) * 2 *
sizeof(
double );
1355 ptr += ( vertexnr - pointindex ) *
sizeof(
double );
1357 memcpy( ptr, &x,
sizeof(
double ) );
1358 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1362 pointindex += ( *nrPoints );
1363 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1366 ptr +=
sizeof( double ) * ( *nrPoints );
1375 int* nrRings = (
int* )ptr;
1376 ptr +=
sizeof( int );
1380 for (
int ringnr = 0; ringnr < *nrRings; ++ringnr )
1382 nrPoints = (
int* )ptr;
1383 ptr +=
sizeof( int );
1384 if ( vertexnr == pointindex || vertexnr == pointindex + ( *nrPoints - 1 ) )
1386 memcpy( ptr, &x,
sizeof(
double ) );
1387 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1390 memcpy( ptr + 3*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1394 memcpy( ptr + 2*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1398 memcpy( ptr +
sizeof(
double ) + 3*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1402 memcpy( ptr +
sizeof(
double ) + 2*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1407 else if ( vertexnr > pointindex && vertexnr < pointindex + ( *nrPoints - 1 ) )
1409 ptr += 2 *
sizeof( double ) * ( vertexnr - pointindex );
1412 ptr +=
sizeof( double ) * ( vertexnr - pointindex );
1414 memcpy( ptr, &x,
sizeof(
double ) );
1415 ptr +=
sizeof( double );
1416 memcpy( ptr, &y,
sizeof(
double ) );
1420 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1423 ptr +=
sizeof( double ) * ( *nrPoints );
1425 pointindex += *nrPoints;
1433 int* nrPolygons = (
int* )ptr;
1434 ptr +=
sizeof( int );
1439 for (
int polynr = 0; polynr < *nrPolygons; ++polynr )
1441 ptr += ( 1 +
sizeof( int ) );
1442 nrRings = (
int* )ptr;
1443 ptr +=
sizeof( int );
1444 for (
int ringnr = 0; ringnr < *nrRings; ++ringnr )
1446 nrPoints = (
int* )ptr;
1447 ptr +=
sizeof( int );
1448 if ( vertexnr == pointindex || vertexnr == pointindex + ( *nrPoints - 1 ) )
1450 memcpy( ptr, &x,
sizeof(
double ) );
1451 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1454 memcpy( ptr + 3*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1458 memcpy( ptr + 2*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1462 memcpy( ptr +
sizeof(
double ) + 3*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1466 memcpy( ptr +
sizeof(
double ) + 2*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1471 else if ( vertexnr > pointindex && vertexnr < pointindex + ( *nrPoints - 1 ) )
1473 ptr += 2 *
sizeof( double ) * ( vertexnr - pointindex );
1476 ptr +=
sizeof( double ) * ( vertexnr - pointindex );
1478 memcpy( ptr, &x,
sizeof(
double ) );
1479 ptr +=
sizeof( double );
1480 memcpy( ptr, &y,
sizeof(
double ) );
1484 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1487 ptr +=
sizeof( double ) * ( *nrPoints );
1489 pointindex += *nrPoints;
1502 int vertexnr = atVertex;
1503 bool success =
false;
1518 unsigned char* newbuffer;
1521 bool hasZValue =
false;
1523 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1533 newbuffer =
new unsigned char[
mGeometrySize-3*
sizeof( double )];
1536 newbuffer =
new unsigned char[
mGeometrySize-2*
sizeof( double )];
1539 memcpy( newbuffer,
mGeometry, 1 +
sizeof(
int ) );
1542 unsigned char* newBufferPtr = newbuffer + 1 +
sizeof( int );
1562 int* nPoints = (
int* )ptr;
1563 if (( *nPoints ) < 3 || vertexnr > ( *nPoints ) - 1 || vertexnr < 0 )
1568 int newNPoints = ( *nPoints ) - 1;
1569 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1570 ptr +=
sizeof( int );
1571 newBufferPtr +=
sizeof( int );
1572 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1574 if ( vertexnr != pointindex )
1576 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1577 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1578 newBufferPtr += 2 *
sizeof( double );
1581 newBufferPtr +=
sizeof( double );
1588 ptr += 2 *
sizeof( double );
1591 ptr +=
sizeof( double );
1601 int* nLines = (
int* )ptr;
1602 memcpy( newBufferPtr, nLines,
sizeof(
int ) );
1603 newBufferPtr +=
sizeof( int );
1604 ptr +=
sizeof( int );
1607 for (
int linenr = 0; linenr < *nLines; ++linenr )
1609 memcpy( newBufferPtr, ptr,
sizeof(
int ) + 1 );
1610 ptr += (
sizeof( int ) + 1 );
1611 newBufferPtr += (
sizeof( int ) + 1 );
1612 nPoints = (
int* )ptr;
1613 ptr +=
sizeof( int );
1617 if ( vertexnr >= pointindex && vertexnr < pointindex + ( *nPoints ) )
1624 newNPoint = ( *nPoints ) - 1;
1628 newNPoint = *nPoints;
1630 memcpy( newBufferPtr, &newNPoint,
sizeof(
int ) );
1631 newBufferPtr +=
sizeof( int );
1633 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1635 if ( vertexnr != pointindex )
1637 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1638 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1639 newBufferPtr += 2 *
sizeof( double );
1642 newBufferPtr +=
sizeof( double );
1649 ptr += 2 *
sizeof( double );
1652 ptr +=
sizeof( double );
1663 int* nRings = (
int* )ptr;
1664 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
1665 ptr +=
sizeof( int );
1666 newBufferPtr +=
sizeof( int );
1670 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
1672 nPoints = (
int* )ptr;
1673 ptr +=
sizeof( int );
1675 if ( vertexnr >= pointindex && vertexnr < pointindex + *nPoints )
1682 newNPoints = *nPoints - 1;
1686 newNPoints = *nPoints;
1688 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1689 newBufferPtr +=
sizeof( int );
1691 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1693 if ( vertexnr != pointindex )
1695 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1696 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1697 newBufferPtr += 2 *
sizeof( double );
1700 newBufferPtr +=
sizeof( double );
1707 memcpy( ptr + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 2*
sizeof(
double ),
sizeof(
double ) );
1708 memcpy( ptr +
sizeof(
double ) + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 3*
sizeof(
double ),
sizeof(
double ) );
1710 if ( pointnr == ( *nPoints ) - 1 )
1712 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ), ptr - 2*
sizeof(
double ),
sizeof(
double ) );
1713 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ) +
sizeof(
double ), ptr -
sizeof(
double ),
sizeof(
double ) );
1717 ptr += 2 *
sizeof( double );
1720 ptr +=
sizeof( double );
1731 int* nPolys = (
int* )ptr;
1732 memcpy( newBufferPtr, nPolys,
sizeof(
int ) );
1733 newBufferPtr +=
sizeof( int );
1734 ptr +=
sizeof( int );
1739 for (
int polynr = 0; polynr < *nPolys; ++polynr )
1741 memcpy( newBufferPtr, ptr, ( 1 +
sizeof(
int ) ) );
1742 ptr += ( 1 +
sizeof( int ) );
1743 newBufferPtr += ( 1 +
sizeof( int ) );
1744 nRings = (
int* )ptr;
1745 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
1746 newBufferPtr +=
sizeof( int );
1747 ptr +=
sizeof( int );
1748 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
1750 nPoints = (
int* )ptr;
1751 ptr +=
sizeof( int );
1753 if ( vertexnr >= pointindex && vertexnr < pointindex + *nPoints )
1760 newNPoints = *nPoints - 1;
1764 newNPoints = *nPoints;
1766 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1767 newBufferPtr +=
sizeof( int );
1769 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1771 if ( vertexnr != pointindex )
1773 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1774 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1775 newBufferPtr += 2 *
sizeof( double );
1778 newBufferPtr +=
sizeof( double );
1785 memcpy( ptr + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 2*
sizeof(
double ),
sizeof(
double ) );
1786 memcpy( ptr +
sizeof(
double ) + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 3*
sizeof(
double ),
sizeof(
double ) );
1788 if ( pointnr == ( *nPoints ) - 1 )
1790 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ), ptr - 2*
sizeof(
double ),
sizeof(
double ) );
1791 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ) +
sizeof(
double ), ptr -
sizeof(
double ),
sizeof(
double ) );
1795 ptr += 2 *
sizeof( double );
1798 ptr +=
sizeof( double );
1831 int vertexnr = beforeVertex;
1832 bool success =
false;
1847 unsigned char* newbuffer;
1851 bool hasZValue =
false;
1854 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1864 newbuffer =
new unsigned char[
mGeometrySize+3*
sizeof( double )];
1867 newbuffer =
new unsigned char[
mGeometrySize+2*
sizeof( double )];
1869 memcpy( newbuffer,
mGeometry, 1 +
sizeof(
int ) );
1872 unsigned char* newBufferPtr = newbuffer + 1 +
sizeof( int );
1893 int* nPoints = (
int* )ptr;
1894 if ( vertexnr > *nPoints || vertexnr < 0 )
1898 int newNPoints = ( *nPoints ) + 1;
1899 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1900 newBufferPtr +=
sizeof( int );
1901 ptr +=
sizeof( int );
1903 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1905 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1906 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1907 ptr += 2 *
sizeof( double );
1910 ptr +=
sizeof( double );
1912 newBufferPtr += 2 *
sizeof( double );
1915 newBufferPtr +=
sizeof( double );
1918 if ( pointindex == vertexnr )
1920 memcpy( newBufferPtr, &x,
sizeof(
double ) );
1921 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
1922 newBufferPtr += 2 *
sizeof( double );
1925 newBufferPtr +=
sizeof( double );
1936 int* nLines = (
int* )ptr;
1938 ptr +=
sizeof( int );
1939 memcpy( newBufferPtr, nLines,
sizeof(
int ) );
1940 newBufferPtr +=
sizeof( int );
1943 for (
int linenr = 0; linenr < *nLines; ++linenr )
1945 memcpy( newBufferPtr, ptr,
sizeof(
int ) + 1 );
1946 ptr += (
sizeof( int ) + 1 );
1947 newBufferPtr += (
sizeof( int ) + 1 );
1948 nPoints = (
int* )ptr;
1950 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
1952 newNPoints = ( *nPoints ) + 1;
1956 newNPoints = *nPoints;
1958 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
1959 newBufferPtr +=
sizeof( int );
1960 ptr +=
sizeof( int );
1962 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1964 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1965 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1966 ptr += 2 *
sizeof( double );
1967 newBufferPtr += 2 *
sizeof( double );
1970 ptr +=
sizeof( double );
1971 newBufferPtr +=
sizeof( double );
1974 if ( pointindex == vertexnr )
1976 memcpy( newBufferPtr, &x,
sizeof(
double ) );
1977 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
1978 newBufferPtr += 2 *
sizeof( double );
1981 newBufferPtr +=
sizeof( double );
1993 int* nRings = (
int* )ptr;
1995 ptr +=
sizeof( int );
1996 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
1997 newBufferPtr +=
sizeof( int );
2000 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2002 nPoints = (
int* )ptr;
2004 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
2006 newNPoints = ( *nPoints ) + 1;
2010 newNPoints = *nPoints;
2012 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
2013 newBufferPtr +=
sizeof( int );
2014 ptr +=
sizeof( int );
2016 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2018 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
2019 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
2020 ptr += 2 *
sizeof( double );
2021 newBufferPtr += 2 *
sizeof( double );
2024 ptr +=
sizeof( double );
2025 newBufferPtr +=
sizeof( double );
2028 if ( pointindex == vertexnr )
2030 memcpy( newBufferPtr, &x,
sizeof(
double ) );
2031 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
2032 newBufferPtr += 2 *
sizeof( double );
2035 newBufferPtr +=
sizeof( double );
2047 int* nPolys = (
int* )ptr;
2050 memcpy( newBufferPtr, nPolys,
sizeof(
int ) );
2051 ptr +=
sizeof( int );
2052 newBufferPtr +=
sizeof( int );
2055 for (
int polynr = 0; polynr < *nPolys; ++polynr )
2057 memcpy( newBufferPtr, ptr, ( 1 +
sizeof(
int ) ) );
2058 ptr += ( 1 +
sizeof( int ) );
2059 newBufferPtr += ( 1 +
sizeof( int ) );
2060 nRings = (
int* )ptr;
2061 ptr +=
sizeof( int );
2062 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
2063 newBufferPtr +=
sizeof( int );
2065 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2067 nPoints = (
int* )ptr;
2069 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
2071 newNPoints = ( *nPoints ) + 1;
2075 newNPoints = *nPoints;
2077 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
2078 newBufferPtr +=
sizeof( int );
2079 ptr +=
sizeof( int );
2081 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2083 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
2084 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
2085 ptr += 2 *
sizeof( double );
2086 newBufferPtr += 2 *
sizeof( double );
2089 ptr +=
sizeof( double );
2090 newBufferPtr +=
sizeof( double );
2093 if ( pointindex == vertexnr )
2095 memcpy( newBufferPtr, &x,
sizeof(
double ) );
2096 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
2097 newBufferPtr += 2 *
sizeof( double );
2100 newBufferPtr +=
sizeof( double );
2150 bool hasZValue =
false;
2153 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
2159 if ( atVertex == 0 )
2162 memcpy( &x, ptr,
sizeof(
double ) );
2163 ptr +=
sizeof( double );
2164 memcpy( &y, ptr,
sizeof(
double ) );
2179 nPoints = (
int * ) ptr;
2182 if ( 0 > atVertex || *nPoints <= atVertex )
2190 ptr =
mGeometry + 9 + ( atVertex * 3 *
sizeof( double ) );
2194 ptr =
mGeometry + 9 + ( atVertex * 2 *
sizeof( double ) );
2196 memcpy( &x, ptr,
sizeof(
double ) );
2197 ptr +=
sizeof( double );
2198 memcpy( &y, ptr,
sizeof(
double ) );
2208 nRings = (
int* )ptr;
2209 ptr +=
sizeof( int );
2211 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2213 nPoints = (
int* )ptr;
2214 ptr +=
sizeof( int );
2215 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2217 if ( pointindex == atVertex )
2219 memcpy( &x, ptr,
sizeof(
double ) );
2220 ptr +=
sizeof( double );
2221 memcpy( &y, ptr,
sizeof(
double ) );
2224 ptr += 2 *
sizeof( double );
2227 ptr +=
sizeof( double );
2239 int* nPoints = (
int* )ptr;
2240 if ( atVertex < 0 || atVertex >= *nPoints )
2246 ptr += atVertex * ( 3 *
sizeof( double ) + 1 +
sizeof(
int ) );
2250 ptr += atVertex * ( 2 *
sizeof( double ) + 1 +
sizeof(
int ) );
2252 ptr += 1 +
sizeof( int );
2253 memcpy( &x, ptr,
sizeof(
double ) );
2254 ptr +=
sizeof( double );
2255 memcpy( &y, ptr,
sizeof(
double ) );
2263 int* nLines = (
int* )ptr;
2266 ptr +=
sizeof( int );
2267 for (
int linenr = 0; linenr < *nLines; ++linenr )
2269 ptr +=
sizeof( int ) + 1;
2270 nPoints = (
int* )ptr;
2271 ptr +=
sizeof( int );
2272 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2274 if ( pointindex == atVertex )
2276 memcpy( &x, ptr,
sizeof(
double ) );
2277 ptr +=
sizeof( double );
2278 memcpy( &y, ptr,
sizeof(
double ) );
2281 ptr += 2 *
sizeof( double );
2284 ptr +=
sizeof( double );
2299 int* nPolygons = (
int* )ptr;
2300 ptr +=
sizeof( int );
2301 for (
int polynr = 0; polynr < *nPolygons; ++polynr )
2303 ptr += ( 1 +
sizeof( int ) );
2304 nRings = (
int* )ptr;
2305 ptr +=
sizeof( int );
2306 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2308 nPoints = (
int* )ptr;
2309 ptr +=
sizeof( int );
2310 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2312 if ( pointindex == atVertex )
2314 memcpy( &x, ptr,
sizeof(
double ) );
2315 ptr +=
sizeof( double );
2316 memcpy( &y, ptr,
sizeof(
double ) );
2320 ptr += 2 *
sizeof( double );
2323 ptr +=
sizeof( double );
2331 QgsDebugMsg(
"error: mGeometry type not recognized" );
2347 QgsDebugMsg(
"Exiting with std::numeric_limits<double>::max()." );
2361 int closestVertexIndex = 0;
2367 const GEOSGeometry *g = GEOSGetExteriorRing(
mGeos );
2371 const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g );
2374 GEOSCoordSeq_getSize( sequence, &n );
2376 for (
unsigned int i = 0; i < n; i++ )
2379 GEOSCoordSeq_getX( sequence, i, &x );
2380 GEOSCoordSeq_getY( sequence, i, &y );
2382 double testDist = point.
sqrDist( x, y );
2383 if ( testDist < sqrDist )
2385 closestVertexIndex = i;
2390 atVertex = closestVertexIndex;
2410 bool hasZValue =
false;
2411 double *thisx = NULL;
2412 double *thisy = NULL;
2413 double *prevx = NULL;
2414 double *prevy = NULL;
2416 int closestSegmentIndex = 0;
2433 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
2449 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2450 int* npoints = (
int* ) ptr;
2451 ptr +=
sizeof( int );
2452 for (
int index = 0; index < *npoints; ++index )
2459 thisx = (
double* ) ptr;
2460 ptr +=
sizeof( double );
2461 thisy = (
double* ) ptr;
2465 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint ) ) < sqrDist )
2467 closestSegmentIndex = index;
2469 minDistPoint = distPoint;
2472 ptr +=
sizeof( double );
2475 ptr +=
sizeof( double );
2478 beforeVertex = closestSegmentIndex;
2485 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2486 int* nLines = (
int* )ptr;
2487 ptr +=
sizeof( int );
2490 for (
int linenr = 0; linenr < *nLines; ++linenr )
2492 ptr +=
sizeof( int ) + 1;
2493 nPoints = (
int* )ptr;
2494 ptr +=
sizeof( int );
2497 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2499 thisx = (
double* ) ptr;
2500 ptr +=
sizeof( double );
2501 thisy = (
double* ) ptr;
2502 ptr +=
sizeof( double );
2505 ptr +=
sizeof( double );
2507 if ( prevx && prevy )
2509 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint ) ) < sqrDist )
2511 closestSegmentIndex = pointindex;
2513 minDistPoint = distPoint;
2521 beforeVertex = closestSegmentIndex;
2529 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2530 int* nrings = (
int* )ptr;
2532 ptr +=
sizeof( int );
2533 for (
int ringnr = 0; ringnr < *nrings; ++ringnr )
2535 npoints = (
int* )ptr;
2536 ptr +=
sizeof( int );
2539 for (
int pointnr = 0; pointnr < *npoints; ++pointnr )
2541 thisx = (
double* )ptr;
2542 ptr +=
sizeof( double );
2543 thisy = (
double* )ptr;
2544 ptr +=
sizeof( double );
2547 ptr +=
sizeof( double );
2549 if ( prevx && prevy )
2551 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint ) ) < sqrDist )
2553 closestSegmentIndex = index;
2555 minDistPoint = distPoint;
2563 beforeVertex = closestSegmentIndex;
2570 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2574 int* nPolygons = (
int* )ptr;
2575 ptr +=
sizeof( int );
2576 for (
int polynr = 0; polynr < *nPolygons; ++polynr )
2578 ptr += ( 1 +
sizeof( int ) );
2579 nRings = (
int* )ptr;
2580 ptr +=
sizeof( int );
2581 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2583 nPoints = (
int* )ptr;
2584 ptr +=
sizeof( int );
2587 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2589 thisx = (
double* )ptr;
2590 ptr +=
sizeof( double );
2591 thisy = (
double* )ptr;
2592 ptr +=
sizeof( double );
2595 ptr +=
sizeof( double );
2597 if ( prevx && prevy )
2599 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint ) ) < sqrDist )
2601 closestSegmentIndex = pointindex;
2603 minDistPoint = distPoint;
2612 beforeVertex = closestSegmentIndex;
2623 ", dist: " + QString::number( sqrDist ) +
"." );
2635 if ( ring.size() < 4 )
2639 if ( ring.first() != ring.last() )
2647 int type = GEOSGeomTypeId(
mGeos );
2650 QVector<const GEOSGeometry*> polygonList;
2654 if ( type != GEOS_POLYGON )
2657 polygonList <<
mGeos;
2661 if ( type != GEOS_MULTIPOLYGON )
2664 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); ++i )
2665 polygonList << GEOSGetGeometryN(
mGeos, i );
2669 GEOSGeometry *newRing = 0;
2670 GEOSGeometry *newRingPolygon = 0;
2675 if ( !GEOSisValid( newRing ) )
2681 if ( !GEOSisValid( newRingPolygon ) )
2689 if ( newRingPolygon )
2690 GEOSGeom_destroy( newRingPolygon );
2692 GEOSGeom_destroy( newRing );
2697 QVector<GEOSGeometry*> rings;
2700 for ( i = 0; i < polygonList.size(); i++ )
2702 for (
int j = 0; j < rings.size(); j++ )
2703 GEOSGeom_destroy( rings[j] );
2706 GEOSGeometry *shellRing = 0;
2707 GEOSGeometry *shell = 0;
2710 shellRing = GEOSGeom_clone( GEOSGetExteriorRing( polygonList[i] ) );
2713 if ( !GEOSWithin( newRingPolygon, shell ) )
2715 GEOSGeom_destroy( shell );
2723 GEOSGeom_destroy( shell );
2724 else if ( shellRing )
2725 GEOSGeom_destroy( shellRing );
2727 GEOSGeom_destroy( newRingPolygon );
2733 rings << GEOSGeom_clone( shellRing );
2735 GEOSGeom_destroy( shell );
2738 int n = GEOSGetNumInteriorRings( polygonList[i] );
2741 for ( j = 0; j < n; j++ )
2743 GEOSGeometry *holeRing = 0;
2744 GEOSGeometry *hole = 0;
2747 holeRing = GEOSGeom_clone( GEOSGetInteriorRingN( polygonList[i], j ) );
2750 if ( !GEOSDisjoint( hole, newRingPolygon ) )
2752 GEOSGeom_destroy( hole );
2760 GEOSGeom_destroy( hole );
2761 else if ( holeRing )
2762 GEOSGeom_destroy( holeRing );
2767 rings << GEOSGeom_clone( holeRing );
2768 GEOSGeom_destroy( hole );
2776 if ( i == polygonList.size() )
2779 for (
int j = 0; j < rings.size(); j++ )
2780 GEOSGeom_destroy( rings[j] );
2783 GEOSGeom_destroy( newRingPolygon );
2789 rings << GEOSGeom_clone( newRing );
2790 GEOSGeom_destroy( newRingPolygon );
2796 GEOSGeom_destroy(
mGeos );
2801 QVector<GEOSGeometry*> newPolygons;
2803 for (
int j = 0; j < polygonList.size(); j++ )
2805 newPolygons << ( i == j ? newPolygon : GEOSGeom_clone( polygonList[j] ) );
2808 GEOSGeom_destroy(
mGeos );
2820 if ( ring.size() < 4 )
2826 if ( ring.first() != ring.last() )
2852 if ( GEOSGeomTypeId(
mGeos ) != GEOS_MULTIPOLYGON )
2858 GEOSGeometry *newRing = 0;
2859 GEOSGeometry *newPolygon = 0;
2864 if ( !GEOSisValid( newRing ) )
2867 if ( !GEOSisValid( newPolygon ) )
2874 GEOSGeom_destroy( newPolygon );
2876 GEOSGeom_destroy( newRing );
2880 QVector<GEOSGeometry*> polygons;
2883 int n = GEOSGetNumGeometries(
mGeos );
2885 for ( i = 0; i < n; ++i )
2887 const GEOSGeometry *polygonN = GEOSGetGeometryN(
mGeos, i );
2889 if ( !GEOSDisjoint( polygonN, newPolygon ) )
2893 polygons << GEOSGeom_clone( polygonN );
2899 for (
int i = 0; i < polygons.size(); i++ )
2900 GEOSGeom_destroy( polygons[i] );
2904 polygons << newPolygon;
2906 GEOSGeom_destroy(
mGeos );
2927 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
2928 bool hasZValue =
false;
2929 int wkbPosition = 5;
2944 int* npoints = (
int* )( &
mGeometry[wkbPosition] );
2945 wkbPosition +=
sizeof( int );
2946 for (
int index = 0; index < *npoints; ++index )
2957 int* nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
2958 wkbPosition +=
sizeof( int );
2961 for (
int index = 0; index < *nrings; ++index )
2963 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
2964 wkbPosition +=
sizeof( int );
2965 for (
int index2 = 0; index2 < *npoints; ++index2 )
2977 int* npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
2978 wkbPosition +=
sizeof( int );
2979 for (
int index = 0; index < *npoints; ++index )
2981 wkbPosition += (
sizeof( int ) + 1 );
2991 int* nlines = (
int* )( &(
mGeometry[wkbPosition] ) );
2993 wkbPosition +=
sizeof( int );
2994 for (
int index = 0; index < *nlines; ++index )
2996 wkbPosition += (
sizeof( int ) + 1 );
2997 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
2998 wkbPosition +=
sizeof( int );
2999 for (
int index2 = 0; index2 < *npoints; ++index2 )
3011 int* npolys = (
int* )( &(
mGeometry[wkbPosition] ) );
3014 wkbPosition +=
sizeof( int );
3015 for (
int index = 0; index < *npolys; ++index )
3017 wkbPosition += ( 1 +
sizeof( int ) );
3018 nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3019 wkbPosition +=
sizeof( int );
3020 for (
int index2 = 0; index2 < *nrings; ++index2 )
3022 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3023 wkbPosition +=
sizeof( int );
3024 for (
int index3 = 0; index3 < *npoints; ++index3 )
3053 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3054 bool hasZValue =
false;
3055 int wkbPosition = 5;
3070 int* npoints = (
int* )( &
mGeometry[wkbPosition] );
3071 wkbPosition +=
sizeof( int );
3072 for (
int index = 0; index < *npoints; ++index )
3083 int* nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3084 wkbPosition +=
sizeof( int );
3087 for (
int index = 0; index < *nrings; ++index )
3089 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3090 wkbPosition +=
sizeof( int );
3091 for (
int index2 = 0; index2 < *npoints; ++index2 )
3103 int* npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3104 wkbPosition +=
sizeof( int );
3105 for (
int index = 0; index < *npoints; ++index )
3107 wkbPosition += (
sizeof( int ) + 1 );
3117 int* nlines = (
int* )( &(
mGeometry[wkbPosition] ) );
3119 wkbPosition +=
sizeof( int );
3120 for (
int index = 0; index < *nlines; ++index )
3122 wkbPosition += (
sizeof( int ) + 1 );
3123 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3124 wkbPosition +=
sizeof( int );
3125 for (
int index2 = 0; index2 < *npoints; ++index2 )
3137 int* npolys = (
int* )( &(
mGeometry[wkbPosition] ) );
3140 wkbPosition +=
sizeof( int );
3141 for (
int index = 0; index < *npolys; ++index )
3143 wkbPosition += ( 1 +
sizeof( int ) );
3144 nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3145 wkbPosition +=
sizeof( int );
3146 for (
int index2 = 0; index2 < *nrings; ++index2 )
3148 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3149 wkbPosition +=
sizeof( int );
3150 for (
int index3 = 0; index3 < *npoints; ++index3 )
3165 int QgsGeometry::splitGeometry(
const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries,
bool topological, QList<QgsPoint> &topologyTestPoints )
3187 if ( !GEOSisValid(
mGeos ) )
3193 if ( splitLine.size() < 2 )
3198 newGeometries.clear();
3203 if ( !GEOSisValid( splitLineGeos ) || !GEOSisSimple( splitLineGeos ) )
3205 GEOSGeom_destroy( splitLineGeos );
3222 GEOSGeom_destroy( splitLineGeos );
3227 GEOSGeom_destroy( splitLineGeos );
3242 if ( reshapeWithLine.size() < 2 )
3261 int numGeoms = GEOSGetNumGeometries(
mGeos );
3262 if ( numGeoms == -1 )
3267 bool isMultiGeom =
false;
3268 int geosTypeId = GEOSGeomTypeId(
mGeos );
3269 if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
3279 GEOSGeometry* reshapedGeometry;
3289 GEOSGeom_destroy( reshapeLineGeos );
3290 if ( reshapedGeometry )
3292 GEOSGeom_destroy(
mGeos );
3293 mGeos = reshapedGeometry;
3305 bool reshapeTookPlace =
false;
3307 GEOSGeometry* currentReshapeGeometry = 0;
3308 GEOSGeometry** newGeoms =
new GEOSGeometry*[numGeoms];
3310 for (
int i = 0; i < numGeoms; ++i )
3314 currentReshapeGeometry =
reshapeLine( GEOSGetGeometryN(
mGeos, i ), reshapeLineGeos );
3321 if ( currentReshapeGeometry )
3323 newGeoms[i] = currentReshapeGeometry;
3324 reshapeTookPlace =
true;
3328 newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN(
mGeos, i ) );
3331 GEOSGeom_destroy( reshapeLineGeos );
3333 GEOSGeometry* newMultiGeom = 0;
3336 newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
3340 newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
3344 if ( ! newMultiGeom )
3349 if ( reshapeTookPlace )
3351 GEOSGeom_destroy(
mGeos );
3352 mGeos = newMultiGeom;
3358 GEOSGeom_destroy( newMultiGeom );
3377 if ( !GEOSisValid(
mGeos ) )
3382 if ( !GEOSisSimple(
mGeos ) )
3393 if ( !other->
mGeos )
3448 bool hasZValue =
false;
3463 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3469 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
3492 nPoints = (
int * ) ptr;
3493 ptr +=
sizeof( int );
3494 for ( idx = 0; idx < *nPoints; idx++ )
3496 ptr += ( 1 +
sizeof( int ) );
3497 x = (
double * ) ptr;
3498 ptr +=
sizeof( double );
3499 y = (
double * ) ptr;
3500 ptr +=
sizeof( double );
3503 ptr +=
sizeof( double );
3530 nPoints = (
int * ) ptr;
3531 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3532 for ( idx = 0; idx < *nPoints; idx++ )
3534 x = (
double * ) ptr;
3535 ptr +=
sizeof( double );
3536 y = (
double * ) ptr;
3537 ptr +=
sizeof( double );
3540 ptr +=
sizeof( double );
3565 numLineStrings = ( int )(
mGeometry[5] );
3567 for ( jdx = 0; jdx < numLineStrings; jdx++ )
3571 nPoints = (
int * ) ptr;
3572 ptr +=
sizeof( int );
3573 for ( idx = 0; idx < *nPoints; idx++ )
3575 x = (
double * ) ptr;
3576 ptr +=
sizeof( double );
3577 y = (
double * ) ptr;
3578 ptr +=
sizeof( double );
3581 ptr +=
sizeof( double );
3608 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
3609 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3610 for ( idx = 0; idx < *numRings; idx++ )
3613 nPoints = (
int * ) ptr;
3615 for ( jdx = 0; jdx < *nPoints; jdx++ )
3618 x = (
double * ) ptr;
3619 ptr +=
sizeof( double );
3620 y = (
double * ) ptr;
3621 ptr +=
sizeof( double );
3624 ptr +=
sizeof( double );
3652 numPolygons = (
int * ) ptr;
3655 for ( kdx = 0; kdx < *numPolygons; kdx++ )
3660 numRings = (
int * ) ptr;
3662 for ( idx = 0; idx < *numRings; idx++ )
3665 nPoints = (
int * ) ptr;
3667 for ( jdx = 0; jdx < *nPoints; jdx++ )
3670 x = (
double * ) ptr;
3671 ptr +=
sizeof( double );
3672 y = (
double * ) ptr;
3673 ptr +=
sizeof( double );
3676 ptr +=
sizeof( double );
3731 return GEOSIntersects(
mGeos, geometry->
mGeos );
3747 GEOSGeometry *geosPoint = 0;
3749 bool returnval =
false;
3754 returnval = GEOSContains(
mGeos, geosPoint );
3763 GEOSGeom_destroy( geosPoint );
3769 char( *op )(
const GEOSGeometry*,
const GEOSGeometry * ),
3791 return geosRelOp( GEOSContains,
this, geometry );
3796 return geosRelOp( GEOSDisjoint,
this, geometry );
3801 return geosRelOp( GEOSEquals,
this, geometry );
3806 return geosRelOp( GEOSTouches,
this, geometry );
3811 return geosRelOp( GEOSOverlaps,
this, geometry );
3816 return geosRelOp( GEOSWithin,
this, geometry );
3821 return geosRelOp( GEOSCrosses,
this, geometry );
3837 return QString::null;
3841 bool hasZValue =
false;
3848 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3857 mWkt += QString::number( *x,
'f', 6 );
3859 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
3860 mWkt += QString::number( *y,
'f', 6 );
3874 mWkt +=
"LINESTRING(";
3877 nPoints = (
int * ) ptr;
3878 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3879 for ( idx = 0; idx < *nPoints; ++idx )
3885 x = (
double * ) ptr;
3886 mWkt += QString::number( *x,
'f', 6 );
3888 ptr +=
sizeof( double );
3889 y = (
double * ) ptr;
3890 mWkt += QString::number( *y,
'f', 6 );
3891 ptr +=
sizeof( double );
3894 ptr +=
sizeof( double );
3908 int *numRings, *nPoints;
3912 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
3913 if ( !( *numRings ) )
3919 ringStart =
new int[*numRings];
3920 ringNumPoints =
new int[*numRings];
3921 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3922 for ( idx = 0; idx < *numRings; idx++ )
3930 nPoints = (
int * ) ptr;
3931 ringNumPoints[idx] = *nPoints;
3934 for ( jdx = 0; jdx < *nPoints; jdx++ )
3940 x = (
double * ) ptr;
3941 mWkt += QString::number( *x,
'f', 6 );
3943 ptr +=
sizeof( double );
3944 y = (
double * ) ptr;
3945 mWkt += QString::number( *y,
'f', 6 );
3946 ptr +=
sizeof( double );
3949 ptr +=
sizeof( double );
3955 delete [] ringStart;
3956 delete [] ringNumPoints;
3968 mWkt +=
"MULTIPOINT(";
3971 for ( idx = 0; idx < *nPoints; ++idx )
3973 ptr += ( 1 +
sizeof( int ) );
3978 x = (
double * )( ptr );
3979 mWkt += QString::number( *x,
'f', 6 );
3981 ptr +=
sizeof( double );
3982 y = (
double * )( ptr );
3983 mWkt += QString::number( *y,
'f', 6 );
3984 ptr +=
sizeof( double );
3987 ptr +=
sizeof( double );
4000 int idx, jdx, numLineStrings;
4003 mWkt +=
"MULTILINESTRING(";
4004 numLineStrings = ( int )(
mGeometry[5] );
4006 for ( jdx = 0; jdx < numLineStrings; jdx++ )
4014 nPoints = (
int * ) ptr;
4015 ptr +=
sizeof( int );
4016 for ( idx = 0; idx < *nPoints; idx++ )
4022 x = (
double * ) ptr;
4023 mWkt += QString::number( *x,
'f', 6 );
4024 ptr +=
sizeof( double );
4026 y = (
double * ) ptr;
4027 mWkt += QString::number( *y,
'f', 6 );
4028 ptr +=
sizeof( double );
4031 ptr +=
sizeof( double );
4047 int *numPolygons, *numRings, *nPoints;
4049 mWkt +=
"MULTIPOLYGON(";
4051 numPolygons = (
int * ) ptr;
4053 for ( kdx = 0; kdx < *numPolygons; kdx++ )
4061 numRings = (
int * ) ptr;
4063 for ( idx = 0; idx < *numRings; idx++ )
4070 nPoints = (
int * ) ptr;
4072 for ( jdx = 0; jdx < *nPoints; jdx++ )
4078 x = (
double * ) ptr;
4079 mWkt += QString::number( *x,
'f', 6 );
4080 ptr +=
sizeof( double );
4082 y = (
double * ) ptr;
4083 mWkt += QString::number( *y,
'f', 6 );
4084 ptr +=
sizeof( double );
4087 ptr +=
sizeof( double );
4099 QgsDebugMsg(
"error: mGeometry type not recognized" );
4100 return QString::null;
4116 GEOSGeom_destroy(
mGeos );
4138 bool hasZValue =
false;
4141 memcpy( &wkbtype, &(
mGeometry[1] ),
sizeof(
int ) );
4151 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
4162 QVector<GEOSGeometry *> points;
4165 nPoints = (
int * ) ptr;
4166 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4167 for ( idx = 0; idx < *nPoints; idx++ )
4169 ptr += ( 1 +
sizeof( int ) );
4170 x = (
double * ) ptr;
4171 ptr +=
sizeof( double );
4172 y = (
double * ) ptr;
4173 ptr +=
sizeof( double );
4176 ptr +=
sizeof( double );
4194 nPoints = (
int * ) ptr;
4195 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4196 for ( idx = 0; idx < *nPoints; idx++ )
4198 x = (
double * ) ptr;
4199 ptr +=
sizeof( double );
4200 y = (
double * ) ptr;
4201 ptr +=
sizeof( double );
4204 ptr +=
sizeof( double );
4218 QVector<GEOSGeometry*> lines;
4219 numLineStrings = ( int )(
mGeometry[5] );
4221 for ( jdx = 0; jdx < numLineStrings; jdx++ )
4227 nPoints = (
int * ) ptr;
4228 ptr +=
sizeof( int );
4229 for ( idx = 0; idx < *nPoints; idx++ )
4231 x = (
double * ) ptr;
4232 ptr +=
sizeof( double );
4233 y = (
double * ) ptr;
4234 ptr +=
sizeof( double );
4237 ptr +=
sizeof( double );
4255 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
4256 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4258 QVector<GEOSGeometry*> rings;
4260 for ( idx = 0; idx < *numRings; idx++ )
4267 nPoints = (
int * ) ptr;
4269 for ( jdx = 0; jdx < *nPoints; jdx++ )
4272 x = (
double * ) ptr;
4273 ptr +=
sizeof( double );
4274 y = (
double * ) ptr;
4275 ptr +=
sizeof( double );
4278 ptr +=
sizeof( double );
4296 QVector<GEOSGeometry*> polygons;
4300 numPolygons = (
int * ) ptr;
4302 for ( kdx = 0; kdx < *numPolygons; kdx++ )
4305 QVector<GEOSGeometry*> rings;
4310 numRings = (
int * ) ptr;
4312 for ( idx = 0; idx < *numRings; idx++ )
4319 nPoints = (
int * ) ptr;
4321 for ( jdx = 0; jdx < *nPoints; jdx++ )
4324 x = (
double * ) ptr;
4325 ptr +=
sizeof( double );
4326 y = (
double * ) ptr;
4327 ptr +=
sizeof( double );
4330 ptr +=
sizeof( double );
4380 switch ( GEOSGeomTypeId(
mGeos ) )
4386 2 *
sizeof( double );
4396 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq(
mGeos );
4399 GEOSCoordSeq_getX( cs, 0, &x );
4400 GEOSCoordSeq_getY( cs, 0, &y );
4402 memcpy(
mGeometry + 5, &x,
sizeof(
double ) );
4403 memcpy(
mGeometry + 13, &y,
sizeof(
double ) );
4409 case GEOS_LINESTRING:
4413 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq(
mGeos );
4414 unsigned int numPoints;
4415 GEOSCoordSeq_getSize( cs, &numPoints );
4421 ((
sizeof( double ) +
4422 sizeof(
double ) ) * numPoints );
4429 memcpy( ptr, &byteOrder, 1 );
4434 memcpy( ptr, &wkbType, 4 );
4438 memcpy( ptr, &numPoints, 4 );
4441 const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq(
mGeos );
4444 for (
unsigned int n = 0; n < numPoints; n++ )
4447 GEOSCoordSeq_getX( sequence, n, (
double * )ptr );
4448 ptr +=
sizeof( double );
4451 GEOSCoordSeq_getY( sequence, n, (
double * )ptr );
4452 ptr +=
sizeof( double );
4461 case GEOS_LINEARRING:
4470 unsigned int nPointsInRing = 0;
4473 geometrySize = 1 + 2 *
sizeof( int );
4474 const GEOSGeometry *theRing = GEOSGetExteriorRing(
mGeos );
4477 geometrySize +=
sizeof( int );
4480 for (
int i = 0; i < GEOSGetNumInteriorRings(
mGeos ); ++i )
4482 geometrySize +=
sizeof( int );
4483 theRing = GEOSGetInteriorRingN(
mGeos, i );
4490 mGeometry =
new unsigned char[geometrySize];
4499 memcpy( &
mGeometry[position], &wkbtype,
sizeof(
int ) );
4500 position +=
sizeof( int );
4501 int nRings = GEOSGetNumInteriorRings(
mGeos ) + 1;
4502 memcpy( &
mGeometry[position], &nRings,
sizeof(
int ) );
4503 position +=
sizeof( int );
4506 theRing = GEOSGetExteriorRing(
mGeos );
4510 memcpy( &
mGeometry[position], &nPointsInRing,
sizeof(
int ) );
4511 position +=
sizeof( int );
4513 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4515 GEOSCoordSeq_getSize( cs, &n );
4517 for (
unsigned int j = 0; j < n; ++j )
4519 GEOSCoordSeq_getX( cs, j, (
double * )&
mGeometry[position] );
4520 position +=
sizeof( double );
4521 GEOSCoordSeq_getY( cs, j, (
double * )&
mGeometry[position] );
4522 position +=
sizeof( double );
4527 for (
int i = 0; i < GEOSGetNumInteriorRings(
mGeos ); i++ )
4529 theRing = GEOSGetInteriorRingN(
mGeos, i );
4531 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4532 GEOSCoordSeq_getSize( cs, &nPointsInRing );
4534 memcpy( &
mGeometry[position], &nPointsInRing,
sizeof(
int ) );
4535 position +=
sizeof( int );
4537 for (
unsigned int j = 0; j < nPointsInRing; j++ )
4539 GEOSCoordSeq_getX( cs, j, (
double * )&
mGeometry[position] );
4540 position +=
sizeof( double );
4541 GEOSCoordSeq_getY( cs, j, (
double * )&
mGeometry[position] );
4542 position +=
sizeof( double );
4550 case GEOS_MULTIPOINT:
4553 int geometrySize = 1 + 2 *
sizeof( int );
4554 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4556 geometrySize += 1 +
sizeof( int ) + 2 *
sizeof(
double );
4559 mGeometry =
new unsigned char[geometrySize];
4561 int wkbPosition = 0;
4566 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
4567 wkbPosition +=
sizeof( int );
4568 int numPoints = GEOSGetNumGeometries(
mGeos );
4569 memcpy( &
mGeometry[wkbPosition], &numPoints,
sizeof(
int ) );
4570 wkbPosition +=
sizeof( int );
4573 const GEOSGeometry *currentPoint = 0;
4575 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4578 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
4580 memcpy( &
mGeometry[wkbPosition], &pointType,
sizeof(
int ) );
4581 wkbPosition +=
sizeof( int );
4583 currentPoint = GEOSGetGeometryN(
mGeos, i );
4585 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( currentPoint );
4587 GEOSCoordSeq_getX( cs, 0, (
double* )&
mGeometry[wkbPosition] );
4588 wkbPosition +=
sizeof( double );
4589 GEOSCoordSeq_getY( cs, 0, (
double* )&
mGeometry[wkbPosition] );
4590 wkbPosition +=
sizeof( double );
4596 case GEOS_MULTILINESTRING:
4599 int geometrySize = 1 + 2 *
sizeof( int );
4600 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4602 geometrySize += 1 + 2 *
sizeof( int );
4606 mGeometry =
new unsigned char[geometrySize];
4608 int wkbPosition = 0;
4613 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
4614 wkbPosition +=
sizeof( int );
4615 int numLines = GEOSGetNumGeometries(
mGeos );
4616 memcpy( &
mGeometry[wkbPosition], &numLines,
sizeof(
int ) );
4617 wkbPosition +=
sizeof( int );
4621 const GEOSCoordSequence *cs = 0;
4622 unsigned int lineSize;
4624 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4627 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
4629 memcpy( &
mGeometry[wkbPosition], &lineType,
sizeof(
int ) );
4630 wkbPosition +=
sizeof( int );
4632 cs = GEOSGeom_getCoordSeq( GEOSGetGeometryN(
mGeos, i ) );
4635 GEOSCoordSeq_getSize( cs, &lineSize );
4636 memcpy( &
mGeometry[wkbPosition], &lineSize,
sizeof(
int ) );
4637 wkbPosition +=
sizeof( int );
4640 for (
unsigned int j = 0; j < lineSize; ++j )
4642 GEOSCoordSeq_getX( cs, j, (
double* )&
mGeometry[wkbPosition] );
4643 wkbPosition +=
sizeof( double );
4644 GEOSCoordSeq_getY( cs, j, (
double* )&
mGeometry[wkbPosition] );
4645 wkbPosition +=
sizeof( double );
4652 case GEOS_MULTIPOLYGON:
4655 int geometrySize = 1 + ( 2 *
sizeof( int ) );
4656 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4658 const GEOSGeometry *thePoly = GEOSGetGeometryN(
mGeos, i );
4659 geometrySize += 1 + 2 *
sizeof( int );
4661 geometrySize +=
sizeof( int );
4662 const GEOSGeometry *exRing = GEOSGetExteriorRing( thePoly );
4665 const GEOSGeometry *intRing = 0;
4666 for (
int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ )
4668 geometrySize +=
sizeof( int );
4669 intRing = GEOSGetInteriorRingN( thePoly, j );
4674 mGeometry =
new unsigned char[geometrySize];
4676 int wkbPosition = 0;
4681 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
4682 wkbPosition +=
sizeof( int );
4683 int numPolygons = GEOSGetNumGeometries(
mGeos );
4684 memcpy( &
mGeometry[wkbPosition], &numPolygons,
sizeof(
int ) );
4685 wkbPosition +=
sizeof( int );
4688 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
4690 const GEOSGeometry *thePoly = GEOSGetGeometryN(
mGeos, i );
4691 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
4694 memcpy( &
mGeometry[wkbPosition], &polygonType,
sizeof(
int ) );
4695 wkbPosition +=
sizeof( int );
4696 int numRings = GEOSGetNumInteriorRings( thePoly ) + 1;
4697 memcpy( &
mGeometry[wkbPosition], &numRings,
sizeof(
int ) );
4698 wkbPosition +=
sizeof( int );
4701 const GEOSGeometry *theRing = GEOSGetExteriorRing( thePoly );
4703 memcpy( &
mGeometry[wkbPosition], &nPointsInRing,
sizeof(
int ) );
4704 wkbPosition +=
sizeof( int );
4705 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4707 for (
int k = 0; k < nPointsInRing; ++k )
4709 GEOSCoordSeq_getX( cs, k, (
double * )&
mGeometry[wkbPosition] );
4710 wkbPosition +=
sizeof( double );
4711 GEOSCoordSeq_getY( cs, k, (
double * )&
mGeometry[wkbPosition] );
4712 wkbPosition +=
sizeof( double );
4716 for (
int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ )
4718 theRing = GEOSGetInteriorRingN( thePoly, j );
4720 memcpy( &
mGeometry[wkbPosition], &nPointsInRing,
sizeof(
int ) );
4721 wkbPosition +=
sizeof( int );
4722 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4724 for (
int k = 0; k < nPointsInRing; ++k )
4726 GEOSCoordSeq_getX( cs, k, (
double * )&
mGeometry[wkbPosition] );
4727 wkbPosition +=
sizeof( double );
4728 GEOSCoordSeq_getY( cs, k, (
double * )&
mGeometry[wkbPosition] );
4729 wkbPosition +=
sizeof( double );
4737 case GEOS_GEOMETRYCOLLECTION:
4740 QgsDebugMsg(
"geometry collection - not supported" );
4766 unsigned char* newGeometry =
new unsigned char[newGeomSize];
4768 int currentWkbPosition = 0;
4771 memcpy( &newGeometry[currentWkbPosition], &byteOrder, 1 );
4772 currentWkbPosition += 1;
4801 memcpy( &newGeometry[currentWkbPosition], &newMultiType,
sizeof(
int ) );
4802 currentWkbPosition +=
sizeof( int );
4805 int nGeometries = 1;
4806 memcpy( &newGeometry[currentWkbPosition], &nGeometries,
sizeof(
int ) );
4807 currentWkbPosition +=
sizeof( int );
4821 double x, y, translated_x, translated_y;
4824 x = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
4825 translated_x = x + dx;
4826 memcpy( &(
mGeometry[wkbPosition] ), &translated_x,
sizeof(
double ) );
4827 wkbPosition +=
sizeof( double );
4830 y = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
4831 translated_y = y + dy;
4832 memcpy( &(
mGeometry[wkbPosition] ), &translated_y,
sizeof(
double ) );
4833 wkbPosition +=
sizeof( double );
4837 wkbPosition +=
sizeof( double );
4846 x = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
4847 y = *((
double * )( &(
mGeometry[wkbPosition +
sizeof(
double )] ) ) );
4853 memcpy( &(
mGeometry[wkbPosition] ), &x,
sizeof(
double ) );
4854 wkbPosition +=
sizeof( double );
4857 memcpy( &(
mGeometry[wkbPosition] ), &y,
sizeof(
double ) );
4858 wkbPosition +=
sizeof( double );
4862 wkbPosition +=
sizeof( double );
4880 if ( !GEOSIntersects( splitLine,
mGeos ) )
4887 if ( !nodedGeometry )
4892 GEOSGeometry *mergedLines = GEOSLineMerge( nodedGeometry );
4895 GEOSGeom_destroy( nodedGeometry );
4899 QVector<GEOSGeometry*> testedGeometries;
4901 for (
int i = 0; i < GEOSGetNumGeometries( mergedLines ); i++ )
4903 const GEOSGeometry *testing = GEOSGetGeometryN( mergedLines, i );
4906 testedGeometries << GEOSGeom_clone( testing );
4912 if ( testedGeometries.size() > 0 )
4914 GEOSGeom_destroy(
mGeos );
4915 mGeos = testedGeometries[0];
4919 for (
int i = 1; i < testedGeometries.size(); ++i )
4922 GEOSGeom_destroy( nodedGeometry );
4923 GEOSGeom_destroy( mergedLines );
4941 if ( !GEOSIntersects( splitLine,
mGeos ) )
4948 if ( !nodedGeometry )
4953 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
4954 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=1)))
4955 GEOSGeometry *cutEdges = GEOSPolygonizer_getCutEdges( &nodedGeometry, 1 );
4960 GEOSGeom_destroy( cutEdges );
4961 GEOSGeom_destroy( nodedGeometry );
4965 GEOSGeom_destroy( cutEdges );
4969 GEOSGeometry *polygons = GEOSPolygonize( &nodedGeometry, 1 );
4973 GEOSGeom_destroy( polygons );
4975 GEOSGeom_destroy( nodedGeometry );
4980 GEOSGeom_destroy( nodedGeometry );
4984 QVector<GEOSGeometry*> testedGeometries;
4985 GEOSGeometry *intersectGeometry = 0;
4992 const GEOSGeometry *polygon = GEOSGetGeometryN( polygons, i );
4993 intersectGeometry = GEOSIntersection(
mGeos, polygon );
4994 if ( !intersectGeometry )
5000 double intersectionArea;
5001 GEOSArea( intersectGeometry, &intersectionArea );
5004 GEOSArea( polygon, &polygonArea );
5006 const double areaRatio = intersectionArea / polygonArea;
5007 if ( areaRatio > 0.99 && areaRatio < 1.01 )
5008 testedGeometries << GEOSGeom_clone( polygon );
5010 GEOSGeom_destroy( intersectGeometry );
5013 bool splitDone =
true;
5015 if ( testedGeometries.size() == nGeometriesThis )
5025 for (
int i = 0; i < testedGeometries.size(); ++i )
5027 GEOSGeom_destroy( testedGeometries[i] );
5031 else if ( testedGeometries.size() > 0 )
5033 GEOSGeom_destroy(
mGeos );
5034 mGeos = testedGeometries[0];
5038 for (
int i = 1; i < testedGeometries.size(); ++i )
5043 GEOSGeom_destroy( polygons );
5050 int nIntersections = 0;
5051 int lastIntersectingRing = -2;
5052 const GEOSGeometry* lastIntersectingGeom = 0;
5054 int nRings = GEOSGetNumInteriorRings( polygon );
5061 const GEOSGeometry* outerRing = GEOSGetExteriorRing( polygon );
5062 if ( GEOSIntersects( outerRing, reshapeLineGeos ) == 1 )
5065 lastIntersectingRing = -1;
5066 lastIntersectingGeom = outerRing;
5070 const GEOSGeometry **innerRings =
new const GEOSGeometry*[nRings];
5074 for (
int i = 0; i < nRings; ++i )
5076 innerRings[i] = GEOSGetInteriorRingN( polygon, i );
5077 if ( GEOSIntersects( innerRings[i], reshapeLineGeos ) == 1 )
5080 lastIntersectingRing = i;
5081 lastIntersectingGeom = innerRings[i];
5091 if ( nIntersections != 1 )
5093 delete [] innerRings;
5098 GEOSGeometry* reshapeResult =
reshapeLine( lastIntersectingGeom, reshapeLineGeos );
5099 if ( !reshapeResult )
5101 delete [] innerRings;
5106 GEOSGeometry* newRing = 0;
5107 const GEOSCoordSequence* reshapeSequence = GEOSGeom_getCoordSeq( reshapeResult );
5108 GEOSCoordSequence* newCoordSequence = GEOSCoordSeq_clone( reshapeSequence );
5110 GEOSGeom_destroy( reshapeResult );
5112 newRing = GEOSGeom_createLinearRing( newCoordSequence );
5115 delete [] innerRings;
5120 GEOSGeometry* newOuterRing = 0;
5121 if ( lastIntersectingRing == -1 )
5123 newOuterRing = newRing;
5127 newOuterRing = GEOSGeom_clone( outerRing );
5131 QList<GEOSGeometry*> ringList;
5134 GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 );
5135 if ( outerRingPoly )
5137 GEOSGeometry* currentRing = 0;
5138 for (
int i = 0; i < nRings; ++i )
5140 if ( lastIntersectingRing == i )
5142 currentRing = newRing;
5146 currentRing = GEOSGeom_clone( innerRings[i] );
5150 if ( GEOSContains( outerRingPoly, currentRing ) == 1 )
5152 ringList.push_back( currentRing );
5156 GEOSGeom_destroy( currentRing );
5160 GEOSGeom_destroy( outerRingPoly );
5163 GEOSGeometry** newInnerRings =
new GEOSGeometry*[ringList.size()];
5164 for (
int i = 0; i < ringList.size(); ++i )
5166 newInnerRings[i] = ringList.at( i );
5169 delete [] innerRings;
5171 GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, ringList.size() );
5172 delete[] newInnerRings;
5173 if ( !reshapedPolygon )
5177 return reshapedPolygon;
5182 if ( !line || !reshapeLineGeos )
5187 bool atLeastTwoIntersections;
5192 GEOSGeometry* intersectGeom = GEOSIntersection( line, reshapeLineGeos );
5193 atLeastTwoIntersections = ( GEOSGeomTypeId( intersectGeom ) == GEOS_MULTIPOINT && GEOSGetNumGeometries( intersectGeom ) > 1 );
5194 GEOSGeom_destroy( intersectGeom );
5199 atLeastTwoIntersections =
false;
5202 if ( !atLeastTwoIntersections )
5208 const GEOSCoordSequence* lineCoordSeq = GEOSGeom_getCoordSeq( line );
5209 if ( !lineCoordSeq )
5213 unsigned int lineCoordSeqSize;
5214 if ( GEOSCoordSeq_getSize( lineCoordSeq, &lineCoordSeqSize ) == 0 )
5218 if ( lineCoordSeqSize < 2 )
5223 double x1, y1, x2, y2;
5224 GEOSCoordSeq_getX( lineCoordSeq, 0, &x1 );
5225 GEOSCoordSeq_getY( lineCoordSeq, 0, &y1 );
5226 GEOSCoordSeq_getX( lineCoordSeq, lineCoordSeqSize - 1, &x2 );
5227 GEOSCoordSeq_getY( lineCoordSeq, lineCoordSeqSize - 1, &y2 );
5231 bool isRing =
false;
5232 if ( GEOSGeomTypeId( line ) == GEOS_LINEARRING || GEOSEquals( beginLineVertex, endLineVertex ) == 1 )
5238 GEOSGeometry* nodedGeometry =
nodeGeometries( reshapeLineGeos, line );
5239 if ( !nodedGeometry )
5241 GEOSGeom_destroy( beginLineVertex );
5242 GEOSGeom_destroy( endLineVertex );
5247 GEOSGeometry *mergedLines = GEOSLineMerge( nodedGeometry );
5248 GEOSGeom_destroy( nodedGeometry );
5251 GEOSGeom_destroy( beginLineVertex );
5252 GEOSGeom_destroy( endLineVertex );
5256 int numMergedLines = GEOSGetNumGeometries( mergedLines );
5257 if ( numMergedLines < 2 )
5259 GEOSGeom_destroy( beginLineVertex );
5260 GEOSGeom_destroy( endLineVertex );
5261 if ( numMergedLines == 1 )
5263 return GEOSGeom_clone( reshapeLineGeos );
5271 QList<GEOSGeometry*> resultLineParts;
5272 QList<GEOSGeometry*> probableParts;
5274 for (
int i = 0; i < numMergedLines; ++i )
5276 const GEOSGeometry* currentGeom;
5278 currentGeom = GEOSGetGeometryN( mergedLines, i );
5279 const GEOSCoordSequence* currentCoordSeq = GEOSGeom_getCoordSeq( currentGeom );
5280 unsigned int currentCoordSeqSize;
5281 GEOSCoordSeq_getSize( currentCoordSeq, ¤tCoordSeqSize );
5282 if ( currentCoordSeqSize < 2 )
5288 double xBegin, xEnd, yBegin, yEnd;
5289 GEOSCoordSeq_getX( currentCoordSeq, 0, &xBegin );
5290 GEOSCoordSeq_getY( currentCoordSeq, 0, &yBegin );
5291 GEOSCoordSeq_getX( currentCoordSeq, currentCoordSeqSize - 1, &xEnd );
5292 GEOSCoordSeq_getY( currentCoordSeq, currentCoordSeqSize - 1, &yEnd );
5297 int nEndpointsOnOriginalLine = 0;
5300 nEndpointsOnOriginalLine += 1;
5305 nEndpointsOnOriginalLine += 1;
5309 int nEndpointsSameAsOriginalLine = 0;
5310 if ( GEOSEquals( beginCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( beginCurrentGeomVertex, endLineVertex ) == 1 )
5312 nEndpointsSameAsOriginalLine += 1;
5314 if ( GEOSEquals( endCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( endCurrentGeomVertex, endLineVertex ) == 1 )
5316 nEndpointsSameAsOriginalLine += 1;
5320 bool currentGeomOverlapsOriginalGeom =
false;
5321 bool currentGeomOverlapsReshapeLine =
false;
5324 currentGeomOverlapsOriginalGeom =
true;
5328 currentGeomOverlapsReshapeLine =
true;
5333 if ( nEndpointsSameAsOriginalLine == 1 && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom )
5335 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5338 else if ( isRing && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom )
5340 probableParts.push_back( GEOSGeom_clone( currentGeom ) );
5342 else if ( nEndpointsOnOriginalLine == 2 && !currentGeomOverlapsOriginalGeom )
5344 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5346 else if ( nEndpointsSameAsOriginalLine == 2 && !currentGeomOverlapsOriginalGeom )
5348 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5350 else if ( currentGeomOverlapsOriginalGeom && currentGeomOverlapsReshapeLine )
5352 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5355 GEOSGeom_destroy( beginCurrentGeomVertex );
5356 GEOSGeom_destroy( endCurrentGeomVertex );
5360 if ( isRing && probableParts.size() > 0 )
5362 GEOSGeometry* maxGeom = 0;
5363 GEOSGeometry* currentGeom = 0;
5364 double maxLength = -DBL_MAX;
5365 double currentLength = 0;
5366 for (
int i = 0; i < probableParts.size(); ++i )
5368 currentGeom = probableParts.at( i );
5369 GEOSLength( currentGeom, ¤tLength );
5370 if ( currentLength > maxLength )
5372 maxLength = currentLength;
5373 GEOSGeom_destroy( maxGeom );
5374 maxGeom = currentGeom;
5378 GEOSGeom_destroy( currentGeom );
5381 resultLineParts.push_back( maxGeom );
5384 GEOSGeom_destroy( beginLineVertex );
5385 GEOSGeom_destroy( endLineVertex );
5386 GEOSGeom_destroy( mergedLines );
5388 GEOSGeometry* result = 0;
5389 if ( resultLineParts.size() < 1 )
5393 if ( resultLineParts.size() == 1 )
5395 result = resultLineParts[0];
5399 GEOSGeometry **lineArray =
new GEOSGeometry*[resultLineParts.size()];
5400 for (
int i = 0; i < resultLineParts.size(); ++i )
5402 lineArray[i] = resultLineParts[i];
5406 GEOSGeometry* multiLineGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, lineArray, resultLineParts.size() );
5407 delete [] lineArray;
5410 result = GEOSLineMerge( multiLineGeom );
5411 GEOSGeom_destroy( multiLineGeom );
5415 if ( GEOSGeomTypeId( result ) != GEOS_LINESTRING )
5417 GEOSGeom_destroy( result );
5430 GEOSGeometry* intersectionGeom = GEOSIntersection(
mGeos, splitLine );
5431 if ( !intersectionGeom )
5436 bool simple =
false;
5437 int nIntersectGeoms = 1;
5438 if ( GEOSGeomTypeId( intersectionGeom ) == GEOS_LINESTRING || GEOSGeomTypeId( intersectionGeom ) == GEOS_POINT )
5445 nIntersectGeoms = GEOSGetNumGeometries( intersectionGeom );
5448 for (
int i = 0; i < nIntersectGeoms; ++i )
5450 const GEOSGeometry* currentIntersectGeom;
5453 currentIntersectGeom = intersectionGeom;
5457 currentIntersectGeom = GEOSGetGeometryN( intersectionGeom, i );
5460 const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq( currentIntersectGeom );
5461 unsigned int sequenceSize = 0;
5463 if ( GEOSCoordSeq_getSize( lineSequence, &sequenceSize ) != 0 )
5465 for (
unsigned int i = 0; i < sequenceSize; ++i )
5467 if ( GEOSCoordSeq_getX( lineSequence, i, &x ) != 0 )
5469 if ( GEOSCoordSeq_getY( lineSequence, i, &y ) != 0 )
5471 testPoints.push_back(
QgsPoint( x, y ) );
5477 GEOSGeom_destroy( intersectionGeom );
5483 if ( !splitLine || !geom )
5488 GEOSGeometry *geometryBoundary = 0;
5489 if ( GEOSGeomTypeId( geom ) == GEOS_POLYGON || GEOSGeomTypeId( geom ) == GEOS_MULTIPOLYGON )
5491 geometryBoundary = GEOSBoundary( geom );
5495 geometryBoundary = GEOSGeom_clone( geom );
5498 GEOSGeometry *splitLineClone = GEOSGeom_clone( splitLine );
5499 GEOSGeometry *unionGeometry = GEOSUnion( splitLineClone, geometryBoundary );
5500 GEOSGeom_destroy( splitLineClone );
5502 GEOSGeom_destroy( geometryBoundary );
5503 return unionGeometry;
5508 if ( !line1 || !line2 )
5514 double bufferDistance = 0.00001;
5517 bufferDistance = 0.00000001;
5525 GEOSGeometry* intersectionGeom = GEOSIntersection( bufferGeom, line1 );
5528 double intersectGeomLength;
5531 GEOSLength( intersectionGeom, &intersectGeomLength );
5532 GEOSLength( line1, &line1Length );
5534 GEOSGeom_destroy( bufferGeom );
5535 GEOSGeom_destroy( intersectionGeom );
5537 double intersectRatio = line1Length / intersectGeomLength;
5538 if ( intersectRatio > 0.9 && intersectRatio < 1.1 )
5547 if ( !point || !line )
5552 double bufferDistance = 0.000001;
5555 bufferDistance = 0.00000001;
5557 GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
5563 bool contained =
false;
5564 if ( GEOSContains( lineBuffer, point ) == 1 )
5569 GEOSGeom_destroy( lineBuffer );
5575 GEOSGeometry* bbox = GEOSEnvelope( geom );
5581 const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox );
5586 const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing );
5588 if ( !bBoxCoordSeq )
5593 unsigned int nCoords = 0;
5594 if ( !GEOSCoordSeq_getSize( bBoxCoordSeq, &nCoords ) )
5600 for (
unsigned int i = 0; i < ( nCoords - 1 ); ++i )
5602 GEOSCoordSeq_getX( bBoxCoordSeq, i, &x );
5603 if ( x > 180 || x < -180 )
5607 GEOSCoordSeq_getY( bBoxCoordSeq, i, &y );
5608 if ( y > 90 || y < -90 )
5623 int geometryType = GEOSGeomTypeId( g );
5624 if ( geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
5625 || geometryType == GEOS_POLYGON )
5631 return GEOSGetNumGeometries( g );
5643 int type = GEOSGeomTypeId(
mGeos );
5644 if ( type != GEOS_GEOMETRYCOLLECTION &&
5645 type != GEOS_MULTILINESTRING &&
5646 type != GEOS_MULTIPOLYGON &&
5647 type != GEOS_MULTIPOINT )
5652 QVector<GEOSGeometry*> copyList = splitResult;
5653 splitResult.clear();
5656 QVector<GEOSGeometry*> unionGeom;
5658 for (
int i = 0; i < copyList.size(); ++i )
5661 bool isPart =
false;
5662 for (
int j = 0; j < GEOSGetNumGeometries(
mGeos ); j++ )
5664 if ( GEOSEquals( copyList[i], GEOSGetGeometryN(
mGeos, j ) ) )
5673 unionGeom << copyList[i];
5677 QVector<GEOSGeometry*> geomVector;
5678 geomVector << copyList[i];
5680 if ( type == GEOS_MULTILINESTRING )
5684 else if ( type == GEOS_MULTIPOLYGON )
5690 GEOSGeom_destroy( copyList[i] );
5696 if ( unionGeom.size() > 0 )
5698 if ( type == GEOS_MULTILINESTRING )
5702 else if ( type == GEOS_MULTIPOLYGON )
5718 double* x = (
double * )( ptr );
5719 double* y = (
double * )( ptr +
sizeof(
double ) );
5720 ptr += 2 *
sizeof( double );
5723 ptr +=
sizeof( double );
5733 unsigned int nPoints = *((
int* )ptr );
5739 for ( uint i = 0; i < nPoints; ++i )
5741 x = *((
double * ) ptr );
5742 y = *((
double * )( ptr +
sizeof(
double ) ) );
5744 ptr += 2 *
sizeof( double );
5749 ptr +=
sizeof( double );
5763 unsigned int numRings = *((
int* )ptr );
5766 if ( numRings == 0 )
5771 for ( uint idx = 0; idx < numRings; idx++ )
5773 uint nPoints = *((
int* )ptr );
5778 for ( uint jdx = 0; jdx < nPoints; jdx++ )
5780 x = *((
double * ) ptr );
5781 y = *((
double * )( ptr +
sizeof(
double ) ) );
5783 ptr += 2 *
sizeof( double );
5786 ptr +=
sizeof( double );
5837 unsigned int nPoints = *((
int* )ptr );
5841 for ( uint i = 0; i < nPoints; i++ )
5843 points[i] =
asPoint( ptr, hasZValue );
5858 unsigned int numLineStrings = *((
int* )ptr );
5863 for ( uint i = 0; i < numLineStrings; i++ )
5880 unsigned int numPolygons = *((
int* )ptr );
5885 for ( uint i = 0; i < numPolygons; i++ )
5887 polygons[i] =
asPolygon( ptr, hasZValue );
5904 if ( GEOSArea(
mGeos, &area ) == 0 )
5923 if ( GEOSLength(
mGeos, &length ) == 0 )
6037 if ( !geometry->
mGeos )
6063 if ( !geometry->
mGeos )
6074 GEOSGeometry* unionGeom = GEOSUnion(
mGeos, geometry->
mGeos );
6080 GEOSGeometry* mergedGeom = GEOSLineMerge( unionGeom );
6083 GEOSGeom_destroy( unionGeom );
6084 unionGeom = mergedGeom;
6102 if ( !geometry->
mGeos )
6128 if ( !geometry->
mGeos )
6150 return QList<QgsGeometry*>();
6153 int type = GEOSGeomTypeId(
mGeos );
6154 QgsDebugMsg(
"geom type: " + QString::number( type ) );
6156 QList<QgsGeometry*> geomCollection;
6158 if ( type != GEOS_MULTIPOINT &&
6159 type != GEOS_MULTILINESTRING &&
6160 type != GEOS_MULTIPOLYGON &&
6161 type != GEOS_GEOMETRYCOLLECTION )
6164 geomCollection.append(
new QgsGeometry( *
this ) );
6165 return geomCollection;
6168 int count = GEOSGetNumGeometries(
mGeos );
6169 QgsDebugMsg(
"geom count: " + QString::number( count ) );
6171 for (
int i = 0; i < count; ++i )
6173 const GEOSGeometry * geometry = GEOSGetGeometryN(
mGeos, i );
6174 geomCollection.append(
fromGeosGeom( GEOSGeom_clone( geometry ) ) );
6177 return geomCollection;
6183 if ( ringNum <= 0 || partNum < 0 )
6195 if ( ringNum >= polygon.count() )
6198 polygon.remove( ringNum );
6211 if ( partNum >= mpolygon.count() )
6214 if ( ringNum >= mpolygon[partNum].count() )
6217 mpolygon[partNum].remove( ringNum );
6243 if ( partNum >= mpoint.size() || mpoint.size() == 1 )
6246 mpoint.remove( partNum );
6259 if ( partNum >= mline.size() || mline.size() == 1 )
6262 mline.remove( partNum );
6275 if ( partNum >= mpolygon.size() || mpolygon.size() == 1 )
6278 mpolygon.remove( partNum );
6296 int returnValue = 0;
6316 QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
6317 for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
6330 if (
wkbType() != geomTypeBeforeModification )
6350 return ( v.
x()*( q.
y() - p.
y() ) - v.
y()*( q.
x() - p.
x() ) ) / v.
length();
6355 double d = v.
y() * w.
x() - v.
x() * w.
y();
6360 double dx = q.
x() - p.
x();
6361 double dy = q.
y() - p.
y();
6362 double k = ( dy * w.
x() - dx * w.
y() ) / d;
6371 bool inside =
false;
6372 int j = ring.size() - 1;
6374 for (
int i = 0; i < ring.size(); i++ )
6376 if ( ring[i].x() == p.
x() && ring[i].y() == p.
y() )
6379 if (( ring[i].y() < p.
y() && ring[j].y() >= p.
y() ) ||
6380 ( ring[j].y() < p.
y() && ring[i].y() >= p.
y() ) )
6382 if ( ring[i].x() + ( p.
y() - ring[i].y() ) / ( ring[j].y() - ring[i].y() )*( ring[j].x() - ring[i].x() ) <= p.
x() )
6394 for (
int i = 0; i < inside.size(); i++ )
6407 for (
int i = 0; i < ring0.size() - 1; i++ )
6411 for (
int j = 0; j < ring1.size() - 1; j++ )
6420 if ( d >= 0 && d <= v.
length() )
6423 if ( d >= 0 && d <= w.
length() )
6425 QString msg = QObject::tr(
"segment %1 of ring %2 of polygon %3 intersects segment %4 of ring %5 of polygon %6 at %7" )
6426 .arg( i0 ).arg( i ).arg( p0 )
6427 .arg( i1 ).arg( j ).arg( p1 )
6430 errors <<
Error( msg, s );
6431 if ( errors.size() > 100 )
6433 QString msg = QObject::tr(
"stopping validation after more than 100 errors" );
6435 errors << Error( msg );
6449 if ( line.size() < 3 )
6451 QString msg = QObject::tr(
"ring %1 with less than three points" ).arg( i );
6453 errors <<
Error( msg );
6457 if ( line[0] != line[ line.size()-1 ] )
6459 QString msg = QObject::tr(
"ring %1 not closed" ).arg( i );
6461 errors <<
Error( msg );
6465 else if ( line.size() < 2 )
6467 QString msg = QObject::tr(
"line %1 with less than two points" ).arg( i );
6469 errors <<
Error( msg );
6474 while ( j < line.size() - 1 )
6477 while ( j < line.size() - 1 && line[j] == line[j+1] )
6485 QString msg = QObject::tr(
"line %1 contains %n duplicate node(s) at %2",
"number of duplicate nodes", n ).arg( i ).arg( j );
6487 errors <<
Error( msg, line[j] );
6493 for ( j = 0; j < line.size() - 3; j++ )
6498 int n = ( j == 0 && ring ) ? line.size() - 2 : line.size() - 1;
6500 for (
int k = j + 2; k < n; k++ )
6509 if ( d < 0 || d > vl )
6513 if ( d < 0 || d > w.
length() )
6516 QString msg = QObject::tr(
"segments %1 and %2 of line %3 intersect at %4" ).arg( j ).arg( k ).arg( i ).arg( s.
toString() );
6518 errors <<
Error( msg, s );
6519 if ( errors.size() > 100 )
6521 QString msg = QObject::tr(
"stopping validation after more than 100 errors" );
6523 errors << Error( msg );
6533 for (
int i = 1; i < polygon.size(); i++ )
6537 QString msg = QObject::tr(
"ring %1 of polygon %2 not in exterior ring" ).arg( i ).arg( idx );
6539 errors <<
Error( msg );
6544 for (
int i = 1; i < polygon.size(); i++ )
6546 for (
int j = i + 1; j < polygon.size(); j++ )
6553 for (
int i = 0; i < polygon.size(); i++ )
6580 for (
int i = 0; i < mp.size(); i++ )
6596 for (
int i = 0; i < mp.size(); i++ )
6601 for (
int i = 0; i < mp.size(); i++ )
6603 for (
int j = i + 1; j < mp.size(); j++ )
6607 errors <<
Error( QObject::tr(
"polygon %1 inside polygon %2" ).arg( i ).arg( j ) );
6611 errors <<
Error( QObject::tr(
"polygon %1 inside polygon %2" ).arg( j ).arg( i ) );
6624 QgsDebugMsg( QObject::tr(
"Unknown geometry type" ) );
6625 errors <<
Error( QObject::tr(
"Unknown geometry type" ) );
6634 GEOSGeometry *g =
asGeos();
6639 return GEOSisValid( g );
6645 QgsDebugMsg( QString(
"GEOS exception caught: %1" ).arg( e.
what() ) );
6652 return geosRelOp( GEOSEquals,
this, &g );
6659 GEOSGeometry *g =
asGeos();
6664 return GEOSisEmpty( g );
6670 QgsDebugMsg( QString(
"GEOS exception caught: %1" ).arg( e.
what() ) );