Thanks Even, Yes, deleting the spaces seems to get it working correctly. Is this expected? Are spaces an illegal part of a style string?
The documentation includes spaces in the example .ofs file there, so I had copied that format when creating my text file. Cheers, Nik. On 3 Aug 2014, at 8:45 pm, Even Rouault <even.roua...@mines-paris.org> wrote: > Le dimanche 03 août 2014 12:41:56, Nik Sands a écrit : >> Sorry, my mistake... I had my logging in the wrong place. styleChars is >> actually of the form (including the leading space): >> >> ' PEN(c:#A08080,w:2pt); LABEL(c:#000000,s:18pt,t:{title})' > > The issue must be the leading space before PEN, and potentially LABEL too. > >> >> On 3 Aug 2014, at 8:35 pm, Nik Sands <nix...@nixanz.com> wrote: >>> 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.roua...@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@lists.osgeo.org >>>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev >>> >>> _______________________________________________ >>> gdal-dev mailing list >>> gdal-dev@lists.osgeo.org >>> http://lists.osgeo.org/mailman/listinfo/gdal-dev > > -- > Geospatial professional services > http://even.rouault.free.fr/services.html _______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev