@@ -830,14 +830,7 @@ bool QgsGeometry::vertexAt(double &x, double &y,
830
830
QgsPoint QgsGeometry::closestVertexWithContext (QgsPoint& point,
831
831
QgsGeometryVertexIndex& atVertex,
832
832
double & sqrDist)
833
- // TODO
834
833
{
835
-
836
- #ifdef QGISDEBUG
837
- std::cout << " QgsGeometry::closestVertexWithContext: Entered"
838
- << " ." << std::endl;
839
- #endif
840
-
841
834
QgsPoint minDistPoint;
842
835
843
836
// Initialise some stuff
@@ -864,102 +857,8 @@ QgsPoint QgsGeometry::closestVertexWithContext(QgsPoint& point,
864
857
}
865
858
}
866
859
atVertex.push_back (closestVertexIndex);
867
- #if 0
868
- switch (mGeos->getGeometryTypeId())
869
- {
870
- case geos::GEOS_POINT: // a point
871
- {
872
- atVertex.push_back(closestVertexIndex);
873
-
874
- minDistPoint = QgsPoint(
875
- mGeos->getCoordinate()->x,
876
- mGeos->getCoordinate()->y
877
- );
878
-
879
- break;
880
- } // case geos::GEOS_POINT
881
-
882
- case geos::GEOS_LINESTRING: // a linestring
883
- {
884
- int numPoints = mGeos->getNumPoints();
885
-
886
- geos::LineString* geosls = static_cast<geos::LineString*>(mGeos);
887
- const geos::CoordinateSequence* sequence = geosls->getCoordinatesRO();
888
-
889
- // go through points
890
- for (int n = 0; n < numPoints; n++)
891
- {
892
- double testDist = point.sqrDist(
893
- sequence->getAt(n).x,
894
- sequence->getAt(n).y
895
- );
896
-
897
- if (testDist < sqrDist)
898
- {
899
- closestVertexIndex = n;
900
- sqrDist = testDist;
901
- }
902
- }
903
-
904
- atVertex.push_back(closestVertexIndex);
905
-
906
- break;
907
- } // case geos::GEOS_LINESTRING
908
-
909
- case geos::GEOS_LINEARRING: // a linear ring (linestring with 1st point == last point)
910
- {
911
- // TODO
912
- break;
913
- } // case geos::GEOS_LINEARRING
914
-
915
- case geos::GEOS_POLYGON: // a polygon
916
- {
917
- geos::CoordinateSequence* sequence = mGeos->getCoordinates();
918
- if(sequence)
919
- {
920
- for(int i = 0; i < sequence->getSize(); ++i)
921
- {
922
- double testDist = point.sqrDist(sequence->getAt(i).x, sequence->getAt(i).y);
923
- if(testDist < sqrDist)
924
- {
925
- closestVertexIndex = i;
926
- sqrDist = testDist;
927
- }
928
- }
929
- }
930
- atVertex.push_back(closestVertexIndex);
931
- break;
932
- } // case geos::GEOS_POLYGON
933
-
934
- case geos::GEOS_MULTIPOINT: // a collection of points
935
- {
936
- // TODO
937
- break;
938
- } // case geos::GEOS_MULTIPOINT
939
-
940
- case geos::GEOS_MULTILINESTRING: // a collection of linestrings
941
- {
942
- // TODO
943
- break;
944
- } // case geos::GEOS_MULTILINESTRING
945
-
946
- case geos::GEOS_MULTIPOLYGON: // a collection of polygons
947
- {
948
- // TODO
949
- break;
950
- } // case geos::GEOS_MULTIPOLYGON
951
-
952
- case geos::GEOS_GEOMETRYCOLLECTION: // a collection of heterogeneus geometries
953
- {
954
- // TODO
955
- break;
956
- } // case geos::GEOS_GEOMETRYCOLLECTION
957
- }
958
- #endif
959
860
} // if (mGeos)
960
-
961
861
return minDistPoint;
962
-
963
862
}
964
863
965
864
@@ -973,7 +872,7 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
973
872
double *thisx,*thisy;
974
873
double *prevx,*prevy;
975
874
double testdist;
976
- int closestSegmentIndex;
875
+ int closestSegmentIndex = 0 ;
977
876
978
877
// Initialise some stuff
979
878
beforeVertex.clear ();
@@ -991,14 +890,14 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
991
890
switch (wkbType)
992
891
{
993
892
case QGis::WKBPoint:
893
+ case QGis::WKBMultiPoint:
994
894
{
995
895
// Points have no lines
996
896
return QgsPoint (0 ,0 );
997
897
}
998
898
case QGis::WKBLineString:
999
899
{
1000
- closestSegmentIndex = 0 ;
1001
- unsigned char * ptr = mGeometry + 5 ;
900
+ unsigned char * ptr = mGeometry +1 +sizeof (int );
1002
901
int * npoints = (int *) ptr;
1003
902
ptr += sizeof (int );
1004
903
for (int index=0 ; index < *npoints; ++index)
@@ -1025,11 +924,45 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
1025
924
beforeVertex.push_back (closestSegmentIndex);
1026
925
break ;
1027
926
}
927
+ case QGis::WKBMultiLineString:
928
+ {
929
+ unsigned char * ptr = mGeometry +1 +sizeof (int );
930
+ int * nLines = (int *)ptr;
931
+ ptr += sizeof (int );
932
+ int * nPoints = 0 ; // number of points in a line
933
+ int pointindex = 0 ;// global pointindex
934
+ for (int linenr = 0 ; linenr < *nLines; ++linenr)
935
+ {
936
+ nPoints = (int *)ptr;
937
+ ptr += sizeof (int );
938
+ prevx = 0 ;
939
+ prevy = 0 ;
940
+ for (int pointnr = 0 ; pointnr < *nPoints; ++pointnr)
941
+ {
942
+ thisx = (double *) ptr;
943
+ ptr += sizeof (double );
944
+ thisy = (double *) ptr;
945
+ ptr += sizeof (double );
946
+ if (prevx && prevy)
947
+ {
948
+ if ((testdist = distanceSquaredPointToSegment (point, prevx, prevy, thisx, thisy, minDistPoint)) < sqrDist )
949
+ {
950
+ closestSegmentIndex = pointindex;
951
+ sqrDist = testdist;
952
+ }
953
+ }
954
+ prevx = thisx;
955
+ prevy = thisy;
956
+ ++pointindex;
957
+ }
958
+ }
959
+ beforeVertex.push_back (closestSegmentIndex);
960
+ break ;
961
+ }
1028
962
case QGis::WKBPolygon:
1029
963
{
1030
- closestSegmentIndex = 0 ;
1031
964
int index = 0 ;
1032
- unsigned char * ptr = mGeometry + 5 ;
965
+ unsigned char * ptr = mGeometry + 1 + sizeof ( int ) ;
1033
966
int * nrings = (int *)ptr;
1034
967
int * npoints = 0 ; // number of points in a ring
1035
968
ptr += sizeof (int );
@@ -1061,6 +994,46 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
1061
994
beforeVertex.push_back (closestSegmentIndex);
1062
995
break ;
1063
996
}
997
+ case QGis::WKBMultiPolygon:
998
+ {
999
+ unsigned char * ptr = mGeometry +1 +sizeof (int );
1000
+ int * nRings = 0 ;
1001
+ int * nPoints = 0 ;
1002
+ int pointindex = 0 ;
1003
+ int * nPolygons = (int *)ptr;
1004
+ ptr += sizeof (int );
1005
+ for (int polynr = 0 ; polynr < *nPolygons; ++polynr)
1006
+ {
1007
+ nRings = (int *)ptr;
1008
+ ptr += sizeof (int );
1009
+ for (int ringnr = 0 ; ringnr < *nRings; ++ringnr)
1010
+ {
1011
+ nPoints = (int *)ptr;
1012
+ prevx = 0 ;
1013
+ prevy = 0 ;
1014
+ for (int pointnr = 0 ; pointnr < *nPoints; ++pointnr)
1015
+ {
1016
+ thisx = (double *)ptr;
1017
+ ptr += sizeof (double );
1018
+ thisy = (double *)ptr;
1019
+ ptr += sizeof (double );
1020
+ if (prevx && prevy)
1021
+ {
1022
+ if ((testdist = distanceSquaredPointToSegment (point, prevx, prevy, thisx, thisy, minDistPoint)) < sqrDist )
1023
+ {
1024
+ closestSegmentIndex = pointindex;
1025
+ sqrDist = testdist;
1026
+ }
1027
+ }
1028
+ prevx = thisx;
1029
+ prevy = thisy;
1030
+ ++pointindex;
1031
+ }
1032
+ }
1033
+ }
1034
+ beforeVertex.push_back (closestSegmentIndex);
1035
+ break ;
1036
+ }
1064
1037
} // switch (wkbType)
1065
1038
1066
1039
} // if (mGeometry)
0 commit comments