patch for mapogcsld.c/h

Yewondwossen Assefa assefa at DMSOLUTIONS.CA
Tue Dec 12 10:19:34 EST 2006


Peter,

  I have added a bug related to this 
(http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=1985) and added your 
patch to mapserver cvs. If possible please confirm through the bug that 
your tests work with mapserver cvs.

Thanks

Peter Freimuth wrote:
> Dear Mapserver-Dev Team,
> I found a problem in mapogssld.c in context of using external Graphics.
> 
> I suggest to use  extGraphicName as SymbolName instead of the Unique
> Name of  created TmpFileName. This will reduce the amount of
> created       Symbols, and will also reduce the number of calls to
> msHTTPGetFile(). Find attached the modified functions based on code of
> current 4.10.0 Release.
> I also insert a LIMIT Check for static symbolset.symbol[] in
> msSLDGetGraphicSymbol to avoid a crash caused by inserting new Symbols.
> Kindest regards,
> Peter
> 
> 
> ------------------------------------------------------------------------
> 
> /* to be mpdified in mapogcsld.h*/
> int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char *extGraphicName);
> 
> /************************************************************************/
> /*                          msSLDGetGraphicSymbol                       */
> /*                                                                      */
> /*      Create a symbol entry for an inmap pixmap symbol. Returns       */
> /*      the symbol id.                                                  */
> /*      pf at mapmedia.de: added  extGraphicName as third parameter        
>         insert also an check for 
> 		  if(map->symbolset.numsymbols == MS_MAXSYMBOLS)
> 			
> 		  to avoid writing over the limit of symbolset.symbol[MS_MAXSYMBOLS]		
> 			
> */
> /************************************************************************/
> int msSLDGetGraphicSymbol(mapObj *map, char *pszFileName, char* extGraphicName)
> {
>     FILE *fp;
>     char bytes[8];
>     gdImagePtr img = NULL;
>     int nSymbolId = 0;
>     symbolObj *psSymbol = NULL;
> 
> 
>     if (map && pszFileName)
>     {
>     /*
>         nSymbolId = msGetSymbolIndex(&map->symbolset, 
>                                      extGraphicName, 
>                                      MS_FALSE);
>                                      */
>         if (nSymbolId <= 0)
>         {
>             if(map->symbolset.numsymbols == MS_MAXSYMBOLS) 
>             {    
>                  msSetError(MS_SYMERR, "Too many symbols defined.", "msSLDGetGraphicSymbol()");
>                  return 0; /* returs 0 for no symbol */
>             }
> 
>             /* check if a symbol of a  */
>             fp = fopen(pszFileName, "rb");
>             if (fp)
>             {
>                 fread(bytes,8,1,fp);
>                 rewind(fp);
>                 if (memcmp(bytes,"GIF8",4)==0)
>                 {
> #ifdef USE_GD_GIF
>                     img = gdImageCreateFromGif(fp);
> #endif
>                 }
>                 else if (memcmp(bytes,PNGsig,8)==0) 
>                 {
> #ifdef USE_GD_PNG
>                     img = gdImageCreateFromPng(fp);
> #endif        
>                 }
>                 fclose(fp);
> 
>                 if (img)
>                 {
>                     psSymbol = &map->symbolset.symbol[map->symbolset.numsymbols];
>                     nSymbolId = map->symbolset.numsymbols;
>                     map->symbolset.numsymbols++;
>                     initSymbol(psSymbol);
>                     psSymbol->inmapfile = MS_TRUE;
>                     psSymbol->sizex = 1;
>                     psSymbol->sizey = 1; 
>                     psSymbol->type = MS_SYMBOL_PIXMAP;
>                     psSymbol->name = strdup(extGraphicName);
>   
>                     psSymbol->img = img;
>                 }
>             }
>         }
>     }
>     return nSymbolId;
> }
> 
> 
> /************************************************************************/
> /*                        msSLDParseExternalGraphic                     */
> /*                                                                      */
> /*      Parse extrenal graphic node : download the symbol referneced    */
> /*      by the URL and create a PIXMAP inmap symbol. Only GIF and       */
> /*      PNG are supported.                                              */
> /************************************************************************/
> void msSLDParseExternalGraphic(CPLXMLNode *psExternalGraphic, 
>                                styleObj *psStyle,  mapObj *map)
> {
> /* needed for libcurl function msHTTPGetFile in maphttp.c */
> #if defined(USE_WMS_LYR) || defined(USE_WFS_LYR)
> 
>     char *pszFormat = NULL;
>     CPLXMLNode *psURL=NULL, *psFormat=NULL, *psTmp=NULL;
>     char *pszURL=NULL, *pszTmpSymbolName=NULL;
>     int status;
> 
>     if (psExternalGraphic && psStyle && map)
>     {
>         psFormat = CPLGetXMLNode(psExternalGraphic, "Format");
>         if (psFormat && psFormat->psChild && psFormat->psChild->pszValue)
>           pszFormat = psFormat->psChild->pszValue;
> 
>         /* supports GIF and PNG */
>         if (pszFormat && 
>             (strcasecmp(pszFormat, "GIF") == 0 ||
>              strcasecmp(pszFormat, "image/gif") == 0 || 
>              strcasecmp(pszFormat, "PNG") == 0 ||
>              strcasecmp(pszFormat, "image/png") == 0))
>         {
>           
>           /* <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.vendor.com/geosym/2267.svg"/> */
>             psURL = CPLGetXMLNode(psExternalGraphic, "OnlineResource");
>             if (psURL && psURL->psChild)
>             {
>                 psTmp =  psURL->psChild;
>                 while (psTmp != NULL && 
>                        psTmp->pszValue && 
>                        strcasecmp(psTmp->pszValue, "xlink:href") != 0)
>                 {
>                     psTmp = psTmp->psNext;
>                 }
>                 if (psTmp && psTmp->psChild)
>                 {
>                     pszURL = (char*)psTmp->psChild->pszValue;
>                     /* pf at mapmedia.de:
>                     check if this external graphic is allready in Symbollist; 
>                     avoids unnecessary http requests; 
>                     this works only if we use the url as symbol->name hashkey!
>                     */
>                     psStyle->symbol = msGetSymbolIndex(&map->symbolset, 
>                                      pszURL, 
>                                      MS_FALSE);
>                     if (psStyle->symbol <= 0) 
>                     {
>                         if (strcasecmp(pszFormat, "GIF") == 0 || 
>                             strcasecmp(pszFormat, "image/gif") == 0)
>                             pszTmpSymbolName = msTmpFile(map->mappath, map->web.imagepath, "gif");
>                         else
>                             pszTmpSymbolName = msTmpFile(map->mappath, map->web.imagepath, "png");
> 
>                         if (msHTTPGetFile(pszURL, pszTmpSymbolName, &status,-1, 0, 0) == MS_SUCCESS)
>                         {
>                             psStyle->symbol = msSLDGetGraphicSymbol(map, pszTmpSymbolName, pszURL);
>                             if (psStyle->symbol > 0 && psStyle->symbol < map->symbolset.numsymbols)
>                                 psStyle->symbolname = strdup(map->symbolset.symbol[psStyle->symbol].name);
> 
>                             /* set the color parameter if not set. Does not make sense */
>                             /* for pixmap but mapserver needs it. */
>                             if (psStyle->color.red == -1 || psStyle->color.green || psStyle->color.blue)
>                             {
>                                 psStyle->color.red = 0;
>                                 psStyle->color.green = 0;
>                                 psStyle->color.blue = 0;
>                             }
>                         }        
>                     } else {
>                             if (psStyle->symbol > 0 && psStyle->symbol < map->symbolset.numsymbols)
>                                 psStyle->symbolname = strdup(map->symbolset.symbol[psStyle->symbol].name);
> 
>                             /* set the color parameter if not set. Does not make sense */
>                             /* for pixmap but mapserver needs it. */
>                             if (psStyle->color.red == -1 || psStyle->color.green || psStyle->color.blue)
>                             {
>                                 psStyle->color.red = 0;
>                                 psStyle->color.green = 0;
>                                 psStyle->color.blue = 0;
>                             }
>                     }
>                 }
>             }
>         }
>     }
> #endif
> }
> 
>  
> 


-- 
----------------------------------------------------------------
Assefa Yewondwossen
Software Analyst

Email: assefa at dmsolutions.ca
http://www.dmsolutions.ca/

Phone: (613) 565-5056 (ext 14)
Fax:   (613) 565-0925
----------------------------------------------------------------



More information about the mapserver-dev mailing list