MS RFC 88:将MapServer对象保存到字符串¶
- 日期
2013年1月15日
- 作者
塔玛斯塞克勒斯
- 联系方式
gmail.com上的szekerest
- 状态
接受(2013/03/02),实施
- 版本
映射服务器6.3-dev
1。概述¶
此RFC提供了将映射对象保存到字符串作为 Mapfile 字符串片段的选项。此功能主要用于mapscript,并将向相应的对象添加一个新方法(convertToString)。此新方法将为已添加到RFC 31范围内的updateFromString提供反转选项。
2。建议的解决方案¶
该解决方案将在写入 Mapfile 时使用现有的MSIO机器。实现的关键点是用mapfile.c和mapsymbol.c中的msio_fprintf替换所有出现的fprintf。此替换将建立将mapfile写入重定向到缓冲区的选项。
三。实施细节¶
假设替换了fprintf,则可以通过为每种对象类型添加一个新的函数来实现将对象写入字符串,如下所示:
char* msWriteLayerToString(layerObj *layer)
{
msIOContext context;
msIOBuffer buffer;
context.label = NULL;
context.write_channel = MS_TRUE;
context.readWriteFunc = msIO_bufferWrite;
context.cbData = &buffer;
buffer.data = NULL;
buffer.data_len = 0;
buffer.data_offset = 0;
msIO_installHandlers( NULL, &context, NULL );
writeLayer(stdout, 0, layer);
msIO_bufferWrite( &buffer, "", 1 );
msIO_installHandlers( NULL, NULL, NULL );
return buffer.data;
}
返回的缓冲区的所有权被传递给调用方,所以我们应该在层中挂接这个函数。如下:
%newobject convertToString;
char* convertToString()
{
return msWriteLayerToString(self);
}
为了实现MAPOBJ的编写器(MSWriteMapToString),我们需要将单独的函数writemap和mssavemap中的大部分编写代码隔离开来。在这方面,mssavemap现在看起来像:
int msSaveMap(mapObj *map, char *filename)
{
FILE *stream;
char szPath[MS_MAXPATHLEN];
if(!map) {
msSetError(MS_MISCERR, "Map is undefined.", "msSaveMap()");
return(-1);
}
if(!filename) {
msSetError(MS_MISCERR, "Filename is undefined.", "msSaveMap()");
return(-1);
}
stream = fopen(msBuildPath(szPath, map->mappath, filename), "w");
if(!stream) {
msSetError(MS_IOERR, "(%s)", "msSaveMap()", filename);
return(-1);
}
writeMap(stream, 0, map);
fclose(stream);
return(0);
}
由于这个实现的结果,下面的新函数将在mapserver.h中公开
MS_DLL_EXPORT char *msWriteLayerToString(layerObj *layer);
MS_DLL_EXPORT char *msWriteMapToString(layerObj *layer);
MS_DLL_EXPORT char *msWriteClassToString(classObj *_class);
MS_DLL_EXPORT char *msWriteStyleToString(styleObj *style);
MS_DLL_EXPORT char *msWriteLabelToString(labelObj *label)
MS_DLL_EXPORT char *msWriteWebToString(webObj *web)
MS_DLL_EXPORT char *msWriteScalebarToString(scalebarObj *scalebar)
MS_DLL_EXPORT char *msWriteQueryMapToString(queryMapObj *querymap)
MS_DLL_EXPORT char *msWriteReferenceMapToString(referenceMapObj *ref)
MS_DLL_EXPORT char *msWriteLegendToString(legendObj *legend)
MS_DLL_EXPORT char *msWriteClusterToString(clusterObj *cluster)
4。受影响的文件¶
mapserver.h:公开mswritexxxtoString方法
mapfile.c:实现mswritexxxtoString方法
mapsymbol.c:实现mswritesymboltostring方法
mapscript/swiginc/map.i:添加convertToString方法
mapscript/swiginc/layer.i:添加convertToString方法
mapscript/swiginc/class.i:添加convertToString方法
mapscript/swiginc/web.i:添加converttoString方法
mapscript/swiginc/legend.i:添加converttoString方法
mapscript/swiginc/scalebar.i:添加convertToString方法
mapscript/swiginc/querymap.i:添加converttoString方法
mapscript/swiginc/referencemap.i:添加convertToString方法
mapscript/swiginc/cluster.i:添加converttoString方法
mapscript/swiginc/label.i:添加converttoString方法
mapscript/swiginc/style.i:添加convertToString方法
mapscript/php/php_mapscript.h:声明新函数
mapscript/php/mapscript_i.c:为新函数添加proxyyes
mapscript/php/map.c:添加converttoString方法
mapscript/php/layer.c:添加converttoString方法
mapscript/php/class.c:添加converttoString方法
mapscript/php/web.c:添加converttoString方法
mapscript/php/legend.c:添加converttoString方法
mapscript/php/scalebar.c:添加convertToString方法
mapscript/php/querymap.c:添加converttoString方法
mapscript/php/referencemap.c:添加converttoString方法
mapscript/php/cluster.c:添加converttoString方法
mapscript/php/label.c:添加converttoString方法
mapscript/php/style.c:添加converttoString方法
6。向后兼容性问题¶
不需要,新功能。
7。mapscript更改¶
新的函数convertToString将添加到相应的对象中。
8。投票历史¶
Tom Kralidis+1 Steve Lime+1 Jeff McKenna+1 Daniel Morissette+1 Umberto Nicoletti+1 Michael Smith+1 Tamas Szekeres+1 Stephen Woodbridge+1