[gdal-dev] Usage of styles in C API

Nik Sands nixanz at nixanz.com
Sun Aug 3 03:35:08 PDT 2014


On one of the iterations through this code, styleChars is:

	'vegetation_low: BRUSH(fc:#A0F0A0); LABEL(c:#004000,s:18pt,t:{title})'

So perhaps the inclusion of the style name is the problem?

This was read into a style table from a text file using 'OGR_STBL_LoadStyleTable()'.  I had assumed that a similar format to .ofs was suitable.  If this is not the case, how should I read a style table from a text file in such a way that I can distinguish the various styles by name?

In guess my more general question is:  What is the correct way to read styles from an arbitrary text file into a style table, and then use a style manager to get the various parts/tools?



On 3 Aug 2014, at 8:26 pm, Even Rouault <even.rouault at mines-paris.org> wrote:

> 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