MCPcopy Create free account
hub / github.com/MapServer/MapServer / msDistanceShapeToShape

Function msDistanceShapeToShape

mapsearch.c:517–663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517double msDistanceShapeToShape(shapeObj *shape1, shapeObj *shape2)
518{
519 int i,j,k,l;
520 double dist, minDist=-1;
521
522 switch(shape1->type) {
523 case(MS_SHAPE_POINT): /* shape1 */
524 for(i=0;i<shape1->numlines;i++) {
525 for(j=0; j<shape1->line[i].numpoints; j++) {
526 dist = msSquareDistancePointToShape(&(shape1->line[i].point[j]), shape2);
527 if((dist < minDist) || (minDist < 0))
528 minDist = dist;
529 }
530 }
531 minDist = sqrt(minDist);
532 break;
533 case(MS_SHAPE_LINE): /* shape1 */
534 switch(shape2->type) {
535 case(MS_SHAPE_POINT):
536 for(i=0;i<shape2->numlines;i++) {
537 for(j=0; j<shape2->line[i].numpoints; j++) {
538 dist = msSquareDistancePointToShape(&(shape2->line[i].point[j]), shape1);
539 if((dist < minDist) || (minDist < 0))
540 minDist = dist;
541 }
542 }
543 minDist = sqrt(minDist);
544 break;
545 case(MS_SHAPE_LINE):
546 for(i=0;i<shape1->numlines;i++) {
547 for(j=1; j<shape1->line[i].numpoints; j++) {
548 for(k=0;k<shape2->numlines;k++) {
549 for(l=1; l<shape2->line[k].numpoints; l++) {
550 /* check intersection (i.e. dist=0) */
551 if(msIntersectSegments(&(shape1->line[i].point[j-1]), &(shape1->line[i].point[j]), &(shape2->line[k].point[l-1]), &(shape2->line[k].point[l])) == MS_TRUE)
552 return(0);
553
554 /* no intersection, compute distance */
555 dist = msDistanceSegmentToSegment(&(shape1->line[i].point[j-1]), &(shape1->line[i].point[j]), &(shape2->line[k].point[l-1]), &(shape2->line[k].point[l]));
556 if((dist < minDist) || (minDist < 0))
557 minDist = dist;
558 }
559 }
560 }
561 }
562 break;
563 case(MS_SHAPE_POLYGON):
564 /* shape2 (the polygon) could contain shape1 or one of it's parts */
565 for(i=0; i<shape1->numlines; i++) {
566 if(msIntersectPointPolygon(&(shape1->line[0].point[0]), shape2) == MS_TRUE) /* this considers holes and multiple parts */
567 return(0);
568 }
569
570 /* check segment intersection and, if necessary, distance between segments */
571 for(i=0;i<shape1->numlines;i++) {
572 for(j=1; j<shape1->line[i].numpoints; j++) {
573 for(k=0;k<shape2->numlines;k++) {
574 for(l=1; l<shape2->line[k].numpoints; l++) {

Callers 4

msQueryByFeaturesFunction · 0.85
msQueryByShapeFunction · 0.85
msRasterQueryByRectLowFunction · 0.85
msGEOSDistanceFunction · 0.85

Calls 4

msIntersectSegmentsFunction · 0.85
msIntersectPointPolygonFunction · 0.85

Tested by

no test coverage detected