@@ -157,7 +157,6 @@ void QgsGeometry::setWkbAndOwnership(unsigned char * wkb, size_t length)
157
157
mDirtyWkb = FALSE ;
158
158
mDirtyGeos = TRUE ;
159
159
mDirtyWkt = TRUE ;
160
-
161
160
}
162
161
163
162
unsigned char * QgsGeometry::wkbBuffer () const
@@ -2190,7 +2189,7 @@ bool QgsGeometry::fast_intersects(const QgsRect& r) const
2190
2189
rectwkt+=" ))" ;
2191
2190
GEOS_GEOM::GeometryFactory *gf = new GEOS_GEOM::GeometryFactory ();
2192
2191
GEOS_IO::WKTReader *wktReader = new GEOS_IO::WKTReader (gf);
2193
- GEOS_GEOM::Geometry *geosRect = wktReader->read ( qstrdup ( rectwkt) );
2192
+ GEOS_GEOM::Geometry *geosRect = wktReader->read (rectwkt. toLocal8Bit (). data () );
2194
2193
2195
2194
try // geos might throw exception on error
2196
2195
{
@@ -2209,7 +2208,6 @@ bool QgsGeometry::fast_intersects(const QgsRect& r) const
2209
2208
QgsLogger::warning (" GEOS: " + error);
2210
2209
}
2211
2210
2212
- delete geosGeom;
2213
2211
delete geosRect;
2214
2212
delete gf;
2215
2213
delete wktReader;
@@ -2501,8 +2499,6 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2501
2499
{
2502
2500
// No need to convert again
2503
2501
return mGeos ;
2504
-
2505
- // TODO: make mGeos useful - assign to it and clear mDirty before we return out of this function
2506
2502
}
2507
2503
2508
2504
if (!mGeometry )
@@ -2522,20 +2518,27 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2522
2518
unsigned char *ptr;
2523
2519
char lsb;
2524
2520
QgsPoint pt;
2525
- int wkbtype;
2521
+ QGis::WKBTYPE wkbtype;
2522
+ bool hasZValue = false ;
2526
2523
2527
- wkbtype = (mGeometry [0 ] == 1 ) ? mGeometry [1 ] : mGeometry [4 ];
2524
+ // wkbtype = (mGeometry[0] == 1) ? mGeometry[1] : mGeometry[4];//MH: this does not work for 2.5D types
2525
+ wkbtype = wkbType ();
2528
2526
switch (wkbtype)
2529
- {
2530
- case QGis::WKBPoint:
2527
+ {
2528
+ case QGis::WKBPoint25D:
2529
+ case QGis::WKBPoint:
2531
2530
{
2532
2531
x = (double *) (mGeometry + 5 );
2533
2532
y = (double *) (mGeometry + 5 + sizeof (double ));
2534
2533
2535
- mDirtyGeos = FALSE ;
2536
- return geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y));
2534
+ mDirtyGeos = FALSE ;
2535
+ mGeos = geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y));
2536
+ mDirtyGeos = FALSE ;
2537
+ return mGeos ;
2537
2538
}
2538
- case QGis::WKBMultiPoint:
2539
+ case QGis::WKBMultiPoint25D:
2540
+ hasZValue = true ;
2541
+ case QGis::WKBMultiPoint:
2539
2542
{
2540
2543
std::vector<GEOS_GEOM::Geometry*>* points=new std::vector<GEOS_GEOM::Geometry*>;
2541
2544
ptr = mGeometry + 5 ;
@@ -2549,10 +2552,19 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2549
2552
y = (double *) ptr;
2550
2553
ptr += sizeof (double );
2551
2554
points->push_back (geosGeometryFactory->createPoint (GEOS_GEOM::Coordinate (*x,*y)));
2555
+ if (hasZValue)
2556
+ {
2557
+ ptr += sizeof (double );
2558
+ }
2552
2559
}
2553
- return geosGeometryFactory->createMultiPoint (points);
2560
+ delete mGeos ;
2561
+ mGeos = geosGeometryFactory->createMultiPoint (points);
2562
+ mDirtyGeos = FALSE ;
2563
+ return mGeos ;
2554
2564
}
2555
- case QGis::WKBLineString:
2565
+ case QGis::WKBLineString25D:
2566
+ hasZValue = true ;
2567
+ case QGis::WKBLineString:
2556
2568
{
2557
2569
QgsDebugMsg (" QgsGeometry::geosGeometry: Linestring found" );
2558
2570
@@ -2567,10 +2579,19 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2567
2579
y = (double *) ptr;
2568
2580
ptr += sizeof (double );
2569
2581
sequence->add (GEOS_GEOM::Coordinate (*x,*y));
2582
+ if (hasZValue)
2583
+ {
2584
+ ptr += sizeof (double );
2585
+ }
2570
2586
}
2571
- return geosGeometryFactory->createLineString (sequence);
2587
+ delete mGeos ;
2588
+ mGeos = geosGeometryFactory->createLineString (sequence);
2589
+ mDirtyGeos = FALSE ;
2590
+ return mGeos ;
2572
2591
}
2573
- case QGis::WKBMultiLineString:
2592
+ case QGis::WKBMultiLineString25D:
2593
+ hasZValue = true ;
2594
+ case QGis::WKBMultiLineString:
2574
2595
{
2575
2596
std::vector<GEOS_GEOM::Geometry*>* lines=new std::vector<GEOS_GEOM::Geometry*>;
2576
2597
numLineStrings = (int ) (mGeometry [5 ]);
@@ -2590,14 +2611,23 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2590
2611
y = (double *) ptr;
2591
2612
ptr += sizeof (double );
2592
2613
sequence->add (GEOS_GEOM::Coordinate (*x,*y));
2614
+ if (hasZValue)
2615
+ {
2616
+ ptr += sizeof (double );
2617
+ }
2593
2618
}
2594
2619
lines->push_back (geosGeometryFactory->createLineString (sequence));
2595
2620
}
2596
- return geosGeometryFactory->createMultiLineString (lines);
2621
+ delete mGeos ;
2622
+ mGeos = geosGeometryFactory->createMultiLineString (lines);
2623
+ mDirtyGeos = FALSE ;
2624
+ return mGeos ;
2597
2625
}
2598
- case QGis::WKBPolygon:
2626
+ case QGis::WKBPolygon25D:
2627
+ hasZValue = true ;
2628
+ case QGis::WKBPolygon:
2599
2629
{
2600
- QgsDebugMsg (" Polygon found" );
2630
+ QgsDebugMsg (" Polygon found" );
2601
2631
2602
2632
// get number of rings in the polygon
2603
2633
numRings = (int *) (mGeometry + 1 + sizeof (int ));
@@ -2623,6 +2653,10 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2623
2653
y = (double *) ptr;
2624
2654
ptr += sizeof (double );
2625
2655
sequence->add (GEOS_GEOM::Coordinate (*x,*y));
2656
+ if (hasZValue)
2657
+ {
2658
+ ptr += sizeof (double );
2659
+ }
2626
2660
}
2627
2661
GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing (sequence);
2628
2662
if (idx==0 )
@@ -2634,10 +2668,14 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2634
2668
inner->push_back (ring);
2635
2669
}
2636
2670
}
2637
- return geosGeometryFactory->createPolygon (outer,inner);
2671
+ delete mGeos ;
2672
+ mGeos = geosGeometryFactory->createPolygon (outer,inner);
2673
+ mDirtyGeos = FALSE ;
2674
+ return mGeos ;
2638
2675
}
2639
-
2640
- case QGis::WKBMultiPolygon:
2676
+ case QGis::WKBMultiPolygon25D:
2677
+ hasZValue = true ;
2678
+ case QGis::WKBMultiPolygon:
2641
2679
{
2642
2680
QgsDebugMsg (" Multipolygon found" );
2643
2681
@@ -2675,6 +2713,10 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2675
2713
y = (double *) ptr;
2676
2714
ptr += sizeof (double );
2677
2715
sequence->add (GEOS_GEOM::Coordinate (*x,*y));
2716
+ if (hasZValue)
2717
+ {
2718
+ ptr += sizeof (double );
2719
+ }
2678
2720
}
2679
2721
GEOS_GEOM::LinearRing* ring=geosGeometryFactory->createLinearRing (sequence);
2680
2722
if (idx==0 )
@@ -2689,10 +2731,13 @@ GEOS_GEOM::Geometry* QgsGeometry::geosGeometry() const
2689
2731
2690
2732
polygons->push_back (geosGeometryFactory->createPolygon (outer,inner));
2691
2733
}
2692
- return (geosGeometryFactory->createMultiPolygon (polygons));
2734
+ delete mGeos ;
2735
+ mGeos = (geosGeometryFactory->createMultiPolygon (polygons));
2736
+ mDirtyGeos = false ;
2737
+ return mGeos ;
2693
2738
}
2694
- default :
2695
- return 0 ;
2739
+ default :
2740
+ return 0 ;
2696
2741
}
2697
2742
2698
2743
}
0 commit comments