[mapserver-commits] r9120 - sandbox/aboudreault

svn at osgeo.org svn at osgeo.org
Thu Jun 25 14:52:25 EDT 2009


Author: aboudreault
Date: 2009-06-25 14:52:24 -0400 (Thu, 25 Jun 2009)
New Revision: 9120

Modified:
   sandbox/aboudreault/mapdraw.c
   sandbox/aboudreault/mapprimitive.c
Log:
modified the algorithm of the labels placement, in aboudreault sandbox

Modified: sandbox/aboudreault/mapdraw.c
===================================================================
--- sandbox/aboudreault/mapdraw.c	2009-06-25 16:35:17 UTC (rev 9119)
+++ sandbox/aboudreault/mapdraw.c	2009-06-25 18:52:24 UTC (rev 9120)
@@ -1613,7 +1613,7 @@
 
           annopoints = msPolylineLabelPointExtended(shape, minfeaturesize, (layer->class[c]->label).repeatdistance, &angles, &lengths, &numpoints, regularLines, numRegularLines);
           
-          for (i = 0; i < numRegularLines; i++)
+          for (i = 0; i < numpoints; i++)
             {
               labelObj label = layer->class[c]->label;
               
@@ -1970,7 +1970,7 @@
 
           annopoints = msPolylineLabelPointExtended(shape, minfeaturesize, (layer->class[c]->label).repeatdistance, &angles, &lengths, &numpoints, regularLines, numRegularLines);
           
-          for (i = 0; i < numRegularLines; i++)
+          for (i = 0; i < numpoints; i++)
           {
             labelObj label = layer->class[c]->label;
             

Modified: sandbox/aboudreault/mapprimitive.c
===================================================================
--- sandbox/aboudreault/mapprimitive.c	2009-06-25 16:35:17 UTC (rev 9119)
+++ sandbox/aboudreault/mapprimitive.c	2009-06-25 18:52:24 UTC (rev 9120)
@@ -1403,9 +1403,10 @@
 void msPolylineLabelPointLineString(shapeObj *p, int min_length, int repeat_distance, double ***angles, double ***lengths, double** segment_lengths,
                                     int line_index, double line_length, double total_length, int* labelpoints_index, int* labelpoints_size, pointObj ***labelpoints)
 {
-  int i, j, k, l, index, point_repeat, point_distance;
-  double t, tmp_length, theta, point_start_position, fwd_length;
- 
+  int i, j, k, l, n, index, point_repeat;
+  double t, tmp_length, theta, fwd_length, point_distance;
+  double center_point_position, left_point_position, right_point_position, point_position;
+  
   tmp_length = total_length;
   if (repeat_distance > 0)
     tmp_length = line_length;
@@ -1415,70 +1416,90 @@
 
   i = line_index;
   point_distance = 0;
+  point_repeat = 1;
+  left_point_position = right_point_position = center_point_position = line_length / 2.0; 
+  
+  if (repeat_distance > 0) {
+    point_repeat = line_length / repeat_distance;
+   
+    if (point_repeat > 1) {
+      if (point_repeat % 2 == 0)
+        point_repeat -= 1;
+      point_distance = (line_length / point_repeat); // buffer allowed per point
 
-  if (repeat_distance > 0) {
-    point_repeat = line_length / (repeat_distance);
-    point_distance = (line_length / point_repeat); // buffer allowed per point
+      // initial point position
+      left_point_position -= ((point_repeat-1)/2 * point_distance);
+      right_point_position += ((point_repeat-1)/2 * point_distance);
+
+      point_repeat = (point_repeat-1)/2+1;
+    }
+    else
+      point_repeat = 1;
   }
 
-  if (repeat_distance > 0 && point_repeat > 1) {
-    point_start_position = (point_distance / 2); 
-  }
-  else
+  for (l=0; l < point_repeat; ++l)
   {
-    point_repeat = 1;
-    point_start_position = line_length / 2.0;
-  }
-    
-  for (l=0; l < point_repeat; l++)
-  {
-    j=0;
-    fwd_length = 0;
-    while (fwd_length < point_start_position) {
-      fwd_length += segment_lengths[i][j++];
+    if (l == point_repeat-1) { // last point to place is always the center point 
+      point_position = center_point_position;
+      n = 1;
+    } 
+    else {
+      point_position = right_point_position;
+      n = 0;
     }
     
-    if (*labelpoints_index == *labelpoints_size) {
+    do {
+      j=0;
+      fwd_length = 0;
+      while (fwd_length < point_position) {
+        fwd_length += segment_lengths[i][j++];
+      }
+      
+      if (*labelpoints_index == *labelpoints_size) {
         *labelpoints_size *= 2;
         (*labelpoints) = (pointObj **) realloc(*labelpoints,sizeof(pointObj *) * (*labelpoints_size));
         (*angles) = (double **) realloc(*angles,sizeof(double *) * (*labelpoints_size));
         (*lengths) = (double **) realloc(*lengths,sizeof(double *) * (*labelpoints_size));
-    }
+      }
 
-    index = (*labelpoints_index)++;
-    (*labelpoints)[index] = (pointObj *) malloc(sizeof(pointObj));
-    (*angles)[index] = (double *) malloc(sizeof(double));
-    (*lengths)[index] = (double *) malloc(sizeof(double));
+      index = (*labelpoints_index)++;
+      (*labelpoints)[index] = (pointObj *) malloc(sizeof(pointObj));
+      (*angles)[index] = (double *) malloc(sizeof(double));
+      (*lengths)[index] = (double *) malloc(sizeof(double));
 
-    if (repeat_distance > 0)
-      *(*lengths)[index] = line_length;
-    else
-      *(*lengths)[index] = total_length;
+      if (repeat_distance > 0)
+        *(*lengths)[index] = line_length;
+      else
+        *(*lengths)[index] = total_length;
     
-    k = j;
-    if (j == p->line[i].numpoints-1)
-      k = j-1;
+      k = j;
+      if (j == p->line[i].numpoints-1)
+        k = j-1;
     
-    t = 1 - (fwd_length - point_start_position) / segment_lengths[i][j-1];
-    (*labelpoints)[index]->x = t * (p->line[i].point[k+1].x - p->line[i].point[k].x) + p->line[i].point[k].x;
-    (*labelpoints)[index]->y = t * (p->line[i].point[k+1].y - p->line[i].point[k].y) + p->line[i].point[k].y;
+      t = 1 - (fwd_length - point_position) / segment_lengths[i][j-1];
+      (*labelpoints)[index]->x = t * (p->line[i].point[k+1].x - p->line[i].point[k].x) + p->line[i].point[k].x;
+      (*labelpoints)[index]->y = t * (p->line[i].point[k+1].y - p->line[i].point[k].y) + p->line[i].point[k].y;
     
-    theta = asin(MS_ABS(p->line[i].point[j].x - p->line[i].point[j-1].x)/sqrt((pow((p->line[i].point[j].x - p->line[i].point[j-1].x),2.0) + pow((p->line[i].point[j].y - p->line[i].point[j-1].y),2.0))));
+      theta = asin(MS_ABS(p->line[i].point[j].x - p->line[i].point[j-1].x)/sqrt((pow((p->line[i].point[j].x - p->line[i].point[j-1].x),2.0) + pow((p->line[i].point[j].y - p->line[i].point[j-1].y),2.0))));
     
-    if(p->line[i].point[j-1].x < p->line[i].point[j].x) { /* i.e. to the left */
-      if(p->line[i].point[j-1].y < p->line[i].point[j].y) /* i.e. below */
-        *(*angles)[index] = -(90.0 - MS_RAD_TO_DEG*theta);
-      else
-        *(*angles)[index] = (90.0 - MS_RAD_TO_DEG*theta);      
-    } else {
-      if(p->line[i].point[j-1].y < p->line[i].point[j].y) /* i.e. below */
-        *(*angles)[index] = (90.0 - MS_RAD_TO_DEG*theta);
-      else
-        *(*angles)[index] = -(90.0 - MS_RAD_TO_DEG*theta);      
-    }
+      if(p->line[i].point[j-1].x < p->line[i].point[j].x) { /* i.e. to the left */
+        if(p->line[i].point[j-1].y < p->line[i].point[j].y) /* i.e. below */
+          *(*angles)[index] = -(90.0 - MS_RAD_TO_DEG*theta);
+        else
+          *(*angles)[index] = (90.0 - MS_RAD_TO_DEG*theta);      
+      } else {
+        if(p->line[i].point[j-1].y < p->line[i].point[j].y) /* i.e. below */
+          *(*angles)[index] = (90.0 - MS_RAD_TO_DEG*theta);
+        else
+          *(*angles)[index] = -(90.0 - MS_RAD_TO_DEG*theta);      
+      }
+      
+      point_position = left_point_position;
+      n++;
+    } while (n<2); // we place 2 labels at time
 
-    point_start_position += point_distance;
-    
+    right_point_position -= point_distance;
+    left_point_position += point_distance;
   }
 
   return;



More information about the mapserver-commits mailing list