[Mapserver-dev] Mapserver 4.0.1 imageOffsetPolyline
damiano.morosi at fastwebnet.it
damiano.morosi at fastwebnet.it
Tue May 11 04:01:11 EDT 2004
You can use the following function instead the one given with the source
code. It gives a constant offset in pixel by giving a -98 offsety in the
mapfile:
double angle_fromPoints(double x1, double y1, double x2, double y2)
{
if(x1 == x2)
if(y2 > y1)
return M_PI/2;
else
return -M_PI/2;
else
if(x2 > x1)
return atan((y2-y1)/(x2-x1));
else
return M_PI + atan((y2-y1)/(x2-x1));
}
static void imageOffsetPolyline(gdImagePtr img, shapeObj *p, int color,
int offsetx, int offsety)
{
int n,i,j;
double *x,*y,x0,y0,x1,y1,x2,y2,k;
if(offsety == -98)
{
n = p->line[0].numpoints;
/* alloco lo spazion per i due vettori che conterranno i punti */
x = (double *)calloc(n, sizeof(double));
y = (double *)calloc(n, sizeof(double));
/* riempio i vettori */
for(i=0; i<n; i++)
{
x[i] = p->line[0].point[i].x;
y[i] = p->line[0].point[i].y;
}
/***************************************************************************
a questo punto nelle prime mcn posizioni dei vettori mcx e mcy ci sono
le coordinate per cui si devono calcolare gli offset
adesso ricopio e adatto l'algoritmo per l'offset delle polilinee
in queta versione adotto l'algoritmo semplificato del mapserver
non dovrebbe essere complicato implementare l'algoritmo di transportation
****************************************************************************/
double a1, a2;
//first point
a2 = angle_fromPoints(x[0],y[0],x[1],y[1]);
x0 = x[0] - offsetx * cos(M_PI/2 - a2);
y0 = y[0] + offsetx * sin(M_PI/2 - a2);
//middle points
for(i=1;i<n-1;i++)
{
a1 = a2;
a2 = angle_fromPoints(x[i],y[i],x[i+1],y[i+1]);
//determina il punto 1
x1 = x[i] - offsetx * cos(M_PI/2 - a1);
y1 = y[i] + offsetx * sin(M_PI/2 - a1);
//determina il punto 2
x2 = x[i] - offsetx * cos(M_PI/2 - a2);
y2 = y[i] + offsetx * sin(M_PI/2 - a2);
if(abs(cos((a2 - a1)/2)) < SMALL_ANGLE_SIN)
{
x1 = (x1 + x2)/2;
y1 = (y1 + y2)/2;
}
else
{
k = offsetx * tan((a2 - a1)/2);
x1 = (x1 - k * cos(a1));
y1 = (y1 - k * sin(a1));
}
gdImageLine(img, (int)x0, (int)y0, (int)x1, (int)y1, color);
x0 = x1;
y0 = y1;
}
//last point
x1 = x[n-1] - offsetx * cos(M_PI/2 - a2);
y1 = y[n-1] + offsetx * sin(M_PI/2 - a2);
gdImageLine(img, (int)x0, (int)y0, (int)x1, (int)y1, color);
}
else { // normal offset (eg. drop shadow)
for (i = 0; i < p->numlines; i++)
for(j=1; j<p->line[i].numpoints; j++)
gdImageLine(img, (int)p->line[i].point[j-1].x+offsetx, (int)p->line[i].point[j-1].y+offsety,
(int)p->line[i].point[j].x+offsetx, (int)p->line[i].point[j].y+offsety,
color);
}
}
More information about the mapserver-dev
mailing list