@@ -649,13 +649,6 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
649
649
bool QgsGeometry::vertexAt (double &x, double &y,
650
650
QgsGeometryVertexIndex atVertex) const
651
651
{
652
- #ifdef QGISDEBUG
653
- std::cout << " QgsGeometry::vertexAt: Entered with "
654
- // << "atVertex " << atVertex << ", atRing " << atRing << ", atItem"
655
- // << " " << atItem
656
- << " ." << std::endl;
657
- #endif
658
-
659
652
if (mGeos )// try to find the vertex from the Geos geometry (it present)
660
653
{
661
654
geos::CoordinateSequence* cs = mGeos ->getCoordinates ();
@@ -672,59 +665,50 @@ bool QgsGeometry::vertexAt(double &x, double &y,
672
665
else if (mGeometry )
673
666
{
674
667
int wkbType;
668
+ unsigned char * ptr;
675
669
676
670
memcpy (&wkbType, (mGeometry +1 ), sizeof (int ));
677
671
switch (wkbType)
678
672
{
679
673
case QGis::WKBPoint:
680
674
{
681
- // TODO
682
- return FALSE ;
675
+ if (atVertex.back () == 0 )
676
+ {
677
+ ptr = mGeometry +1 +sizeof (int );
678
+ memcpy (&x, ptr, sizeof (double ));
679
+ ptr += sizeof (double );
680
+ memcpy (&y, ptr, sizeof (double ));
681
+ }
682
+ else
683
+ {
684
+ return FALSE ;
685
+ }
683
686
break ;
684
687
}
685
688
case QGis::WKBLineString:
686
689
{
687
- unsigned char *ptr;
688
690
int *nPoints;
689
-
690
691
// get number of points in the line
691
- ptr = mGeometry + 5 ; // now at mGeometry.numPoints
692
+ ptr = mGeometry + 1 + sizeof ( int ) ; // now at mGeometry.numPoints
692
693
nPoints = (int *) ptr;
693
694
694
- #ifdef QGISDEBUG
695
- std::cout << " QgsGeometry::vertexAt: Number of points in WKBLineString is " << *nPoints
696
- << " ." << std::endl;
697
- #endif
698
695
// return error if underflow
699
- if (0 > atVertex.back ())
700
- {
701
- return FALSE ;
702
- }
703
- // return error if overflow
704
- if (*nPoints <= atVertex.back ())
696
+ if (0 > atVertex.back () || *nPoints <= atVertex.back ())
705
697
{
706
698
return FALSE ;
707
699
}
708
-
709
700
// copy the vertex coordinates
710
- ptr = mGeometry + 9 + (atVertex.back () * 16 );
711
- memcpy (&x, ptr, 8 );
712
- ptr += 8 ;
713
- memcpy (&y, ptr, 8 );
714
-
715
- #ifdef QGISDEBUG
716
- std::cout << " QgsGeometry::vertexAt: Point is (" << x << " , " << y << " )"
717
- << " ." << std::endl;
718
- #endif
719
-
701
+ ptr = mGeometry + 9 + (atVertex.back () * 2 *sizeof (double ));
702
+ memcpy (&x, ptr, sizeof (double ));
703
+ ptr += sizeof (double );
704
+ memcpy (&y, ptr, sizeof (double ));
720
705
break ;
721
706
}
722
707
case QGis::WKBPolygon:
723
708
{
724
- unsigned char *ptr;
725
709
int *nRings;
726
710
int *nPoints = 0 ;
727
- ptr = mGeometry +5 ;
711
+ ptr = mGeometry +1 + sizeof ( int ) ;
728
712
nRings = (int *)ptr;
729
713
ptr += sizeof (int );
730
714
int pointindex = 0 ;
@@ -749,23 +733,74 @@ bool QgsGeometry::vertexAt(double &x, double &y,
749
733
}
750
734
case QGis::WKBMultiPoint:
751
735
{
752
- // TODO
753
- return false ;
736
+ ptr = mGeometry +1 +sizeof (int );
737
+ int * nPoints = (int *)ptr;
738
+ if (atVertex.back () < 0 || atVertex.back () >= *nPoints)
739
+ {
740
+ return false ;
741
+ }
742
+ ptr += atVertex.back ()*2 *sizeof (double );
743
+ memcpy (&x, ptr, sizeof (double ));
744
+ ptr += sizeof (double );
745
+ memcpy (&y, ptr, sizeof (double ));
754
746
break ;
755
- }
756
-
747
+ }
757
748
case QGis::WKBMultiLineString:
758
749
{
759
- // TODO
750
+ ptr = mGeometry +1 +sizeof (int );
751
+ int * nLines = (int *)ptr;
752
+ int * nPoints = 0 ; // number of points in a line
753
+ int pointindex = 0 ; // global point counter
754
+ ptr += sizeof (int );
755
+ for (int linenr = 0 ; linenr < *nLines; ++linenr)
756
+ {
757
+ nPoints = (int *)ptr;
758
+ ptr += sizeof (int );
759
+ for (int pointnr = 0 ; pointnr < *nPoints; ++pointnr)
760
+ {
761
+ if (pointindex == atVertex.back ())
762
+ {
763
+ memcpy (&x, ptr, sizeof (double ));
764
+ ptr += sizeof (double );
765
+ memcpy (&y, ptr, sizeof (double ));
766
+ break ;
767
+ }
768
+ ptr += 2 *sizeof (double );
769
+ ++pointindex;
770
+ }
771
+ }
760
772
return false ;
761
- break ;
762
773
}
763
-
764
774
case QGis::WKBMultiPolygon:
765
775
{
766
- // TODO
776
+ ptr = mGeometry +1 +sizeof (int );
777
+ int * nRings = 0 ;// number of rings in a polygon
778
+ int * nPoints = 0 ;// number of points in a ring
779
+ int pointindex = 0 ; // global point counter
780
+ int * nPolygons = (int *)ptr;
781
+ ptr += sizeof (int );
782
+ for (int polynr = 0 ; polynr < *nPolygons; ++polynr)
783
+ {
784
+ nRings = (int *)ptr;
785
+ ptr += sizeof (int );
786
+ for (int ringnr = 0 ; ringnr < *nRings; ++ringnr)
787
+ {
788
+ nPoints = (int *)ptr;
789
+ for (int pointnr = 0 ; pointnr < *nPoints; ++pointnr)
790
+ {
791
+ if (pointindex == atVertex.back ())
792
+ {
793
+ memcpy (&x, ptr, sizeof (double ));
794
+ ptr += sizeof (double );
795
+ memcpy (&y, ptr, sizeof (double ));
796
+ break ;
797
+ }
798
+ ++pointindex;
799
+ ptr += 2 *sizeof (double );
800
+ }
801
+ }
802
+ }
767
803
return false ;
768
- break ;
769
804
}
770
805
default :
771
806
#ifdef QGISDEBUG
0 commit comments