Ejemplo n.º 1
0
int mapObj_setSymbolSet(mapObj *self,
                        char *szFileName)
{
    msFreeSymbolSet(&self->symbolset);
    msInitSymbolSet(&self->symbolset);
   
    // Set symbolset filename
    self->symbolset.filename = strdup(szFileName);

    // Symbolset shares same fontset as main mapfile
    self->symbolset.fontset = &(self->fontset);

    return msLoadSymbolSet(&self->symbolset, self);
}
Ejemplo n.º 2
0
Handle<Value> MSMap::SetSymbolSet(const Arguments &args) {
  HandleScope scope;
  int result;
  MSMap *map = ObjectWrap::Unwrap<MSMap>(args.This());
  REQ_STR_ARG(0, symbolfile);

  msFreeSymbolSet(&(map->this_->symbolset));
  msInitSymbolSet(&(map->this_->symbolset));

  // Set symbolset filename
  map->this_->symbolset.filename = strdup(*symbolfile);

  // Symbolset shares same fontset as main mapfile
  map->this_->symbolset.fontset = &(map->this_->fontset);

  result = msLoadSymbolSet(&(map->this_->symbolset), map->this_);
  return scope.Close(Number::New(result));
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
  FILE *stream;
  int ns,n,k;
  gdImagePtr img;
  shapeObj p;
  int i,j;
  int ncols,nrows;
  char buffer[256];
  int gray, green, red, black, white;
  classObj class;
  symbolSetObj symbolSet;

   /* ---- check the number of arguments, return syntax if not correct ---- */
  if( argc < 2 ) {
      fprintf(stdout, "Syntax: sym2img [symbolset] [outfile]\n" );
      exit(0);
  }

  /* Initialize the polygon/polyline */
  p.line = (lineObj *)malloc(sizeof(lineObj));
  p.numlines = 1;
  p.line[0].point = (pointObj *)malloc(sizeof(pointObj)*4);
  p.line[0].numpoints = 4;

  /* Initialize the symbol and font sets */
  symbolSet.filename = msStrdup(argv[1]);

  /* 
  ** load the symbol file
  */
  if(msLoadSymbolSet(&symbolSet) == -1) { 
    msWriteError(stderr);
    exit(1);
  }
  
  ns = symbolSet.numsymbols;

  if(ns < NCOLS) {
    ncols = ns;
    nrows = 1;
  } else {
    ncols = NCOLS;
    nrows = (int)ceil((double)ns/NCOLS);
  }

  img = gdImageCreate(ncols*CELLSIZE, nrows*CELLSIZE);

  gray = gdImageColorAllocate(img, 222, 222, 222);
  white = gdImageColorAllocate(img, 255, 255, 255);
  green = gdImageColorAllocate(img, 40, 170, 40);
  black = gdImageColorAllocate(img, 0, 0, 0);
  red = gdImageColorAllocate(img, 255, 0, 0);

  class.color = red;
  class.backgroundcolor = white;
  class.outlinecolor = black;

  n=0;

  for(i=0; n<ns;i+=CELLSIZE) {
	k=0;
    for(j=0; n<ns;j+=CELLSIZE) {
	  if (k == ncols) break;
	  k++;
      gdImageFilledRectangle(img,j,i,j+CELLSIZE, i+CELLSIZE, gray);

      class.symbol = n;

      switch(symbolSet.type) {
      case(MS_MARKERSET):
	class.sizescaled = RATIO*CELLSIZE;
	p.line[0].point[0].x = MS_NINT(j + CELLSIZE/2);
	p.line[0].point[0].y = MS_NINT(i + CELLSIZE/2);
	p.line[0].numpoints = 1;
	msDrawMarkerSymbol(&(symbolSet), img, &(p.line[0].point[0]), &(class));
	break;

      case(MS_LINESET):
	class.sizescaled = 1;
	p.line[0].point[0].x = j;
        p.line[0].point[0].y = i + (CELLSIZE-LBUF) - 1;
	p.line[0].point[1].x = j + MS_NINT((CELLSIZE-LBUF)/3.0) - 1;
        p.line[0].point[1].y = i;
        p.line[0].point[2].x = j + MS_NINT(2*(CELLSIZE-LBUF)/3.0) - 1;
        p.line[0].point[2].y = i + (CELLSIZE-LBUF) - 1;
	p.line[0].point[3].x = j + (CELLSIZE-LBUF) - 1;
        p.line[0].point[3].y = i;
	p.line[0].numpoints = 4;
        msDrawLineSymbol(&(symbolSet), img, &p, &(class));
	break;

      case(MS_SHADESET):
	class.sizescaled = 5;
	p.line[0].point[0].x = j;
	p.line[0].point[0].y = i;
	p.line[0].point[1].x = j + CELLSIZE-1;
	p.line[0].point[1].y = i;
	p.line[0].point[2].x = j + CELLSIZE-1;
	p.line[0].point[2].y = i + CELLSIZE-1 ;
	p.line[0].point[3].x = j;
	p.line[0].point[3].y = i + CELLSIZE-1;
	p.line[0].numpoints = 4;
	msDrawShadeSymbol(&(symbolSet), img, &p, &(class));
	break;

      default:
	break;
      }

      if(symbolSet.symbol[n]->name)
        snprintf(buffer, sizeof(buffer), "%d - %s", n, symbolSet.symbol[n]->name);
      else
        snprintf(buffer, sizeof(buffer), "%d", n);
      gdImageString(img, gdFontTiny, j+1, i+1, buffer, black);

      n++;
    }
  }

 if((stream = fopen(argv[2],"wb")) == NULL) { /* open the file */
    fprintf(stderr, "Unable to open output file: %s\n", argv[2]);
    exit(1);
  }
#ifndef USE_GD_1_6
  gdImageGif(img, stream);
#else
  gdImagePng(img, stream);
#endif
  gdImageDestroy(img);
  free(symbolSet.filename);
  fclose(stream);

  return(MS_TRUE);
}