[gdal-dev] Usage of styles in C API

Even Rouault even.rouault at mines-paris.org
Sun Aug 3 03:26:03 PDT 2014


Le dimanche 03 août 2014 12:11:42, Nik Sands a écrit :
> I'm just starting out using the styles features of OGR (using the C API)
> but at struggling with a few elements of it.
> 
> My code (copied below) fails to get any OGRStyleToolH.  Ie, the "if ( tool
> )" block never gets run, because 'tool' is always NULL at the point
> indicated by the comment.  But the execution does reach that point in the
> code which indicates that the OGRStyleMrgH does in fact include at least
> one part (tool).
> 
> I'd be grateful if somebody could point out what I'm doing wrong.

Nothing strikes me as wrong. A potential explanation is that styleChars 
doesn't contain a valid OGR Feature Style string.
GetPartCount() counts the number of ";" separating style parts, but it doens't 
check that each style part actually begins by a recognized tool name (PEN, 
BRUSH, SYMBOL, LABEL). OGR_SM_GetPart() does this check however and if it 
cannot recognize it it returns a NULL tool.

> 
> Thanks,
> Nik.
> 
> 
> -------------------------------------------
> 	const char *styleChars = OGR_STBL_GetNextStyle(table) ) )
> 	NSString *styleName = [NSString
> stringWithUTF8String:OGR_STBL_GetLastStyleName(table)]; OGRStyleMgrH
> styleMgr = OGR_SM_Create(NULL);
> 	OGR_SM_InitStyleString(styleMgr, styleChars);
> 
> 
> 	for ( int i = 0; i < OGR_SM_GetPartCount(styleMgr, NULL); i++ )
> 	{
> 		OGRStyleToolH tool = OGR_SM_GetPart(styleMgr, i, NULL);
> 
> 		if ( tool )  //  'tool' always NULL here
> 		{
> 			switch ( OGR_ST_GetType(tool) )
> 			{
> 				case OGRSTCPen:
> 					self.pen = tool;
> 					break;
> 
> 				case OGRSTCBrush:
> 					self.brush = tool;
> 					break;
> 
> 				case OGRSTCSymbol:
> 					self.symbol = tool;
> 					break;
> 
> 				case OGRSTCLabel:
> 					self.label = tool;
> 					break;
> 
> 				default:
> 					NSLog(@"Unknown style tool type!");
> 					break;
> 			}
> 		}
> 	}
> -------------------------------------------
> 
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list