36 #include <netinet/in.h>
41 #define DEFAULT_QUADRANT_SEGMENTS 8
43 #define CATCH_GEOS(r) \
44 catch (GEOSException &e) \
46 QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr("GEOS") ); \
55 if ( theMsg ==
"Unknown exception thrown" &&
lastMsg.isNull() )
96 vsnprintf( buffer,
sizeof buffer, fmt, ap );
99 QgsDebugMsg( QString(
"GEOS exception: %1" ).arg( buffer ) );
106 #if defined(QGISDEBUG)
111 vsnprintf( buffer,
sizeof buffer, fmt, ap );
114 QgsDebugMsg( QString(
"GEOS notice: %1" ).arg( QString::fromUtf8( buffer ) ) );
137 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
138 #define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
139 #define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
140 #define GEOSGetNumInteriorRings(g) GEOSGetNumInteriorRings( (GEOSGeometry *)g )
141 #define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i )
142 #define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 )
143 #define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 )
144 #define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s )
145 #define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a )
146 #define GEOSTopologyPreserveSimplify(g, t) GEOSTopologyPreserveSimplify( (GEOSGeometry*) g, t )
147 #define GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g )
149 #define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
150 #define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
151 #define GEOSCoordSeq_getY(cs,i,y) GEOSCoordSeq_getY( (GEOSCoordSequence *)cs, i, y )
155 static GEOSGeometry *cloneGeosGeom(
const GEOSGeometry *geom )
159 int type = GEOSGeomTypeId(( GEOSGeometry * ) geom );
161 if ( type == GEOS_MULTIPOINT || type == GEOS_MULTILINESTRING || type == GEOS_MULTIPOLYGON )
163 QVector<GEOSGeometry *> geoms;
168 for (
int i = 0; i < GEOSGetNumGeometries(( GEOSGeometry * )geom ); ++i )
169 geoms << GEOSGeom_clone(( GEOSGeometry * ) GEOSGetGeometryN(( GEOSGeometry * ) geom, i ) );
176 for (
int i = 0; i < geoms.count(); i++ )
177 GEOSGeom_destroy( geoms[i] );
184 return GEOSGeom_clone(( GEOSGeometry * ) geom );
188 #define GEOSGeom_clone(g) cloneGeosGeom(g)
196 , mDirtyGeos( false )
202 , mGeometrySize( rhs.mGeometrySize )
203 , mDirtyWkb( rhs.mDirtyWkb )
204 , mDirtyGeos( rhs.mDirtyGeos )
233 GEOSGeom_destroy(
mGeos );
240 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom );
241 GEOSCoordSeq_getSize( cs, &n );
247 GEOSCoordSequence *coord = GEOSCoordSeq_create( 1, 2 );
248 GEOSCoordSeq_setX( coord, 0, point.
x() );
249 GEOSCoordSeq_setY( coord, 0, point.
y() );
250 return GEOSGeom_createPoint( coord );
255 GEOSCoordSequence *coord = 0;
259 coord = GEOSCoordSeq_create( points.count(), 2 );
261 for ( i = 0; i < points.count(); i++ )
263 GEOSCoordSeq_setX( coord, i, points[i].x() );
264 GEOSCoordSeq_setY( coord, i, points[i].y() );
279 GEOSGeometry **geomarr =
new GEOSGeometry*[ geoms.size()];
283 for (
int i = 0; i < geoms.size(); i++ )
284 geomarr[i] = geoms[i];
286 GEOSGeometry *geom = 0;
290 geom = GEOSGeom_createCollection( typeId, geomarr, geoms.size() );
304 GEOSCoordSequence *coord = 0;
309 return GEOSGeom_createLineString( coord );
323 GEOSCoordSequence *coord = 0;
325 if ( polyline.count() == 0 )
330 if ( polyline[0] != polyline[polyline.size()-1] )
342 return GEOSGeom_createLinearRing( coord );
358 if ( rings.size() == 0 )
360 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
361 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
362 return GEOSGeom_createEmptyPolygon();
364 shell = GEOSGeom_createLinearRing( GEOSCoordSeq_create( 0, 2 ) );
372 GEOSGeometry **holes = NULL;
375 if ( rings.size() > 1 )
377 nHoles = rings.size() - 1;
378 holes =
new GEOSGeometry*[ nHoles ];
382 for (
int i = 0; i < nHoles; i++ )
383 holes[i] = rings[i+1];
386 GEOSGeometry *geom = GEOSGeom_createPolygon( shell, holes, nHoles );
401 if ( polygon.count() == 0 )
404 QVector<GEOSGeometry *> geoms;
408 for (
int i = 0; i < polygon.count(); i++ )
416 for (
int i = 0; i < geoms.count(); i++ )
417 GEOSGeom_destroy( geoms[i] );
436 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR>=3)
437 GEOSWKTReader *reader = GEOSWKTReader_create();
439 GEOSWKTReader_destroy( reader );
442 return fromGeosGeom( GEOSGeomFromWKT( wkt.toLocal8Bit().data() ) );
469 QVector<GEOSGeometry *> geoms;
473 for (
int i = 0; i < multipoint.size(); ++i )
484 for (
int i = 0; i < geoms.size(); ++i )
485 GEOSGeom_destroy( geoms[i] );
493 QVector<GEOSGeometry *> geoms;
497 for (
int i = 0; i < multiline.count(); i++ )
506 for (
int i = 0; i < geoms.count(); i++ )
507 GEOSGeom_destroy( geoms[i] );
515 if ( multipoly.count() == 0 )
518 QVector<GEOSGeometry *> geoms;
522 for (
int i = 0; i < multipoly.count(); i++ )
531 for (
int i = 0; i < geoms.count(); i++ )
532 GEOSGeom_destroy( geoms[i] );
548 polygon.append( ring );
571 GEOSGeom_destroy(
mGeos );
597 GEOSGeom_destroy(
mGeos );
644 const unsigned char *geom =
asWkb();
648 memcpy( &wkbType, ( geom + 1 ),
sizeof( wkbType ) );
718 GEOSGeom_destroy(
mGeos );
748 int vertexcounter = 0;
753 double *tempx, *tempy;
754 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
757 bool hasZValue =
false;
765 y = *((
double * )(
mGeometry + 5 +
sizeof(
double ) ) );
766 actdist = point.
sqrDist( x, y );
778 int* npoints = (
int* )ptr;
779 ptr +=
sizeof( int );
780 for (
int index = 0; index < *npoints; ++index )
782 tempx = (
double* )ptr;
783 ptr +=
sizeof( double );
784 tempy = (
double* )ptr;
785 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
789 actdist = point.
sqrDist( *tempx, *tempy );
797 beforeVertex = index - 1;
799 if ( index == ( *npoints - 1 ) )
805 afterVertex = index + 1;
808 ptr +=
sizeof( double );
811 ptr +=
sizeof( double );
823 for (
int index = 0; index < *nrings; ++index )
825 npoints = (
int* )ptr;
826 ptr +=
sizeof( int );
827 for (
int index2 = 0; index2 < *npoints; ++index2 )
829 tempx = (
double* )ptr;
830 ptr +=
sizeof( double );
831 tempy = (
double* )ptr;
832 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
836 actdist = point.
sqrDist( *tempx, *tempy );
837 vertexnr = vertexcounter;
841 beforeVertex = vertexcounter + ( *npoints - 2 );
842 afterVertex = vertexcounter + 1;
844 else if ( index2 == ( *npoints - 1 ) )
846 beforeVertex = vertexcounter - 1;
847 afterVertex = vertexcounter - ( *npoints - 2 );
851 beforeVertex = vertexcounter - 1;
852 afterVertex = vertexcounter + 1;
855 ptr +=
sizeof( double );
858 ptr +=
sizeof( double );
870 int* npoints = (
int* )ptr;
871 ptr +=
sizeof( int );
872 for (
int index = 0; index < *npoints; ++index )
874 ptr += ( 1 +
sizeof( int ) );
875 tempx = (
double* )ptr;
876 tempy = (
double* )( ptr +
sizeof(
double ) );
877 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
881 actdist = point.
sqrDist( *tempx, *tempy );
884 ptr += ( 2 *
sizeof( double ) );
887 ptr +=
sizeof( double );
897 int* nlines = (
int* )ptr;
899 ptr +=
sizeof( int );
900 for (
int index = 0; index < *nlines; ++index )
902 ptr += (
sizeof( int ) + 1 );
903 npoints = (
int* )ptr;
904 ptr +=
sizeof( int );
905 for (
int index2 = 0; index2 < *npoints; ++index2 )
907 tempx = (
double* )ptr;
908 ptr +=
sizeof( double );
909 tempy = (
double* )ptr;
910 ptr +=
sizeof( double );
911 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
915 actdist = point.
sqrDist( *tempx, *tempy );
916 vertexnr = vertexcounter;
924 beforeVertex = vertexnr - 1;
926 if ( index2 == ( *npoints ) - 1 )
932 afterVertex = vertexnr + 1;
937 ptr +=
sizeof( double );
949 int* npolys = (
int* )ptr;
952 ptr +=
sizeof( int );
953 for (
int index = 0; index < *npolys; ++index )
955 ptr += ( 1 +
sizeof( int ) );
956 nrings = (
int* )ptr;
957 ptr +=
sizeof( int );
958 for (
int index2 = 0; index2 < *nrings; ++index2 )
960 npoints = (
int* )ptr;
961 ptr +=
sizeof( int );
962 for (
int index3 = 0; index3 < *npoints; ++index3 )
964 tempx = (
double* )ptr;
965 ptr +=
sizeof( double );
966 tempy = (
double* )ptr;
967 if ( point.
sqrDist( *tempx, *tempy ) < actdist )
971 actdist = point.
sqrDist( *tempx, *tempy );
972 vertexnr = vertexcounter;
977 beforeVertex = vertexcounter + ( *npoints - 2 );
978 afterVertex = vertexcounter + 1;
980 else if ( index3 == ( *npoints - 1 ) )
982 beforeVertex = vertexcounter - 1;
983 afterVertex = vertexcounter - ( *npoints - 2 );
987 beforeVertex = vertexcounter - 1;
988 afterVertex = vertexcounter + 1;
991 ptr +=
sizeof( double );
994 ptr +=
sizeof( double );
1006 atVertex = vertexnr;
1028 int vertexcounter = 0;
1031 bool hasZValue =
false;
1033 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
1046 int* npoints = (
int* ) ptr;
1048 const int index = atVertex;
1058 beforeVertex = index - 1;
1061 if ( index == ( *npoints - 1 ) )
1067 afterVertex = index + 1;
1076 int* nrings = (
int* )(
mGeometry + 5 );
1082 for (
int index0 = 0; index0 < *nrings; ++index0 )
1084 npoints = (
int* )ptr;
1085 ptr +=
sizeof( int );
1087 for (
int index1 = 0; index1 < *npoints; ++index1 )
1089 ptr +=
sizeof( double );
1090 ptr +=
sizeof( double );
1093 ptr +=
sizeof( double );
1095 if ( vertexcounter == atVertex )
1099 beforeVertex = vertexcounter + ( *npoints - 2 );
1100 afterVertex = vertexcounter + 1;
1102 else if ( index1 == ( *npoints - 1 ) )
1104 beforeVertex = vertexcounter - 1;
1105 afterVertex = vertexcounter - ( *npoints - 2 );
1109 beforeVertex = vertexcounter - 1;
1110 afterVertex = vertexcounter + 1;
1131 int* nlines = (
int* )ptr;
1133 ptr +=
sizeof( int );
1135 for (
int index0 = 0; index0 < *nlines; ++index0 )
1137 ptr += (
sizeof( int ) + 1 );
1138 npoints = (
int* )ptr;
1139 ptr +=
sizeof( int );
1141 for (
int index1 = 0; index1 < *npoints; ++index1 )
1143 ptr +=
sizeof( double );
1144 ptr +=
sizeof( double );
1147 ptr +=
sizeof( double );
1150 if ( vertexcounter == atVertex )
1159 beforeVertex = vertexcounter - 1;
1161 if ( index1 == ( *npoints ) - 1 )
1167 afterVertex = vertexcounter + 1;
1180 int* npolys = (
int* )ptr;
1183 ptr +=
sizeof( int );
1185 for (
int index0 = 0; index0 < *npolys; ++index0 )
1187 ptr += ( 1 +
sizeof( int ) );
1188 nrings = (
int* )ptr;
1189 ptr +=
sizeof( int );
1191 for (
int index1 = 0; index1 < *nrings; ++index1 )
1193 npoints = (
int* )ptr;
1194 ptr +=
sizeof( int );
1196 for (
int index2 = 0; index2 < *npoints; ++index2 )
1198 ptr +=
sizeof( double );
1199 ptr +=
sizeof( double );
1202 ptr +=
sizeof( double );
1204 if ( vertexcounter == atVertex )
1211 beforeVertex = vertexcounter + ( *npoints - 2 );
1212 afterVertex = vertexcounter + 1;
1214 else if ( index2 == ( *npoints - 1 ) )
1216 beforeVertex = vertexcounter - 1;
1217 afterVertex = vertexcounter - ( *npoints - 2 );
1221 beforeVertex = vertexcounter - 1;
1222 afterVertex = vertexcounter + 1;
1242 const GEOSCoordSequence* old_sequence,
1243 GEOSCoordSequence** new_sequence )
1247 if ( beforeVertex < 0 )
1253 unsigned int numPoints;
1254 GEOSCoordSeq_getSize( old_sequence, &numPoints );
1256 *new_sequence = GEOSCoordSeq_create( numPoints + 1, 2 );
1257 if ( !*new_sequence )
1260 bool inserted =
false;
1261 for (
unsigned int i = 0, j = 0; i < numPoints; i++, j++ )
1264 if ( beforeVertex == static_cast<int>( i ) )
1266 GEOSCoordSeq_setX( *new_sequence, j, x );
1267 GEOSCoordSeq_setY( *new_sequence, j, y );
1273 GEOSCoordSeq_getX( old_sequence, i, &aX );
1274 GEOSCoordSeq_getY( old_sequence, i, &aY );
1276 GEOSCoordSeq_setX( *new_sequence, j, aX );
1277 GEOSCoordSeq_setY( *new_sequence, j, aY );
1284 GEOSCoordSeq_setX( *new_sequence, numPoints, x );
1285 GEOSCoordSeq_setY( *new_sequence, numPoints, y );
1294 int vertexnr = atVertex;
1309 bool hasZValue =
false;
1311 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1319 if ( vertexnr == 0 )
1321 memcpy( ptr, &x,
sizeof(
double ) );
1322 ptr +=
sizeof( double );
1323 memcpy( ptr, &y,
sizeof(
double ) );
1336 int* nrPoints = (
int* )ptr;
1337 if ( vertexnr > *nrPoints || vertexnr < 0 )
1341 ptr +=
sizeof( int );
1344 ptr += ( 3 *
sizeof( double ) + 1 +
sizeof(
int ) ) * vertexnr;
1348 ptr += ( 2 *
sizeof( double ) + 1 +
sizeof(
int ) ) * vertexnr;
1350 ptr += ( 1 +
sizeof( int ) );
1351 memcpy( ptr, &x,
sizeof(
double ) );
1352 ptr +=
sizeof( double );
1353 memcpy( ptr, &y,
sizeof(
double ) );
1361 int* nrPoints = (
int* )ptr;
1362 if ( vertexnr > *nrPoints || vertexnr < 0 )
1366 ptr +=
sizeof( int );
1367 ptr += 2 *
sizeof( double ) * vertexnr;
1370 ptr +=
sizeof( double ) * vertexnr;
1372 memcpy( ptr, &x,
sizeof(
double ) );
1373 ptr +=
sizeof( double );
1374 memcpy( ptr, &y,
sizeof(
double ) );
1382 int* nrLines = (
int* )ptr;
1383 ptr +=
sizeof( int );
1386 for (
int linenr = 0; linenr < *nrLines; ++linenr )
1388 ptr +=
sizeof( int ) + 1;
1389 nrPoints = (
int* )ptr;
1390 ptr +=
sizeof( int );
1391 if ( vertexnr >= pointindex && vertexnr < pointindex + ( *nrPoints ) )
1393 ptr += ( vertexnr - pointindex ) * 2 *
sizeof(
double );
1396 ptr += ( vertexnr - pointindex ) *
sizeof(
double );
1398 memcpy( ptr, &x,
sizeof(
double ) );
1399 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1403 pointindex += ( *nrPoints );
1404 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1407 ptr +=
sizeof( double ) * ( *nrPoints );
1416 int* nrRings = (
int* )ptr;
1417 ptr +=
sizeof( int );
1421 for (
int ringnr = 0; ringnr < *nrRings; ++ringnr )
1423 nrPoints = (
int* )ptr;
1424 ptr +=
sizeof( int );
1425 if ( vertexnr == pointindex || vertexnr == pointindex + ( *nrPoints - 1 ) )
1427 memcpy( ptr, &x,
sizeof(
double ) );
1428 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1431 memcpy( ptr + 3*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1435 memcpy( ptr + 2*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1439 memcpy( ptr +
sizeof(
double ) + 3*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1443 memcpy( ptr +
sizeof(
double ) + 2*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1448 else if ( vertexnr > pointindex && vertexnr < pointindex + ( *nrPoints - 1 ) )
1450 ptr += 2 *
sizeof( double ) * ( vertexnr - pointindex );
1453 ptr +=
sizeof( double ) * ( vertexnr - pointindex );
1455 memcpy( ptr, &x,
sizeof(
double ) );
1456 ptr +=
sizeof( double );
1457 memcpy( ptr, &y,
sizeof(
double ) );
1461 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1464 ptr +=
sizeof( double ) * ( *nrPoints );
1466 pointindex += *nrPoints;
1474 int* nrPolygons = (
int* )ptr;
1475 ptr +=
sizeof( int );
1480 for (
int polynr = 0; polynr < *nrPolygons; ++polynr )
1482 ptr += ( 1 +
sizeof( int ) );
1483 nrRings = (
int* )ptr;
1484 ptr +=
sizeof( int );
1485 for (
int ringnr = 0; ringnr < *nrRings; ++ringnr )
1487 nrPoints = (
int* )ptr;
1488 ptr +=
sizeof( int );
1489 if ( vertexnr == pointindex || vertexnr == pointindex + ( *nrPoints - 1 ) )
1491 memcpy( ptr, &x,
sizeof(
double ) );
1492 memcpy( ptr +
sizeof(
double ), &y,
sizeof(
double ) );
1495 memcpy( ptr + 3*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1499 memcpy( ptr + 2*
sizeof(
double )*( *nrPoints - 1 ), &x,
sizeof(
double ) );
1503 memcpy( ptr +
sizeof(
double ) + 3*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1507 memcpy( ptr +
sizeof(
double ) + 2*
sizeof(
double )*( *nrPoints - 1 ), &y,
sizeof(
double ) );
1512 else if ( vertexnr > pointindex && vertexnr < pointindex + ( *nrPoints - 1 ) )
1514 ptr += 2 *
sizeof( double ) * ( vertexnr - pointindex );
1517 ptr +=
sizeof( double ) * ( vertexnr - pointindex );
1519 memcpy( ptr, &x,
sizeof(
double ) );
1520 ptr +=
sizeof( double );
1521 memcpy( ptr, &y,
sizeof(
double ) );
1525 ptr += 2 *
sizeof( double ) * ( *nrPoints );
1528 ptr +=
sizeof( double ) * ( *nrPoints );
1530 pointindex += *nrPoints;
1543 int vertexnr = atVertex;
1544 bool success =
false;
1559 unsigned char* newbuffer;
1562 bool hasZValue =
false;
1564 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1574 newbuffer =
new unsigned char[
mGeometrySize-3*
sizeof( double )];
1577 newbuffer =
new unsigned char[
mGeometrySize-2*
sizeof( double )];
1580 memcpy( newbuffer,
mGeometry, 1 +
sizeof(
int ) );
1583 unsigned char* newBufferPtr = newbuffer + 1 +
sizeof( int );
1603 int* nPoints = (
int* )ptr;
1604 if (( *nPoints ) < 3 || vertexnr > ( *nPoints ) - 1 || vertexnr < 0 )
1609 int newNPoints = ( *nPoints ) - 1;
1610 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1611 ptr +=
sizeof( int );
1612 newBufferPtr +=
sizeof( int );
1613 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1615 if ( vertexnr != pointindex )
1617 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1618 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1619 newBufferPtr += 2 *
sizeof( double );
1622 newBufferPtr +=
sizeof( double );
1629 ptr += 2 *
sizeof( double );
1632 ptr +=
sizeof( double );
1642 int* nLines = (
int* )ptr;
1643 memcpy( newBufferPtr, nLines,
sizeof(
int ) );
1644 newBufferPtr +=
sizeof( int );
1645 ptr +=
sizeof( int );
1648 for (
int linenr = 0; linenr < *nLines; ++linenr )
1650 memcpy( newBufferPtr, ptr,
sizeof(
int ) + 1 );
1651 ptr += (
sizeof( int ) + 1 );
1652 newBufferPtr += (
sizeof( int ) + 1 );
1653 nPoints = (
int* )ptr;
1654 ptr +=
sizeof( int );
1658 if ( vertexnr >= pointindex && vertexnr < pointindex + ( *nPoints ) )
1665 newNPoint = ( *nPoints ) - 1;
1669 newNPoint = *nPoints;
1671 memcpy( newBufferPtr, &newNPoint,
sizeof(
int ) );
1672 newBufferPtr +=
sizeof( int );
1674 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1676 if ( vertexnr != pointindex )
1678 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1679 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1680 newBufferPtr += 2 *
sizeof( double );
1683 newBufferPtr +=
sizeof( double );
1690 ptr += 2 *
sizeof( double );
1693 ptr +=
sizeof( double );
1704 int* nRings = (
int* )ptr;
1705 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
1706 ptr +=
sizeof( int );
1707 newBufferPtr +=
sizeof( int );
1711 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
1713 nPoints = (
int* )ptr;
1714 ptr +=
sizeof( int );
1716 if ( vertexnr >= pointindex && vertexnr < pointindex + *nPoints )
1723 newNPoints = *nPoints - 1;
1727 newNPoints = *nPoints;
1729 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1730 newBufferPtr +=
sizeof( int );
1732 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1734 if ( vertexnr != pointindex )
1736 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1737 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1738 newBufferPtr += 2 *
sizeof( double );
1741 newBufferPtr +=
sizeof( double );
1748 memcpy( ptr + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 2*
sizeof(
double ),
sizeof(
double ) );
1749 memcpy( ptr +
sizeof(
double ) + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 3*
sizeof(
double ),
sizeof(
double ) );
1751 if ( pointnr == ( *nPoints ) - 1 )
1753 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ), ptr - 2*
sizeof(
double ),
sizeof(
double ) );
1754 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ) +
sizeof(
double ), ptr -
sizeof(
double ),
sizeof(
double ) );
1758 ptr += 2 *
sizeof( double );
1761 ptr +=
sizeof( double );
1772 int* nPolys = (
int* )ptr;
1773 memcpy( newBufferPtr, nPolys,
sizeof(
int ) );
1774 newBufferPtr +=
sizeof( int );
1775 ptr +=
sizeof( int );
1780 for (
int polynr = 0; polynr < *nPolys; ++polynr )
1782 memcpy( newBufferPtr, ptr, ( 1 +
sizeof(
int ) ) );
1783 ptr += ( 1 +
sizeof( int ) );
1784 newBufferPtr += ( 1 +
sizeof( int ) );
1785 nRings = (
int* )ptr;
1786 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
1787 newBufferPtr +=
sizeof( int );
1788 ptr +=
sizeof( int );
1789 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
1791 nPoints = (
int* )ptr;
1792 ptr +=
sizeof( int );
1794 if ( vertexnr >= pointindex && vertexnr < pointindex + *nPoints )
1801 newNPoints = *nPoints - 1;
1805 newNPoints = *nPoints;
1807 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1808 newBufferPtr +=
sizeof( int );
1810 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1812 if ( vertexnr != pointindex )
1814 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1815 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1816 newBufferPtr += 2 *
sizeof( double );
1819 newBufferPtr +=
sizeof( double );
1826 memcpy( ptr + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 2*
sizeof(
double ),
sizeof(
double ) );
1827 memcpy( ptr +
sizeof(
double ) + ( *nPoints - 1 )*2*
sizeof(
double ), ptr + 3*
sizeof(
double ),
sizeof(
double ) );
1829 if ( pointnr == ( *nPoints ) - 1 )
1831 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ), ptr - 2*
sizeof(
double ),
sizeof(
double ) );
1832 memcpy( newBufferPtr - ( *nPoints - 1 )*2*
sizeof(
double ) +
sizeof(
double ), ptr -
sizeof(
double ),
sizeof(
double ) );
1836 ptr += 2 *
sizeof( double );
1839 ptr +=
sizeof( double );
1872 int vertexnr = beforeVertex;
1873 bool success =
false;
1888 unsigned char* newbuffer;
1892 bool hasZValue =
false;
1895 memcpy( &wkbType, ptr,
sizeof( wkbType ) );
1905 newbuffer =
new unsigned char[
mGeometrySize+3*
sizeof( double )];
1908 newbuffer =
new unsigned char[
mGeometrySize+2*
sizeof( double )];
1910 memcpy( newbuffer,
mGeometry, 1 +
sizeof(
int ) );
1913 unsigned char* newBufferPtr = newbuffer + 1 +
sizeof( int );
1934 int* nPoints = (
int* )ptr;
1935 if ( vertexnr > *nPoints || vertexnr < 0 )
1939 int newNPoints = ( *nPoints ) + 1;
1940 memcpy( newBufferPtr, &newNPoints,
sizeof(
int ) );
1941 newBufferPtr +=
sizeof( int );
1942 ptr +=
sizeof( int );
1944 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
1946 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
1947 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
1948 ptr += 2 *
sizeof( double );
1951 ptr +=
sizeof( double );
1953 newBufferPtr += 2 *
sizeof( double );
1956 newBufferPtr +=
sizeof( double );
1959 if ( pointindex == vertexnr )
1961 memcpy( newBufferPtr, &x,
sizeof(
double ) );
1962 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
1963 newBufferPtr += 2 *
sizeof( double );
1966 newBufferPtr +=
sizeof( double );
1977 int* nLines = (
int* )ptr;
1979 ptr +=
sizeof( int );
1980 memcpy( newBufferPtr, nLines,
sizeof(
int ) );
1981 newBufferPtr +=
sizeof( int );
1984 for (
int linenr = 0; linenr < *nLines; ++linenr )
1986 memcpy( newBufferPtr, ptr,
sizeof(
int ) + 1 );
1987 ptr += (
sizeof( int ) + 1 );
1988 newBufferPtr += (
sizeof( int ) + 1 );
1989 nPoints = (
int* )ptr;
1991 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
1993 newNPoints = ( *nPoints ) + 1;
1997 newNPoints = *nPoints;
1999 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
2000 newBufferPtr +=
sizeof( int );
2001 ptr +=
sizeof( int );
2003 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2005 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
2006 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
2007 ptr += 2 *
sizeof( double );
2008 newBufferPtr += 2 *
sizeof( double );
2011 ptr +=
sizeof( double );
2012 newBufferPtr +=
sizeof( double );
2015 if ( pointindex == vertexnr )
2017 memcpy( newBufferPtr, &x,
sizeof(
double ) );
2018 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
2019 newBufferPtr += 2 *
sizeof( double );
2022 newBufferPtr +=
sizeof( double );
2034 int* nRings = (
int* )ptr;
2036 ptr +=
sizeof( int );
2037 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
2038 newBufferPtr +=
sizeof( int );
2041 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2043 nPoints = (
int* )ptr;
2045 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
2047 newNPoints = ( *nPoints ) + 1;
2051 newNPoints = *nPoints;
2053 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
2054 newBufferPtr +=
sizeof( int );
2055 ptr +=
sizeof( int );
2057 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2059 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
2060 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
2061 ptr += 2 *
sizeof( double );
2062 newBufferPtr += 2 *
sizeof( double );
2065 ptr +=
sizeof( double );
2066 newBufferPtr +=
sizeof( double );
2069 if ( pointindex == vertexnr )
2071 memcpy( newBufferPtr, &x,
sizeof(
double ) );
2072 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
2073 newBufferPtr += 2 *
sizeof( double );
2076 newBufferPtr +=
sizeof( double );
2088 int* nPolys = (
int* )ptr;
2091 memcpy( newBufferPtr, nPolys,
sizeof(
int ) );
2092 ptr +=
sizeof( int );
2093 newBufferPtr +=
sizeof( int );
2096 for (
int polynr = 0; polynr < *nPolys; ++polynr )
2098 memcpy( newBufferPtr, ptr, ( 1 +
sizeof(
int ) ) );
2099 ptr += ( 1 +
sizeof( int ) );
2100 newBufferPtr += ( 1 +
sizeof( int ) );
2101 nRings = (
int* )ptr;
2102 ptr +=
sizeof( int );
2103 memcpy( newBufferPtr, nRings,
sizeof(
int ) );
2104 newBufferPtr +=
sizeof( int );
2106 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2108 nPoints = (
int* )ptr;
2110 if ( vertexnr >= pointindex && vertexnr < ( pointindex + ( *nPoints ) ) )
2112 newNPoints = ( *nPoints ) + 1;
2116 newNPoints = *nPoints;
2118 memcpy( newBufferPtr, &newNPoints,
sizeof(
double ) );
2119 newBufferPtr +=
sizeof( int );
2120 ptr +=
sizeof( int );
2122 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2124 memcpy( newBufferPtr, ptr,
sizeof(
double ) );
2125 memcpy( newBufferPtr +
sizeof(
double ), ptr +
sizeof(
double ),
sizeof(
double ) );
2126 ptr += 2 *
sizeof( double );
2127 newBufferPtr += 2 *
sizeof( double );
2130 ptr +=
sizeof( double );
2131 newBufferPtr +=
sizeof( double );
2134 if ( pointindex == vertexnr )
2136 memcpy( newBufferPtr, &x,
sizeof(
double ) );
2137 memcpy( newBufferPtr +
sizeof(
double ), &y,
sizeof(
double ) );
2138 newBufferPtr += 2 *
sizeof( double );
2141 newBufferPtr +=
sizeof( double );
2191 bool hasZValue =
false;
2194 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
2200 if ( atVertex == 0 )
2203 memcpy( &x, ptr,
sizeof(
double ) );
2204 ptr +=
sizeof( double );
2205 memcpy( &y, ptr,
sizeof(
double ) );
2220 nPoints = (
int * ) ptr;
2223 if ( 0 > atVertex || *nPoints <= atVertex )
2231 ptr =
mGeometry + 9 + ( atVertex * 3 *
sizeof( double ) );
2235 ptr =
mGeometry + 9 + ( atVertex * 2 *
sizeof( double ) );
2237 memcpy( &x, ptr,
sizeof(
double ) );
2238 ptr +=
sizeof( double );
2239 memcpy( &y, ptr,
sizeof(
double ) );
2249 nRings = (
int* )ptr;
2250 ptr +=
sizeof( int );
2252 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2254 nPoints = (
int* )ptr;
2255 ptr +=
sizeof( int );
2256 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2258 if ( pointindex == atVertex )
2260 memcpy( &x, ptr,
sizeof(
double ) );
2261 ptr +=
sizeof( double );
2262 memcpy( &y, ptr,
sizeof(
double ) );
2265 ptr += 2 *
sizeof( double );
2268 ptr +=
sizeof( double );
2280 int* nPoints = (
int* )ptr;
2281 if ( atVertex < 0 || atVertex >= *nPoints )
2287 ptr += atVertex * ( 3 *
sizeof( double ) + 1 +
sizeof(
int ) );
2291 ptr += atVertex * ( 2 *
sizeof( double ) + 1 +
sizeof(
int ) );
2293 ptr += 1 +
sizeof( int );
2294 memcpy( &x, ptr,
sizeof(
double ) );
2295 ptr +=
sizeof( double );
2296 memcpy( &y, ptr,
sizeof(
double ) );
2304 int* nLines = (
int* )ptr;
2307 ptr +=
sizeof( int );
2308 for (
int linenr = 0; linenr < *nLines; ++linenr )
2310 ptr +=
sizeof( int ) + 1;
2311 nPoints = (
int* )ptr;
2312 ptr +=
sizeof( int );
2313 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2315 if ( pointindex == atVertex )
2317 memcpy( &x, ptr,
sizeof(
double ) );
2318 ptr +=
sizeof( double );
2319 memcpy( &y, ptr,
sizeof(
double ) );
2322 ptr += 2 *
sizeof( double );
2325 ptr +=
sizeof( double );
2340 int* nPolygons = (
int* )ptr;
2341 ptr +=
sizeof( int );
2342 for (
int polynr = 0; polynr < *nPolygons; ++polynr )
2344 ptr += ( 1 +
sizeof( int ) );
2345 nRings = (
int* )ptr;
2346 ptr +=
sizeof( int );
2347 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2349 nPoints = (
int* )ptr;
2350 ptr +=
sizeof( int );
2351 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2353 if ( pointindex == atVertex )
2355 memcpy( &x, ptr,
sizeof(
double ) );
2356 ptr +=
sizeof( double );
2357 memcpy( &y, ptr,
sizeof(
double ) );
2361 ptr += 2 *
sizeof( double );
2364 ptr +=
sizeof( double );
2372 QgsDebugMsg(
"error: mGeometry type not recognized" );
2388 QgsDebugMsg(
"Exiting with std::numeric_limits<double>::max()." );
2402 int closestVertexIndex = 0;
2415 const GEOSGeometry *g = GEOSGetExteriorRing(
mGeos );
2419 const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g );
2422 GEOSCoordSeq_getSize( sequence, &n );
2424 for (
unsigned int i = 0; i < n; i++ )
2427 GEOSCoordSeq_getX( sequence, i, &x );
2428 GEOSCoordSeq_getY( sequence, i, &y );
2430 double testDist = point.
sqrDist( x, y );
2431 if ( testDist < sqrDist )
2433 closestVertexIndex = i;
2438 atVertex = closestVertexIndex;
2461 bool hasZValue =
false;
2462 double *thisx = NULL;
2463 double *thisy = NULL;
2464 double *prevx = NULL;
2465 double *prevy = NULL;
2467 int closestSegmentIndex = 0;
2484 memcpy( &wkbType, (
mGeometry + 1 ),
sizeof(
int ) );
2500 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2501 int* npoints = (
int* ) ptr;
2502 ptr +=
sizeof( int );
2503 for (
int index = 0; index < *npoints; ++index )
2510 thisx = (
double* ) ptr;
2511 ptr +=
sizeof( double );
2512 thisy = (
double* ) ptr;
2516 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint, epsilon ) ) < sqrDist )
2518 closestSegmentIndex = index;
2520 minDistPoint = distPoint;
2527 ptr +=
sizeof( double );
2530 ptr +=
sizeof( double );
2533 afterVertex = closestSegmentIndex;
2540 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2541 int* nLines = (
int* )ptr;
2542 ptr +=
sizeof( int );
2545 for (
int linenr = 0; linenr < *nLines; ++linenr )
2547 ptr +=
sizeof( int ) + 1;
2548 nPoints = (
int* )ptr;
2549 ptr +=
sizeof( int );
2552 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2554 thisx = (
double* ) ptr;
2555 ptr +=
sizeof( double );
2556 thisy = (
double* ) ptr;
2557 ptr +=
sizeof( double );
2560 ptr +=
sizeof( double );
2562 if ( prevx && prevy )
2564 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint, epsilon ) ) < sqrDist )
2566 closestSegmentIndex = pointindex;
2568 minDistPoint = distPoint;
2580 afterVertex = closestSegmentIndex;
2588 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2589 int* nrings = (
int* )ptr;
2591 ptr +=
sizeof( int );
2592 for (
int ringnr = 0; ringnr < *nrings; ++ringnr )
2594 npoints = (
int* )ptr;
2595 ptr +=
sizeof( int );
2598 for (
int pointnr = 0; pointnr < *npoints; ++pointnr )
2600 thisx = (
double* )ptr;
2601 ptr +=
sizeof( double );
2602 thisy = (
double* )ptr;
2603 ptr +=
sizeof( double );
2606 ptr +=
sizeof( double );
2608 if ( prevx && prevy )
2610 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint, epsilon ) ) < sqrDist )
2612 closestSegmentIndex = index;
2614 minDistPoint = distPoint;
2626 afterVertex = closestSegmentIndex;
2633 unsigned char* ptr =
mGeometry + 1 +
sizeof( int );
2637 int* nPolygons = (
int* )ptr;
2638 ptr +=
sizeof( int );
2639 for (
int polynr = 0; polynr < *nPolygons; ++polynr )
2641 ptr += ( 1 +
sizeof( int ) );
2642 nRings = (
int* )ptr;
2643 ptr +=
sizeof( int );
2644 for (
int ringnr = 0; ringnr < *nRings; ++ringnr )
2646 nPoints = (
int* )ptr;
2647 ptr +=
sizeof( int );
2650 for (
int pointnr = 0; pointnr < *nPoints; ++pointnr )
2652 thisx = (
double* )ptr;
2653 ptr +=
sizeof( double );
2654 thisy = (
double* )ptr;
2655 ptr +=
sizeof( double );
2658 ptr +=
sizeof( double );
2660 if ( prevx && prevy )
2662 if (( testdist = point.
sqrDistToSegment( *prevx, *prevy, *thisx, *thisy, distPoint, epsilon ) ) < sqrDist )
2664 closestSegmentIndex = pointindex;
2666 minDistPoint = distPoint;
2679 afterVertex = closestSegmentIndex;
2689 QgsDebugMsg( QString(
"Exiting with nearest point %1, dist %2." )
2690 .arg( point.
toString() ).arg( sqrDist ) );
2702 if ( ring.size() < 4 )
2706 if ( ring.first() != ring.last() )
2720 int type = GEOSGeomTypeId(
mGeos );
2723 QVector<const GEOSGeometry*> polygonList;
2727 if ( type != GEOS_POLYGON )
2730 polygonList <<
mGeos;
2734 if ( type != GEOS_MULTIPOLYGON )
2737 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); ++i )
2738 polygonList << GEOSGetGeometryN(
mGeos, i );
2742 GEOSGeometry *newRing = 0;
2743 GEOSGeometry *newRingPolygon = 0;
2748 if ( !GEOSisValid( newRing ) )
2754 if ( !GEOSisValid( newRingPolygon ) )
2763 if ( newRingPolygon )
2764 GEOSGeom_destroy( newRingPolygon );
2766 GEOSGeom_destroy( newRing );
2771 QVector<GEOSGeometry*> rings;
2774 for ( i = 0; i < polygonList.size(); i++ )
2776 for (
int j = 0; j < rings.size(); j++ )
2777 GEOSGeom_destroy( rings[j] );
2780 GEOSGeometry *shellRing = 0;
2781 GEOSGeometry *shell = 0;
2784 shellRing = GEOSGeom_clone( GEOSGetExteriorRing( polygonList[i] ) );
2787 if ( !GEOSWithin( newRingPolygon, shell ) )
2789 GEOSGeom_destroy( shell );
2798 GEOSGeom_destroy( shell );
2799 else if ( shellRing )
2800 GEOSGeom_destroy( shellRing );
2802 GEOSGeom_destroy( newRingPolygon );
2808 rings << GEOSGeom_clone( shellRing );
2810 GEOSGeom_destroy( shell );
2813 int n = GEOSGetNumInteriorRings( polygonList[i] );
2816 for ( j = 0; j < n; j++ )
2818 GEOSGeometry *holeRing = 0;
2819 GEOSGeometry *hole = 0;
2822 holeRing = GEOSGeom_clone( GEOSGetInteriorRingN( polygonList[i], j ) );
2825 if ( !GEOSDisjoint( hole, newRingPolygon ) )
2827 GEOSGeom_destroy( hole );
2836 GEOSGeom_destroy( hole );
2837 else if ( holeRing )
2838 GEOSGeom_destroy( holeRing );
2843 rings << GEOSGeom_clone( holeRing );
2844 GEOSGeom_destroy( hole );
2852 if ( i == polygonList.size() )
2855 for (
int j = 0; j < rings.size(); j++ )
2856 GEOSGeom_destroy( rings[j] );
2859 GEOSGeom_destroy( newRingPolygon );
2865 rings << GEOSGeom_clone( newRing );
2866 GEOSGeom_destroy( newRingPolygon );
2872 GEOSGeom_destroy(
mGeos );
2877 QVector<GEOSGeometry*> newPolygons;
2879 for (
int j = 0; j < polygonList.size(); j++ )
2881 newPolygons << ( i == j ? newPolygon : GEOSGeom_clone( polygonList[j] ) );
2884 GEOSGeom_destroy(
mGeos );
2901 if ( points.size() != 1 )
2903 QgsDebugMsg(
"expected 1 point: " + QString::number( points.size() ) );
2910 if ( points.size() < 3 )
2912 QgsDebugMsg(
"line must at least have two points: " + QString::number( points.size() ) );
2919 if ( points.size() < 4 )
2921 QgsDebugMsg(
"polygon must at least have three points: " + QString::number( points.size() ) );
2926 if ( points.first() != points.last() )
2934 QgsDebugMsg(
"unsupported geometry type: " + QString::number( geomType ) );
2956 int geosType = GEOSGeomTypeId(
mGeos );
2957 GEOSGeometry *newPart = 0;
2972 GEOSGeometry *newRing = 0;
2977 if ( !GEOSisValid( newRing ) )
2987 GEOSGeom_destroy( newRing );
2999 Q_ASSERT( newPart );
3003 if ( !GEOSisValid( newPart ) )
3011 GEOSGeom_destroy( newPart );
3017 QVector<GEOSGeometry*> parts;
3020 int n = GEOSGetNumGeometries(
mGeos );
3022 for ( i = 0; i < n; ++i )
3024 const GEOSGeometry *partN = GEOSGetGeometryN(
mGeos, i );
3026 if ( geomType ==
QGis::Polygon && !GEOSDisjoint( partN, newPart ) )
3030 parts << GEOSGeom_clone( partN );
3036 for (
int i = 0; i < parts.size(); i++ )
3037 GEOSGeom_destroy( parts[i] );
3045 GEOSGeom_destroy(
mGeos );
3069 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3070 bool hasZValue =
false;
3071 int wkbPosition = 5;
3086 int* npoints = (
int* )( &
mGeometry[wkbPosition] );
3087 wkbPosition +=
sizeof( int );
3088 for (
int index = 0; index < *npoints; ++index )
3099 int* nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3100 wkbPosition +=
sizeof( int );
3103 for (
int index = 0; index < *nrings; ++index )
3105 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3106 wkbPosition +=
sizeof( int );
3107 for (
int index2 = 0; index2 < *npoints; ++index2 )
3119 int* npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3120 wkbPosition +=
sizeof( int );
3121 for (
int index = 0; index < *npoints; ++index )
3123 wkbPosition += (
sizeof( int ) + 1 );
3133 int* nlines = (
int* )( &(
mGeometry[wkbPosition] ) );
3135 wkbPosition +=
sizeof( int );
3136 for (
int index = 0; index < *nlines; ++index )
3138 wkbPosition += (
sizeof( int ) + 1 );
3139 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3140 wkbPosition +=
sizeof( int );
3141 for (
int index2 = 0; index2 < *npoints; ++index2 )
3153 int* npolys = (
int* )( &(
mGeometry[wkbPosition] ) );
3156 wkbPosition +=
sizeof( int );
3157 for (
int index = 0; index < *npolys; ++index )
3159 wkbPosition += ( 1 +
sizeof( int ) );
3160 nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3161 wkbPosition +=
sizeof( int );
3162 for (
int index2 = 0; index2 < *nrings; ++index2 )
3164 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3165 wkbPosition +=
sizeof( int );
3166 for (
int index3 = 0; index3 < *npoints; ++index3 )
3195 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3196 bool hasZValue =
false;
3197 int wkbPosition = 5;
3212 int* npoints = (
int* )( &
mGeometry[wkbPosition] );
3213 wkbPosition +=
sizeof( int );
3214 for (
int index = 0; index < *npoints; ++index )
3225 int* nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3226 wkbPosition +=
sizeof( int );
3229 for (
int index = 0; index < *nrings; ++index )
3231 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3232 wkbPosition +=
sizeof( int );
3233 for (
int index2 = 0; index2 < *npoints; ++index2 )
3245 int* npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3246 wkbPosition +=
sizeof( int );
3247 for (
int index = 0; index < *npoints; ++index )
3249 wkbPosition += (
sizeof( int ) + 1 );
3259 int* nlines = (
int* )( &(
mGeometry[wkbPosition] ) );
3261 wkbPosition +=
sizeof( int );
3262 for (
int index = 0; index < *nlines; ++index )
3264 wkbPosition += (
sizeof( int ) + 1 );
3265 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3266 wkbPosition +=
sizeof( int );
3267 for (
int index2 = 0; index2 < *npoints; ++index2 )
3279 int* npolys = (
int* )( &(
mGeometry[wkbPosition] ) );
3282 wkbPosition +=
sizeof( int );
3283 for (
int index = 0; index < *npolys; ++index )
3285 wkbPosition += ( 1 +
sizeof( int ) );
3286 nrings = (
int* )( &(
mGeometry[wkbPosition] ) );
3287 wkbPosition +=
sizeof( int );
3288 for (
int index2 = 0; index2 < *nrings; ++index2 )
3290 npoints = (
int* )( &(
mGeometry[wkbPosition] ) );
3291 wkbPosition +=
sizeof( int );
3292 for (
int index3 = 0; index3 < *npoints; ++index3 )
3307 int QgsGeometry::splitGeometry(
const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries,
bool topological, QList<QgsPoint> &topologyTestPoints )
3333 if ( !GEOSisValid(
mGeos ) )
3339 if ( splitLine.size() < 2 )
3344 newGeometries.clear();
3349 if ( !GEOSisValid( splitLineGeos ) || !GEOSisSimple( splitLineGeos ) )
3351 GEOSGeom_destroy( splitLineGeos );
3368 GEOSGeom_destroy( splitLineGeos );
3373 GEOSGeom_destroy( splitLineGeos );
3388 if ( reshapeWithLine.size() < 2 )
3412 int numGeoms = GEOSGetNumGeometries(
mGeos );
3413 if ( numGeoms == -1 )
3418 bool isMultiGeom =
false;
3419 int geosTypeId = GEOSGeomTypeId(
mGeos );
3420 if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON )
3430 GEOSGeometry* reshapedGeometry;
3440 GEOSGeom_destroy( reshapeLineGeos );
3441 if ( reshapedGeometry )
3443 GEOSGeom_destroy(
mGeos );
3444 mGeos = reshapedGeometry;
3456 bool reshapeTookPlace =
false;
3458 GEOSGeometry* currentReshapeGeometry = 0;
3459 GEOSGeometry** newGeoms =
new GEOSGeometry*[numGeoms];
3461 for (
int i = 0; i < numGeoms; ++i )
3465 currentReshapeGeometry =
reshapeLine( GEOSGetGeometryN(
mGeos, i ), reshapeLineGeos );
3472 if ( currentReshapeGeometry )
3474 newGeoms[i] = currentReshapeGeometry;
3475 reshapeTookPlace =
true;
3479 newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN(
mGeos, i ) );
3482 GEOSGeom_destroy( reshapeLineGeos );
3484 GEOSGeometry* newMultiGeom = 0;
3487 newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms );
3491 newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms );
3495 if ( ! newMultiGeom )
3500 if ( reshapeTookPlace )
3502 GEOSGeom_destroy(
mGeos );
3503 mGeos = newMultiGeom;
3509 GEOSGeom_destroy( newMultiGeom );
3528 if ( !GEOSisValid(
mGeos ) )
3533 if ( !GEOSisSimple(
mGeos ) )
3544 if ( !other->
mGeos )
3599 bool hasZValue =
false;
3618 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
3624 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
3647 nPoints = (
int * ) ptr;
3648 ptr +=
sizeof( int );
3649 for ( idx = 0; idx < *nPoints; idx++ )
3651 ptr += ( 1 +
sizeof( int ) );
3652 x = (
double * ) ptr;
3653 ptr +=
sizeof( double );
3654 y = (
double * ) ptr;
3655 ptr +=
sizeof( double );
3658 ptr +=
sizeof( double );
3685 nPoints = (
int * ) ptr;
3686 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3687 for ( idx = 0; idx < *nPoints; idx++ )
3689 x = (
double * ) ptr;
3690 ptr +=
sizeof( double );
3691 y = (
double * ) ptr;
3692 ptr +=
sizeof( double );
3695 ptr +=
sizeof( double );
3720 numLineStrings = ( int )(
mGeometry[5] );
3722 for ( jdx = 0; jdx < numLineStrings; jdx++ )
3726 nPoints = (
int * ) ptr;
3727 ptr +=
sizeof( int );
3728 for ( idx = 0; idx < *nPoints; idx++ )
3730 x = (
double * ) ptr;
3731 ptr +=
sizeof( double );
3732 y = (
double * ) ptr;
3733 ptr +=
sizeof( double );
3736 ptr +=
sizeof( double );
3763 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
3764 ptr =
mGeometry + 1 + 2 *
sizeof( int );
3765 for ( idx = 0; idx < *numRings; idx++ )
3768 nPoints = (
int * ) ptr;
3770 for ( jdx = 0; jdx < *nPoints; jdx++ )
3773 x = (
double * ) ptr;
3774 ptr +=
sizeof( double );
3775 y = (
double * ) ptr;
3776 ptr +=
sizeof( double );
3779 ptr +=
sizeof( double );
3807 numPolygons = (
int * ) ptr;
3810 for ( kdx = 0; kdx < *numPolygons; kdx++ )
3815 numRings = (
int * ) ptr;
3817 for ( idx = 0; idx < *numRings; idx++ )
3820 nPoints = (
int * ) ptr;
3822 for ( jdx = 0; jdx < *nPoints; jdx++ )
3825 x = (
double * ) ptr;
3826 ptr +=
sizeof( double );
3827 y = (
double * ) ptr;
3828 ptr +=
sizeof( double );
3831 ptr +=
sizeof( double );
3856 QgsDebugMsg( QString(
"Unknown WkbType %1 ENCOUNTERED" ).arg( wkbType ) );
3886 return GEOSIntersects(
mGeos, geometry->
mGeos );
3902 GEOSGeometry *geosPoint = 0;
3904 bool returnval =
false;
3909 returnval = GEOSContains(
mGeos, geosPoint );
3918 GEOSGeom_destroy( geosPoint );
3924 char( *op )(
const GEOSGeometry*,
const GEOSGeometry * ),
3946 return geosRelOp( GEOSContains,
this, geometry );
3951 return geosRelOp( GEOSDisjoint,
this, geometry );
3956 return geosRelOp( GEOSEquals,
this, geometry );
3961 return geosRelOp( GEOSTouches,
this, geometry );
3966 return geosRelOp( GEOSOverlaps,
this, geometry );
3971 return geosRelOp( GEOSWithin,
this, geometry );
3976 return geosRelOp( GEOSCrosses,
this, geometry );
3991 QgsDebugMsg(
"WKB geometry not available or too short!" );
3992 return QString::null;
3996 bool hasZValue =
false;
4003 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
4014 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
4029 mWkt +=
"LINESTRING(";
4032 nPoints = (
int * ) ptr;
4033 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4034 for ( idx = 0; idx < *nPoints; ++idx )
4040 x = (
double * ) ptr;
4043 ptr +=
sizeof( double );
4044 y = (
double * ) ptr;
4046 ptr +=
sizeof( double );
4049 ptr +=
sizeof( double );
4063 int *numRings, *nPoints;
4067 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
4068 if ( !( *numRings ) )
4074 ringStart =
new int[*numRings];
4075 ringNumPoints =
new int[*numRings];
4076 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4077 for ( idx = 0; idx < *numRings; idx++ )
4085 nPoints = (
int * ) ptr;
4086 ringNumPoints[idx] = *nPoints;
4089 for ( jdx = 0; jdx < *nPoints; jdx++ )
4095 x = (
double * ) ptr;
4098 ptr +=
sizeof( double );
4099 y = (
double * ) ptr;
4101 ptr +=
sizeof( double );
4104 ptr +=
sizeof( double );
4110 delete [] ringStart;
4111 delete [] ringNumPoints;
4123 mWkt +=
"MULTIPOINT(";
4126 for ( idx = 0; idx < *nPoints; ++idx )
4128 ptr += ( 1 +
sizeof( int ) );
4133 x = (
double * )( ptr );
4136 ptr +=
sizeof( double );
4137 y = (
double * )( ptr );
4139 ptr +=
sizeof( double );
4142 ptr +=
sizeof( double );
4155 int idx, jdx, numLineStrings;
4158 mWkt +=
"MULTILINESTRING(";
4159 numLineStrings = ( int )(
mGeometry[5] );
4161 for ( jdx = 0; jdx < numLineStrings; jdx++ )
4169 nPoints = (
int * ) ptr;
4170 ptr +=
sizeof( int );
4171 for ( idx = 0; idx < *nPoints; idx++ )
4177 x = (
double * ) ptr;
4179 ptr +=
sizeof( double );
4181 y = (
double * ) ptr;
4183 ptr +=
sizeof( double );
4186 ptr +=
sizeof( double );
4202 int *numPolygons, *numRings, *nPoints;
4204 mWkt +=
"MULTIPOLYGON(";
4206 numPolygons = (
int * ) ptr;
4208 for ( kdx = 0; kdx < *numPolygons; kdx++ )
4216 numRings = (
int * ) ptr;
4218 for ( idx = 0; idx < *numRings; idx++ )
4225 nPoints = (
int * ) ptr;
4227 for ( jdx = 0; jdx < *nPoints; jdx++ )
4233 x = (
double * ) ptr;
4235 ptr +=
sizeof( double );
4237 y = (
double * ) ptr;
4239 ptr +=
sizeof( double );
4242 ptr +=
sizeof( double );
4254 QgsDebugMsg(
"error: mGeometry type not recognized" );
4255 return QString::null;
4272 return QString::null;
4276 bool hasZValue =
false;
4283 memcpy( &wkbType, &(
mGeometry[1] ),
sizeof(
int ) );
4290 mWkt +=
"{ \"type\": \"Point\", \"coordinates\": [";
4294 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
4309 mWkt +=
"{ \"type\": \"LineString\", \"coordinates\": [ ";
4312 nPoints = (
int * ) ptr;
4313 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4314 for ( idx = 0; idx < *nPoints; ++idx )
4321 x = (
double * ) ptr;
4324 ptr +=
sizeof( double );
4325 y = (
double * ) ptr;
4327 ptr +=
sizeof( double );
4330 ptr +=
sizeof( double );
4345 int *numRings, *nPoints;
4347 mWkt +=
"{ \"type\": \"Polygon\", \"coordinates\": [ ";
4349 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
4350 if ( !( *numRings ) )
4356 ringStart =
new int[*numRings];
4357 ringNumPoints =
new int[*numRings];
4358 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4359 for ( idx = 0; idx < *numRings; idx++ )
4367 nPoints = (
int * ) ptr;
4368 ringNumPoints[idx] = *nPoints;
4371 for ( jdx = 0; jdx < *nPoints; jdx++ )
4378 x = (
double * ) ptr;
4381 ptr +=
sizeof( double );
4382 y = (
double * ) ptr;
4384 ptr +=
sizeof( double );
4387 ptr +=
sizeof( double );
4394 delete [] ringStart;
4395 delete [] ringNumPoints;
4407 mWkt +=
"{ \"type\": \"MultiPoint\", \"coordinates\": [ ";
4410 for ( idx = 0; idx < *nPoints; ++idx )
4412 ptr += ( 1 +
sizeof( int ) );
4418 x = (
double * )( ptr );
4421 ptr +=
sizeof( double );
4422 y = (
double * )( ptr );
4424 ptr +=
sizeof( double );
4427 ptr +=
sizeof( double );
4441 int idx, jdx, numLineStrings;
4444 mWkt +=
"{ \"type\": \"MultiLineString\", \"coordinates\": [ ";
4445 numLineStrings = ( int )(
mGeometry[5] );
4447 for ( jdx = 0; jdx < numLineStrings; jdx++ )
4455 nPoints = (
int * ) ptr;
4456 ptr +=
sizeof( int );
4457 for ( idx = 0; idx < *nPoints; idx++ )
4464 x = (
double * ) ptr;
4466 ptr +=
sizeof( double );
4468 y = (
double * ) ptr;
4470 ptr +=
sizeof( double );
4473 ptr +=
sizeof( double );
4490 int *numPolygons, *numRings, *nPoints;
4492 mWkt +=
"{ \"type\": \"MultiPolygon\", \"coordinates\": [ ";
4494 numPolygons = (
int * ) ptr;
4496 for ( kdx = 0; kdx < *numPolygons; kdx++ )
4504 numRings = (
int * ) ptr;
4506 for ( idx = 0; idx < *numRings; idx++ )
4513 nPoints = (
int * ) ptr;
4515 for ( jdx = 0; jdx < *nPoints; jdx++ )
4522 x = (
double * ) ptr;
4524 ptr +=
sizeof( double );
4526 y = (
double * ) ptr;
4528 ptr +=
sizeof( double );
4531 ptr +=
sizeof( double );
4544 QgsDebugMsg(
"error: mGeometry type not recognized" );
4545 return QString::null;
4562 GEOSGeom_destroy(
mGeos );
4579 int *numLineStrings;
4584 bool hasZValue =
false;
4587 memcpy( &wkbtype, &(
mGeometry[1] ),
sizeof(
int ) );
4597 y = (
double * )(
mGeometry + 5 +
sizeof(
double ) );
4608 QVector<GEOSGeometry *> points;
4611 nPoints = (
int * ) ptr;
4612 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4613 for ( idx = 0; idx < *nPoints; idx++ )
4615 ptr += ( 1 +
sizeof( int ) );
4616 x = (
double * ) ptr;
4617 ptr +=
sizeof( double );
4618 y = (
double * ) ptr;
4619 ptr +=
sizeof( double );
4622 ptr +=
sizeof( double );
4640 nPoints = (
int * ) ptr;
4641 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4642 for ( idx = 0; idx < *nPoints; idx++ )
4644 x = (
double * ) ptr;
4645 ptr +=
sizeof( double );
4646 y = (
double * ) ptr;
4647 ptr +=
sizeof( double );
4650 ptr +=
sizeof( double );
4664 QVector<GEOSGeometry*> lines;
4665 numLineStrings = (
int* )(
mGeometry + 5 );
4667 for ( jdx = 0; jdx < *numLineStrings; jdx++ )
4673 nPoints = (
int * ) ptr;
4674 ptr +=
sizeof( int );
4675 for ( idx = 0; idx < *nPoints; idx++ )
4677 x = (
double * ) ptr;
4678 ptr +=
sizeof( double );
4679 y = (
double * ) ptr;
4680 ptr +=
sizeof( double );
4683 ptr +=
sizeof( double );
4701 numRings = (
int * )(
mGeometry + 1 +
sizeof(
int ) );
4702 ptr =
mGeometry + 1 + 2 *
sizeof( int );
4704 QVector<GEOSGeometry*> rings;
4706 for ( idx = 0; idx < *numRings; idx++ )
4713 nPoints = (
int * ) ptr;
4715 for ( jdx = 0; jdx < *nPoints; jdx++ )
4718 x = (
double * ) ptr;
4719 ptr +=
sizeof( double );
4720 y = (
double * ) ptr;
4721 ptr +=
sizeof( double );
4724 ptr +=
sizeof( double );
4742 QVector<GEOSGeometry*> polygons;
4746 numPolygons = (
int * ) ptr;
4748 for ( kdx = 0; kdx < *numPolygons; kdx++ )
4751 QVector<GEOSGeometry*> rings;
4756 numRings = (
int * ) ptr;
4758 for ( idx = 0; idx < *numRings; idx++ )
4765 nPoints = (
int * ) ptr;
4767 for ( jdx = 0; jdx < *nPoints; jdx++ )
4770 x = (
double * ) ptr;
4771 ptr +=
sizeof( double );
4772 y = (
double * ) ptr;
4773 ptr +=
sizeof( double );
4776 ptr +=
sizeof( double );
4826 switch ( GEOSGeomTypeId(
mGeos ) )
4832 2 *
sizeof( double );
4842 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq(
mGeos );
4845 GEOSCoordSeq_getX( cs, 0, &x );
4846 GEOSCoordSeq_getY( cs, 0, &y );
4848 memcpy(
mGeometry + 5, &x,
sizeof(
double ) );
4849 memcpy(
mGeometry + 13, &y,
sizeof(
double ) );
4855 case GEOS_LINESTRING:
4859 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq(
mGeos );
4860 unsigned int numPoints;
4861 GEOSCoordSeq_getSize( cs, &numPoints );
4867 ((
sizeof( double ) +
4868 sizeof(
double ) ) * numPoints );
4875 memcpy( ptr, &byteOrder, 1 );
4880 memcpy( ptr, &wkbType, 4 );
4884 memcpy( ptr, &numPoints, 4 );
4887 const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq(
mGeos );
4890 for (
unsigned int n = 0; n < numPoints; n++ )
4893 GEOSCoordSeq_getX( sequence, n, (
double * )ptr );
4894 ptr +=
sizeof( double );
4897 GEOSCoordSeq_getY( sequence, n, (
double * )ptr );
4898 ptr +=
sizeof( double );
4907 case GEOS_LINEARRING:
4916 unsigned int nPointsInRing = 0;
4919 geometrySize = 1 + 2 *
sizeof( int );
4920 const GEOSGeometry *theRing = GEOSGetExteriorRing(
mGeos );
4923 geometrySize +=
sizeof( int );
4926 for (
int i = 0; i < GEOSGetNumInteriorRings(
mGeos ); ++i )
4928 geometrySize +=
sizeof( int );
4929 theRing = GEOSGetInteriorRingN(
mGeos, i );
4936 mGeometry =
new unsigned char[geometrySize];
4945 memcpy( &
mGeometry[position], &wkbtype,
sizeof(
int ) );
4946 position +=
sizeof( int );
4947 int nRings = GEOSGetNumInteriorRings(
mGeos ) + 1;
4948 memcpy( &
mGeometry[position], &nRings,
sizeof(
int ) );
4949 position +=
sizeof( int );
4952 theRing = GEOSGetExteriorRing(
mGeos );
4956 memcpy( &
mGeometry[position], &nPointsInRing,
sizeof(
int ) );
4957 position +=
sizeof( int );
4959 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4961 GEOSCoordSeq_getSize( cs, &n );
4963 for (
unsigned int j = 0; j < n; ++j )
4965 GEOSCoordSeq_getX( cs, j, (
double * )&
mGeometry[position] );
4966 position +=
sizeof( double );
4967 GEOSCoordSeq_getY( cs, j, (
double * )&
mGeometry[position] );
4968 position +=
sizeof( double );
4973 for (
int i = 0; i < GEOSGetNumInteriorRings(
mGeos ); i++ )
4975 theRing = GEOSGetInteriorRingN(
mGeos, i );
4977 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
4978 GEOSCoordSeq_getSize( cs, &nPointsInRing );
4980 memcpy( &
mGeometry[position], &nPointsInRing,
sizeof(
int ) );
4981 position +=
sizeof( int );
4983 for (
unsigned int j = 0; j < nPointsInRing; j++ )
4985 GEOSCoordSeq_getX( cs, j, (
double * )&
mGeometry[position] );
4986 position +=
sizeof( double );
4987 GEOSCoordSeq_getY( cs, j, (
double * )&
mGeometry[position] );
4988 position +=
sizeof( double );
4996 case GEOS_MULTIPOINT:
4999 int geometrySize = 1 + 2 *
sizeof( int );
5000 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5002 geometrySize += 1 +
sizeof( int ) + 2 *
sizeof(
double );
5005 mGeometry =
new unsigned char[geometrySize];
5007 int wkbPosition = 0;
5012 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
5013 wkbPosition +=
sizeof( int );
5014 int numPoints = GEOSGetNumGeometries(
mGeos );
5015 memcpy( &
mGeometry[wkbPosition], &numPoints,
sizeof(
int ) );
5016 wkbPosition +=
sizeof( int );
5019 const GEOSGeometry *currentPoint = 0;
5021 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5024 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
5026 memcpy( &
mGeometry[wkbPosition], &pointType,
sizeof(
int ) );
5027 wkbPosition +=
sizeof( int );
5029 currentPoint = GEOSGetGeometryN(
mGeos, i );
5031 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( currentPoint );
5033 GEOSCoordSeq_getX( cs, 0, (
double* )&
mGeometry[wkbPosition] );
5034 wkbPosition +=
sizeof( double );
5035 GEOSCoordSeq_getY( cs, 0, (
double* )&
mGeometry[wkbPosition] );
5036 wkbPosition +=
sizeof( double );
5042 case GEOS_MULTILINESTRING:
5045 int geometrySize = 1 + 2 *
sizeof( int );
5046 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5048 geometrySize += 1 + 2 *
sizeof( int );
5052 mGeometry =
new unsigned char[geometrySize];
5054 int wkbPosition = 0;
5059 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
5060 wkbPosition +=
sizeof( int );
5061 int numLines = GEOSGetNumGeometries(
mGeos );
5062 memcpy( &
mGeometry[wkbPosition], &numLines,
sizeof(
int ) );
5063 wkbPosition +=
sizeof( int );
5067 const GEOSCoordSequence *cs = 0;
5068 unsigned int lineSize;
5070 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5073 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
5075 memcpy( &
mGeometry[wkbPosition], &lineType,
sizeof(
int ) );
5076 wkbPosition +=
sizeof( int );
5078 cs = GEOSGeom_getCoordSeq( GEOSGetGeometryN(
mGeos, i ) );
5081 GEOSCoordSeq_getSize( cs, &lineSize );
5082 memcpy( &
mGeometry[wkbPosition], &lineSize,
sizeof(
int ) );
5083 wkbPosition +=
sizeof( int );
5086 for (
unsigned int j = 0; j < lineSize; ++j )
5088 GEOSCoordSeq_getX( cs, j, (
double* )&
mGeometry[wkbPosition] );
5089 wkbPosition +=
sizeof( double );
5090 GEOSCoordSeq_getY( cs, j, (
double* )&
mGeometry[wkbPosition] );
5091 wkbPosition +=
sizeof( double );
5098 case GEOS_MULTIPOLYGON:
5101 int geometrySize = 1 + ( 2 *
sizeof( int ) );
5102 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5104 const GEOSGeometry *thePoly = GEOSGetGeometryN(
mGeos, i );
5105 geometrySize += 1 + 2 *
sizeof( int );
5107 geometrySize +=
sizeof( int );
5108 const GEOSGeometry *exRing = GEOSGetExteriorRing( thePoly );
5111 const GEOSGeometry *intRing = 0;
5112 for (
int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ )
5114 geometrySize +=
sizeof( int );
5115 intRing = GEOSGetInteriorRingN( thePoly, j );
5120 mGeometry =
new unsigned char[geometrySize];
5122 int wkbPosition = 0;
5127 memcpy( &
mGeometry[wkbPosition], &wkbtype,
sizeof(
int ) );
5128 wkbPosition +=
sizeof( int );
5129 int numPolygons = GEOSGetNumGeometries(
mGeos );
5130 memcpy( &
mGeometry[wkbPosition], &numPolygons,
sizeof(
int ) );
5131 wkbPosition +=
sizeof( int );
5134 for (
int i = 0; i < GEOSGetNumGeometries(
mGeos ); i++ )
5136 const GEOSGeometry *thePoly = GEOSGetGeometryN(
mGeos, i );
5137 memcpy( &
mGeometry[wkbPosition], &byteOrder, 1 );
5140 memcpy( &
mGeometry[wkbPosition], &polygonType,
sizeof(
int ) );
5141 wkbPosition +=
sizeof( int );
5142 int numRings = GEOSGetNumInteriorRings( thePoly ) + 1;
5143 memcpy( &
mGeometry[wkbPosition], &numRings,
sizeof(
int ) );
5144 wkbPosition +=
sizeof( int );
5147 const GEOSGeometry *theRing = GEOSGetExteriorRing( thePoly );
5149 memcpy( &
mGeometry[wkbPosition], &nPointsInRing,
sizeof(
int ) );
5150 wkbPosition +=
sizeof( int );
5151 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
5153 for (
int k = 0; k < nPointsInRing; ++k )
5155 GEOSCoordSeq_getX( cs, k, (
double * )&
mGeometry[wkbPosition] );
5156 wkbPosition +=
sizeof( double );
5157 GEOSCoordSeq_getY( cs, k, (
double * )&
mGeometry[wkbPosition] );
5158 wkbPosition +=
sizeof( double );
5162 for (
int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ )
5164 theRing = GEOSGetInteriorRingN( thePoly, j );
5166 memcpy( &
mGeometry[wkbPosition], &nPointsInRing,
sizeof(
int ) );
5167 wkbPosition +=
sizeof( int );
5168 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing );
5170 for (
int k = 0; k < nPointsInRing; ++k )
5172 GEOSCoordSeq_getX( cs, k, (
double * )&
mGeometry[wkbPosition] );
5173 wkbPosition +=
sizeof( double );
5174 GEOSCoordSeq_getY( cs, k, (
double * )&
mGeometry[wkbPosition] );
5175 wkbPosition +=
sizeof( double );
5183 case GEOS_GEOMETRYCOLLECTION:
5186 QgsDebugMsg(
"geometry collection - not supported" );
5212 unsigned char* newGeometry =
new unsigned char[newGeomSize];
5214 int currentWkbPosition = 0;
5217 memcpy( &newGeometry[currentWkbPosition], &byteOrder, 1 );
5218 currentWkbPosition += 1;
5247 memcpy( &newGeometry[currentWkbPosition], &newMultiType,
sizeof(
int ) );
5248 currentWkbPosition +=
sizeof( int );
5251 int nGeometries = 1;
5252 memcpy( &newGeometry[currentWkbPosition], &nGeometries,
sizeof(
int ) );
5253 currentWkbPosition +=
sizeof( int );
5267 double x, y, translated_x, translated_y;
5270 x = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
5271 translated_x = x + dx;
5272 memcpy( &(
mGeometry[wkbPosition] ), &translated_x,
sizeof(
double ) );
5273 wkbPosition +=
sizeof( double );
5276 y = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
5277 translated_y = y + dy;
5278 memcpy( &(
mGeometry[wkbPosition] ), &translated_y,
sizeof(
double ) );
5279 wkbPosition +=
sizeof( double );
5283 wkbPosition +=
sizeof( double );
5292 x = *((
double * )( &(
mGeometry[wkbPosition] ) ) );
5293 y = *((
double * )( &(
mGeometry[wkbPosition +
sizeof(
double )] ) ) );
5299 memcpy( &(
mGeometry[wkbPosition] ), &x,
sizeof(
double ) );
5300 wkbPosition +=
sizeof( double );
5303 memcpy( &(
mGeometry[wkbPosition] ), &y,
sizeof(
double ) );
5304 wkbPosition +=
sizeof( double );
5308 wkbPosition +=
sizeof( double );
5330 if ( !GEOSIntersects( splitLine,
mGeos ) )
5336 int linearIntersect = GEOSRelatePattern(
mGeos, splitLine,
"1********" );
5337 if ( linearIntersect > 0 )
5342 GEOSGeometry* splitGeom = GEOSDifference(
mGeos, splitLine );
5343 QVector<GEOSGeometry*> lineGeoms;
5345 int splitType = GEOSGeomTypeId( splitGeom );
5346 if ( splitType == GEOS_MULTILINESTRING )
5348 int nGeoms = GEOSGetNumGeometries( splitGeom );
5349 for (
int i = 0; i < nGeoms; ++i )
5351 lineGeoms << GEOSGeom_clone( GEOSGetGeometryN( splitGeom, i ) );
5356 lineGeoms << GEOSGeom_clone( splitGeom );
5361 if ( lineGeoms.size() > 0 )
5363 GEOSGeom_destroy(
mGeos );
5364 mGeos = lineGeoms[0];
5368 for (
int i = 1; i < lineGeoms.size(); ++i )
5373 GEOSGeom_destroy( splitGeom );
5395 if ( !GEOSIntersects( splitLine,
mGeos ) )
5402 if ( !nodedGeometry )
5407 GEOSGeometry *polygons = GEOSPolygonize( &nodedGeometry, 1 );
5411 GEOSGeom_destroy( polygons );
5413 GEOSGeom_destroy( nodedGeometry );
5418 GEOSGeom_destroy( nodedGeometry );
5422 QVector<GEOSGeometry*> testedGeometries;
5423 GEOSGeometry *intersectGeometry = 0;
5430 const GEOSGeometry *polygon = GEOSGetGeometryN( polygons, i );
5431 intersectGeometry = GEOSIntersection(
mGeos, polygon );
5432 if ( !intersectGeometry )
5438 double intersectionArea;
5439 GEOSArea( intersectGeometry, &intersectionArea );
5442 GEOSArea( polygon, &polygonArea );
5444 const double areaRatio = intersectionArea / polygonArea;
5445 if ( areaRatio > 0.99 && areaRatio < 1.01 )
5446 testedGeometries << GEOSGeom_clone( polygon );
5448 GEOSGeom_destroy( intersectGeometry );
5451 bool splitDone =
true;
5453 if ( testedGeometries.size() == nGeometriesThis )
5463 for (
int i = 0; i < testedGeometries.size(); ++i )
5465 GEOSGeom_destroy( testedGeometries[i] );
5469 else if ( testedGeometries.size() > 0 )
5471 GEOSGeom_destroy(
mGeos );
5472 mGeos = testedGeometries[0];
5477 for ( i = 1; i < testedGeometries.size() && GEOSisValid( testedGeometries[i] ); ++i )
5480 if ( i < testedGeometries.size() )
5482 for ( i = 0; i < testedGeometries.size(); ++i )
5484 GEOSGeom_destroy( testedGeometries[i] );
5489 for ( i = 1; i < testedGeometries.size(); ++i )
5494 GEOSGeom_destroy( polygons );
5501 int nIntersections = 0;
5502 int lastIntersectingRing = -2;
5503 const GEOSGeometry* lastIntersectingGeom = 0;
5505 int nRings = GEOSGetNumInteriorRings( polygon );
5512 const GEOSGeometry* outerRing = GEOSGetExteriorRing( polygon );
5513 if ( GEOSIntersects( outerRing, reshapeLineGeos ) == 1 )
5516 lastIntersectingRing = -1;
5517 lastIntersectingGeom = outerRing;
5521 const GEOSGeometry **innerRings =
new const GEOSGeometry*[nRings];
5525 for (
int i = 0; i < nRings; ++i )
5527 innerRings[i] = GEOSGetInteriorRingN( polygon, i );
5528 if ( GEOSIntersects( innerRings[i], reshapeLineGeos ) == 1 )
5531 lastIntersectingRing = i;
5532 lastIntersectingGeom = innerRings[i];
5542 if ( nIntersections != 1 )
5544 delete [] innerRings;
5549 GEOSGeometry* reshapeResult =
reshapeLine( lastIntersectingGeom, reshapeLineGeos );
5550 if ( !reshapeResult )
5552 delete [] innerRings;
5557 GEOSGeometry* newRing = 0;
5558 const GEOSCoordSequence* reshapeSequence = GEOSGeom_getCoordSeq( reshapeResult );
5559 GEOSCoordSequence* newCoordSequence = GEOSCoordSeq_clone( reshapeSequence );
5561 GEOSGeom_destroy( reshapeResult );
5563 newRing = GEOSGeom_createLinearRing( newCoordSequence );
5566 delete [] innerRings;
5571 GEOSGeometry* newOuterRing = 0;
5572 if ( lastIntersectingRing == -1 )
5574 newOuterRing = newRing;
5578 newOuterRing = GEOSGeom_clone( outerRing );
5582 QList<GEOSGeometry*> ringList;
5585 GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 );
5586 if ( outerRingPoly )
5588 GEOSGeometry* currentRing = 0;
5589 for (
int i = 0; i < nRings; ++i )
5591 if ( lastIntersectingRing == i )
5593 currentRing = newRing;
5597 currentRing = GEOSGeom_clone( innerRings[i] );
5601 if ( GEOSContains( outerRingPoly, currentRing ) == 1 )
5603 ringList.push_back( currentRing );
5607 GEOSGeom_destroy( currentRing );
5611 GEOSGeom_destroy( outerRingPoly );
5614 GEOSGeometry** newInnerRings =
new GEOSGeometry*[ringList.size()];
5615 for (
int i = 0; i < ringList.size(); ++i )
5617 newInnerRings[i] = ringList.at( i );
5620 delete [] innerRings;
5622 GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, ringList.size() );
5623 delete[] newInnerRings;
5624 if ( !reshapedPolygon )
5628 return reshapedPolygon;
5633 if ( !line || !reshapeLineGeos )
5638 bool atLeastTwoIntersections =
false;
5643 GEOSGeometry* intersectGeom = GEOSIntersection( line, reshapeLineGeos );
5644 if ( intersectGeom )
5646 atLeastTwoIntersections = ( GEOSGeomTypeId( intersectGeom ) == GEOS_MULTIPOINT && GEOSGetNumGeometries( intersectGeom ) > 1 );
5647 GEOSGeom_destroy( intersectGeom );
5653 atLeastTwoIntersections =
false;
5656 if ( !atLeastTwoIntersections )
5662 const GEOSCoordSequence* lineCoordSeq = GEOSGeom_getCoordSeq( line );
5663 if ( !lineCoordSeq )
5667 unsigned int lineCoordSeqSize;
5668 if ( GEOSCoordSeq_getSize( lineCoordSeq, &lineCoordSeqSize ) == 0 )
5672 if ( lineCoordSeqSize < 2 )
5677 double x1, y1, x2, y2;
5678 GEOSCoordSeq_getX( lineCoordSeq, 0, &x1 );
5679 GEOSCoordSeq_getY( lineCoordSeq, 0, &y1 );
5680 GEOSCoordSeq_getX( lineCoordSeq, lineCoordSeqSize - 1, &x2 );
5681 GEOSCoordSeq_getY( lineCoordSeq, lineCoordSeqSize - 1, &y2 );
5685 bool isRing =
false;
5686 if ( GEOSGeomTypeId( line ) == GEOS_LINEARRING || GEOSEquals( beginLineVertex, endLineVertex ) == 1 )
5692 GEOSGeometry* nodedGeometry =
nodeGeometries( reshapeLineGeos, line );
5693 if ( !nodedGeometry )
5695 GEOSGeom_destroy( beginLineVertex );
5696 GEOSGeom_destroy( endLineVertex );
5701 GEOSGeometry *mergedLines = GEOSLineMerge( nodedGeometry );
5702 GEOSGeom_destroy( nodedGeometry );
5705 GEOSGeom_destroy( beginLineVertex );
5706 GEOSGeom_destroy( endLineVertex );
5710 int numMergedLines = GEOSGetNumGeometries( mergedLines );
5711 if ( numMergedLines < 2 )
5713 GEOSGeom_destroy( beginLineVertex );
5714 GEOSGeom_destroy( endLineVertex );
5715 if ( numMergedLines == 1 )
5717 return GEOSGeom_clone( reshapeLineGeos );
5725 QList<GEOSGeometry*> resultLineParts;
5726 QList<GEOSGeometry*> probableParts;
5728 for (
int i = 0; i < numMergedLines; ++i )
5730 const GEOSGeometry* currentGeom;
5732 currentGeom = GEOSGetGeometryN( mergedLines, i );
5733 const GEOSCoordSequence* currentCoordSeq = GEOSGeom_getCoordSeq( currentGeom );
5734 unsigned int currentCoordSeqSize;
5735 GEOSCoordSeq_getSize( currentCoordSeq, ¤tCoordSeqSize );
5736 if ( currentCoordSeqSize < 2 )
5742 double xBegin, xEnd, yBegin, yEnd;
5743 GEOSCoordSeq_getX( currentCoordSeq, 0, &xBegin );
5744 GEOSCoordSeq_getY( currentCoordSeq, 0, &yBegin );
5745 GEOSCoordSeq_getX( currentCoordSeq, currentCoordSeqSize - 1, &xEnd );
5746 GEOSCoordSeq_getY( currentCoordSeq, currentCoordSeqSize - 1, &yEnd );
5751 int nEndpointsOnOriginalLine = 0;
5754 nEndpointsOnOriginalLine += 1;
5759 nEndpointsOnOriginalLine += 1;
5763 int nEndpointsSameAsOriginalLine = 0;
5764 if ( GEOSEquals( beginCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( beginCurrentGeomVertex, endLineVertex ) == 1 )
5766 nEndpointsSameAsOriginalLine += 1;
5768 if ( GEOSEquals( endCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( endCurrentGeomVertex, endLineVertex ) == 1 )
5770 nEndpointsSameAsOriginalLine += 1;
5774 bool currentGeomOverlapsOriginalGeom =
false;
5775 bool currentGeomOverlapsReshapeLine =
false;
5778 currentGeomOverlapsOriginalGeom =
true;
5782 currentGeomOverlapsReshapeLine =
true;
5787 if ( nEndpointsSameAsOriginalLine == 1 && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom )
5789 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5792 else if ( isRing && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom )
5794 probableParts.push_back( GEOSGeom_clone( currentGeom ) );
5796 else if ( nEndpointsOnOriginalLine == 2 && !currentGeomOverlapsOriginalGeom )
5798 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5800 else if ( nEndpointsSameAsOriginalLine == 2 && !currentGeomOverlapsOriginalGeom )
5802 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5804 else if ( currentGeomOverlapsOriginalGeom && currentGeomOverlapsReshapeLine )
5806 resultLineParts.push_back( GEOSGeom_clone( currentGeom ) );
5809 GEOSGeom_destroy( beginCurrentGeomVertex );
5810 GEOSGeom_destroy( endCurrentGeomVertex );
5814 if ( isRing && probableParts.size() > 0 )
5816 GEOSGeometry* maxGeom = 0;
5817 GEOSGeometry* currentGeom = 0;
5818 double maxLength = -DBL_MAX;
5819 double currentLength = 0;
5820 for (
int i = 0; i < probableParts.size(); ++i )
5822 currentGeom = probableParts.at( i );
5823 GEOSLength( currentGeom, ¤tLength );
5824 if ( currentLength > maxLength )
5826 maxLength = currentLength;
5827 GEOSGeom_destroy( maxGeom );
5828 maxGeom = currentGeom;
5832 GEOSGeom_destroy( currentGeom );
5835 resultLineParts.push_back( maxGeom );
5838 GEOSGeom_destroy( beginLineVertex );
5839 GEOSGeom_destroy( endLineVertex );
5840 GEOSGeom_destroy( mergedLines );
5842 GEOSGeometry* result = 0;
5843 if ( resultLineParts.size() < 1 )
5847 if ( resultLineParts.size() == 1 )
5849 result = resultLineParts[0];
5853 GEOSGeometry **lineArray =
new GEOSGeometry*[resultLineParts.size()];
5854 for (
int i = 0; i < resultLineParts.size(); ++i )
5856 lineArray[i] = resultLineParts[i];
5860 GEOSGeometry* multiLineGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, lineArray, resultLineParts.size() );
5861 delete [] lineArray;
5864 result = GEOSLineMerge( multiLineGeom );
5865 GEOSGeom_destroy( multiLineGeom );
5869 if ( GEOSGeomTypeId( result ) != GEOS_LINESTRING )
5871 GEOSGeom_destroy( result );
5884 GEOSGeometry* intersectionGeom = GEOSIntersection(
mGeos, splitLine );
5885 if ( !intersectionGeom )
5890 bool simple =
false;
5891 int nIntersectGeoms = 1;
5892 if ( GEOSGeomTypeId( intersectionGeom ) == GEOS_LINESTRING || GEOSGeomTypeId( intersectionGeom ) == GEOS_POINT )
5899 nIntersectGeoms = GEOSGetNumGeometries( intersectionGeom );
5902 for (
int i = 0; i < nIntersectGeoms; ++i )
5904 const GEOSGeometry* currentIntersectGeom;
5907 currentIntersectGeom = intersectionGeom;
5911 currentIntersectGeom = GEOSGetGeometryN( intersectionGeom, i );
5914 const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq( currentIntersectGeom );
5915 unsigned int sequenceSize = 0;
5917 if ( GEOSCoordSeq_getSize( lineSequence, &sequenceSize ) != 0 )
5919 for (
unsigned int i = 0; i < sequenceSize; ++i )
5921 if ( GEOSCoordSeq_getX( lineSequence, i, &x ) != 0 )
5923 if ( GEOSCoordSeq_getY( lineSequence, i, &y ) != 0 )
5925 testPoints.push_back(
QgsPoint( x, y ) );
5931 GEOSGeom_destroy( intersectionGeom );
5937 if ( !splitLine || !geom )
5942 GEOSGeometry *geometryBoundary = 0;
5943 if ( GEOSGeomTypeId( geom ) == GEOS_POLYGON || GEOSGeomTypeId( geom ) == GEOS_MULTIPOLYGON )
5945 geometryBoundary = GEOSBoundary( geom );
5949 geometryBoundary = GEOSGeom_clone( geom );
5952 GEOSGeometry *splitLineClone = GEOSGeom_clone( splitLine );
5953 GEOSGeometry *unionGeometry = GEOSUnion( splitLineClone, geometryBoundary );
5954 GEOSGeom_destroy( splitLineClone );
5956 GEOSGeom_destroy( geometryBoundary );
5957 return unionGeometry;
5962 if ( !line1 || !line2 )
5968 double bufferDistance = 0.00001;
5971 bufferDistance = 0.00000001;
5979 GEOSGeometry* intersectionGeom = GEOSIntersection( bufferGeom, line1 );
5982 double intersectGeomLength;
5985 GEOSLength( intersectionGeom, &intersectGeomLength );
5986 GEOSLength( line1, &line1Length );
5988 GEOSGeom_destroy( bufferGeom );
5989 GEOSGeom_destroy( intersectionGeom );
5991 double intersectRatio = line1Length / intersectGeomLength;
5992 if ( intersectRatio > 0.9 && intersectRatio < 1.1 )
6001 if ( !point || !line )
6006 double bufferDistance = 0.000001;
6009 bufferDistance = 0.00000001;
6011 GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 );
6017 bool contained =
false;
6018 if ( GEOSContains( lineBuffer, point ) == 1 )
6023 GEOSGeom_destroy( lineBuffer );
6029 GEOSGeometry* bbox = GEOSEnvelope( geom );
6035 const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox );
6040 const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing );
6042 if ( !bBoxCoordSeq )
6047 unsigned int nCoords = 0;
6048 if ( !GEOSCoordSeq_getSize( bBoxCoordSeq, &nCoords ) )
6054 for (
unsigned int i = 0; i < ( nCoords - 1 ); ++i )
6056 GEOSCoordSeq_getX( bBoxCoordSeq, i, &x );
6057 if ( x > 180 || x < -180 )
6061 GEOSCoordSeq_getY( bBoxCoordSeq, i, &y );
6062 if ( y > 90 || y < -90 )
6077 int geometryType = GEOSGeomTypeId( g );
6078 if ( geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING
6079 || geometryType == GEOS_POLYGON )
6085 return GEOSGetNumGeometries( g );
6101 int type = GEOSGeomTypeId(
mGeos );
6102 if ( type != GEOS_GEOMETRYCOLLECTION &&
6103 type != GEOS_MULTILINESTRING &&
6104 type != GEOS_MULTIPOLYGON &&
6105 type != GEOS_MULTIPOINT )
6110 QVector<GEOSGeometry*> copyList = splitResult;
6111 splitResult.clear();
6114 QVector<GEOSGeometry*> unionGeom;
6116 for (
int i = 0; i < copyList.size(); ++i )
6119 bool isPart =
false;
6120 for (
int j = 0; j < GEOSGetNumGeometries(
mGeos ); j++ )
6122 if ( GEOSEquals( copyList[i], GEOSGetGeometryN(
mGeos, j ) ) )
6131 unionGeom << copyList[i];
6135 QVector<GEOSGeometry*> geomVector;
6136 geomVector << copyList[i];
6138 if ( type == GEOS_MULTILINESTRING )
6142 else if ( type == GEOS_MULTIPOLYGON )
6148 GEOSGeom_destroy( copyList[i] );
6154 if ( unionGeom.size() > 0 )
6156 if ( type == GEOS_MULTILINESTRING )
6160 else if ( type == GEOS_MULTIPOLYGON )
6176 double* x = (
double * )( ptr );
6177 double* y = (
double * )( ptr +
sizeof(
double ) );
6178 ptr += 2 *
sizeof( double );
6181 ptr +=
sizeof( double );
6191 unsigned int nPoints = *((
int* )ptr );
6197 for ( uint i = 0; i < nPoints; ++i )
6199 x = *((
double * ) ptr );
6200 y = *((
double * )( ptr +
sizeof(
double ) ) );
6202 ptr += 2 *
sizeof( double );
6207 ptr +=
sizeof( double );
6221 unsigned int numRings = *((
int* )ptr );
6224 if ( numRings == 0 )
6229 for ( uint idx = 0; idx < numRings; idx++ )
6231 uint nPoints = *((
int* )ptr );
6236 for ( uint jdx = 0; jdx < nPoints; jdx++ )
6238 x = *((
double * ) ptr );
6239 y = *((
double * )( ptr +
sizeof(
double ) ) );
6241 ptr += 2 *
sizeof( double );
6244 ptr +=
sizeof( double );
6295 unsigned int nPoints = *((
int* )ptr );
6299 for ( uint i = 0; i < nPoints; i++ )
6301 points[i] =
asPoint( ptr, hasZValue );
6316 unsigned int numLineStrings = *((
int* )ptr );
6321 for ( uint i = 0; i < numLineStrings; i++ )
6338 unsigned int numPolygons = *((
int* )ptr );
6343 for ( uint i = 0; i < numPolygons; i++ )
6345 polygons[i] =
asPolygon( ptr, hasZValue );
6366 if ( GEOSArea(
mGeos, &area ) == 0 )
6389 if ( GEOSLength(
mGeos, &length ) == 0 )
6494 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
6495 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=2)))
6567 GEOSGeometry* unionGeom = GEOSUnion(
mGeos, geometry->
mGeos );
6575 GEOSGeometry* mergedGeom = GEOSLineMerge( unionGeom );
6578 GEOSGeom_destroy( unionGeom );
6579 unionGeom = mergedGeom;
6652 return QList<QgsGeometry*>();
6655 int type = GEOSGeomTypeId(
mGeos );
6656 QgsDebugMsg(
"geom type: " + QString::number( type ) );
6658 QList<QgsGeometry*> geomCollection;
6660 if ( type != GEOS_MULTIPOINT &&
6661 type != GEOS_MULTILINESTRING &&
6662 type != GEOS_MULTIPOLYGON &&
6663 type != GEOS_GEOMETRYCOLLECTION )
6666 geomCollection.append(
new QgsGeometry( *
this ) );
6667 return geomCollection;
6670 int count = GEOSGetNumGeometries(
mGeos );
6671 QgsDebugMsg(
"geom count: " + QString::number( count ) );
6673 for (
int i = 0; i < count; ++i )
6675 const GEOSGeometry * geometry = GEOSGetGeometryN(
mGeos, i );
6676 geomCollection.append(
fromGeosGeom( GEOSGeom_clone( geometry ) ) );
6679 return geomCollection;
6685 if ( ringNum <= 0 || partNum < 0 )
6697 if ( ringNum >= polygon.count() )
6700 polygon.remove( ringNum );
6713 if ( partNum >= mpolygon.count() )
6716 if ( ringNum >= mpolygon[partNum].count() )
6719 mpolygon[partNum].remove( ringNum );
6745 if ( partNum >= mpoint.size() || mpoint.size() == 1 )
6748 mpoint.remove( partNum );
6761 if ( partNum >= mline.size() || mline.size() == 1 )
6764 mline.remove( partNum );
6777 if ( partNum >= mpolygon.size() || mpolygon.size() == 1 )
6780 mpolygon.remove( partNum );
6798 int returnValue = 0;
6818 QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
6819 for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
6825 QMap<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer );
6826 if ( ignoreIt != ignoreFeatures.constEnd() )
6828 ignoreIds = ignoreIt.value();
6839 if (
wkbType() != geomTypeBeforeModification )
6856 const GEOSGeometry *g =
asGeos();
6861 return GEOSisValid( g );
6872 return geosRelOp( GEOSEquals,
this, &g );
6879 const GEOSGeometry *g =
asGeos();
6884 return GEOSisEmpty( g );
6896 double f2 = y2 - y1;
6898 double f4 = x2 - x1;
6899 return f1*f2 - f3*f4;