From: Kevin Neufeld Date: Thu, 14 May 2009 23:42:02 +0000 (+0000) Subject: added styles to the generated documentation images X-Git-Tag: 1.4.0b1~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9bf9327b74bb6d8c5cc4767edf84f724f4a4d651;p=postgis added styles to the generated documentation images added ImageMagick as a dependency git-svn-id: http://svn.osgeo.org/postgis/trunk@4081 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/configure.ac b/configure.ac index 3f2ad0c0f..c95cad9fe 100644 --- a/configure.ac +++ b/configure.ac @@ -85,6 +85,11 @@ dnl dnl Search for xsltproc which is required for building documentation dnl +AC_PATH_PROG([IMAGEMAGICK], [convert], []) +if test "x$IMAGEMAGICK" = "x"; then + AC_MSG_WARN([ImageMagick does not seem to be installed. Documentation cannot be built]) +fi + AC_PATH_PROG([XSLTPROC], [xsltproc], []) if test "x$XSLTPROC" = "x"; then AC_MSG_WARN([xsltproc is not installed so documentation cannot be built]) diff --git a/doc/Makefile.in b/doc/Makefile.in index 30f06fbfb..4200ecfb9 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -49,9 +49,13 @@ else ifeq ($(XSLBASE),) all: requirements_not_met_xslbase else +ifeq ($(IMAGEMAGICK),) +all: requirements_not_met_imagemagick +else all: html/postgis.html ../postgis_comments.sql endif endif +endif postgis_aggs_mm.xml: ./xsl/postgis_aggs_mm.xml.xsl reference.xml $(XSLTPROC) ./xsl/postgis_aggs_mm.xml.xsl reference.xml > $@ @@ -107,7 +111,7 @@ doxygen: doxygen.cfg doxygen $< images: - make -C html/image_src + make -C html/image_src images clean: make -C html/image_src clean @@ -149,5 +153,14 @@ requirements_not_met_xslbase: @echo " http://postgis.refractions.net/docs" @echo +requirements_not_met_imagemagick: + @echo + @echo "configure was unable to find the ImageMagick's 'convert' utility program." + @echo "To build the documentation, install ImageMagick and then re-run configure. Alternatively " + @echo "refer to online manual:" + @echo + @echo " http://postgis.refractions.net/docs" + @echo + .PHONY: html diff --git a/doc/html/image_src/Makefile.in b/doc/html/image_src/Makefile.in index 0ab59911f..51da89d1c 100644 --- a/doc/html/image_src/Makefile.in +++ b/doc/html/image_src/Makefile.in @@ -36,22 +36,34 @@ IMAGES= \ ../images/st_isvalid02.png \ ../images/st_isvalid03.png \ ../images/st_isvalid04.png \ - ../images/st_isvalid05.png + ../images/st_isvalid05.png \ + ../images/st_isvalid06.png \ + ../images/st_isvalid07.png \ + ../images/st_isvalid08.png \ + ../images/st_touches01.png \ + ../images/st_touches02.png \ + ../images/st_touches03.png \ + ../images/st_touches04.png \ + ../images/st_touches05.png \ + ../images/st_touches06.png -OBJS=generator.o +OBJS=styles.o generator.o # Build the generator -all: $(IMAGES) +all: generator + +# generate the images +images: $(IMAGES) # Command to build each of the .o files $(OBJS): %.o: %.c $(CC) $(CFLAGS) $(CUNIT_CPPFLAGS) -c -o $@ $< # Command to build each of the .wkt files -$(IMAGES): ../images/%.png: %.wkt generator +$(IMAGES): ../images/%.png: %.wkt generator styles.conf @./generator $< -# Build the main unit test executable +# Build the main executable generator: ../../../liblwgeom/liblwgeom.a $(OBJS) $(CC) -o $@ $(OBJS) ../../../liblwgeom/liblwgeom.a -lm $(CUNIT_LDFLAGS) diff --git a/doc/html/image_src/generator.c b/doc/html/image_src/generator.c index 3d0e34180..5614ce135 100644 --- a/doc/html/image_src/generator.c +++ b/doc/html/image_src/generator.c @@ -30,9 +30,11 @@ #include #include #include +#include #include "CUnit/Basic.h" #include "lwalgorithm.h" +#include "styles.h" #define SHOW_DIGS_DOUBLE 15 #define MAX_DOUBLE_PRECISION 15 @@ -41,26 +43,16 @@ // Some global styling variables char *imageSize = "200x200"; -typedef struct { - int pointSize; - char *pointColor; - - int lineWidth; - char *lineColor; - - char *polygonFillColor; - char *polygonStrokeColor; - int polygonStrokeWidth; -} LAYERSTYLE; +int getStyleName(char **styleName, char* line); /** * Set up liblwgeom to run in stand-alone mode using the * usual system memory handling functions. */ void lwgeom_init_allocators(void) { - /* liblwgeom callback - install default handlers */ - lwgeom_install_default_allocators(); + /* liblwgeom callback - install default handlers */ + lwgeom_install_default_allocators(); } /** @@ -103,9 +95,7 @@ pointarrayToString(char *output, POINTARRAY *pa) { * @return the numbers of character written to *output */ static size_t -drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE style) { - LWDEBUGF( 4, "%s", "enter drawPoint" ); - +drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE *styles) { char x[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1]; char y1[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1]; char y2[MAX_DIGS_DOUBLE+MAX_DOUBLE_PRECISION+1]; @@ -118,10 +108,10 @@ drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE style) { trim_trailing_zeros(x); sprintf(y1, "%f", p.y); trim_trailing_zeros(y1); - sprintf(y2, "%f", p.y + style.pointSize); + sprintf(y2, "%f", p.y + styles->pointSize); trim_trailing_zeros(y2); - ptr += sprintf(ptr, "-fill %s -strokewidth 5 ", style.pointColor); + ptr += sprintf(ptr, "-fill %s -strokewidth 0 ", styles->pointColor); ptr += sprintf(ptr, "-draw \"circle %s,%s %s,%s", x, y1, x, y2); ptr += sprintf(ptr, "'\" "); @@ -138,11 +128,10 @@ drawPoint(char *output, LWPOINT *lwp, LAYERSTYLE style) { * @return the numbers of character written to *output */ static size_t -drawLineString(char *output, LWLINE *lwl, LAYERSTYLE style) { - LWDEBUGF( 4, "%s", "enter drawLineString" ); +drawLineString(char *output, LWLINE *lwl, LAYERSTYLE *style) { char *ptr = output; - ptr += sprintf(ptr, "-fill none -stroke %s -strokewidth %d ", style.lineColor, style.lineWidth); + ptr += sprintf(ptr, "-fill none -stroke %s -strokewidth %d ", style->lineColor, style->lineWidth); ptr += sprintf(ptr, "-draw \"stroke-linecap round stroke-linejoin round path 'M "); ptr += pointarrayToString(ptr, lwl->points ); ptr += sprintf(ptr, "'\" "); @@ -160,13 +149,11 @@ drawLineString(char *output, LWLINE *lwl, LAYERSTYLE style) { * @return the numbers of character written to *output */ static size_t -drawPolygon(char *output, LWPOLY *lwp, LAYERSTYLE style) { - LWDEBUGF( 4, "%s", "enter drawPolygon" ); - +drawPolygon(char *output, LWPOLY *lwp, LAYERSTYLE *style) { char *ptr = output; int i; - ptr += sprintf(ptr, "-fill %s -stroke %s -strokewidth %d ", style.polygonFillColor, style.polygonStrokeColor, style.polygonStrokeWidth ); + ptr += sprintf(ptr, "-fill %s -stroke %s -strokewidth %d ", style->polygonFillColor, style->polygonStrokeColor, style->polygonStrokeWidth ); ptr += sprintf(ptr, "-draw \"path '"); for (i=0; inrings; i++) { ptr += sprintf(ptr, "M "); @@ -188,29 +175,27 @@ drawPolygon(char *output, LWPOLY *lwp, LAYERSTYLE style) { * @return the numbers of character written to *output */ static size_t -drawGeometry(char *output, LWGEOM *lwgeom, LAYERSTYLE style ) { - LWDEBUGF( 4, "%s", "enter drawGeometry" ); +drawGeometry(char *output, LWGEOM *lwgeom, LAYERSTYLE *styles ) { char *ptr = output; int i; int type = lwgeom_getType(lwgeom->type); - LWDEBUGF( 4, "switching on %d", type ); switch(type) { case POINTTYPE: - ptr += drawPoint(ptr, (LWPOINT*)lwgeom, style ); + ptr += drawPoint(ptr, (LWPOINT*)lwgeom, styles ); break; case LINETYPE: - ptr += drawLineString(ptr, (LWLINE*)lwgeom, style ); + ptr += drawLineString(ptr, (LWLINE*)lwgeom, styles ); break; case POLYGONTYPE: - ptr += drawPolygon(ptr, (LWPOLY*)lwgeom, style ); + ptr += drawPolygon(ptr, (LWPOLY*)lwgeom, styles ); break; case MULTIPOINTTYPE: case MULTILINETYPE: case MULTIPOLYGONTYPE: case COLLECTIONTYPE: for (i=0; i<((LWCOLLECTION*)lwgeom)->ngeoms; i++) { - ptr += drawGeometry( ptr, lwcollection_getsubgeom ((LWCOLLECTION*)lwgeom, i), style ); + ptr += drawGeometry( ptr, lwcollection_getsubgeom ((LWCOLLECTION*)lwgeom, i), styles ); } break; } @@ -226,12 +211,14 @@ drawGeometry(char *output, LWGEOM *lwgeom, LAYERSTYLE style ) { */ static void addDropShadow(int layerNumber) { - char str[129]; + // TODO: change to properly sized string + char str[512]; sprintf( str, "convert tmp%d.png -gravity center \\( +clone -background navy -shadow 100x3+4+4 \\) +swap -background none -flatten tmp%d.png", layerNumber, layerNumber); system(str); + LWDEBUGF(4, "%s", str); } /** @@ -242,12 +229,30 @@ addDropShadow(int layerNumber) { */ static void addHighlight(int layerNumber) { - char str[129]; + // TODO: change to properly sized string + char str[512]; sprintf( str, - "convert tmp%d.png -fx A +matte -blur 1x1 -shade 120x45 -normalize tmp%d.png -compose Overlay -composite tmp%d.png -matte -compose Dst_In -composite tmp%d.png", - layerNumber, layerNumber, layerNumber, layerNumber); + "convert tmp%d.png \\( +clone -channel A -separate +channel -negate -background black -virtual-pixel background -blur 0x3 -shade 120x55 -contrast-stretch 0%% +sigmoidal-contrast 7x50%% -fill grey50 -colorize 10%% +clone +swap -compose overlay -composite \\) -compose In -composite tmp%d.png", + layerNumber, layerNumber); + system(str); + LWDEBUGF(4, "%s", str); +} + +/** + * Invokes a system call to ImageMagick's "convert" command that reduces + * the overall filesize + * + * @param filename the current working image. + */ +static void +optimizeImage(char* filename) { + char *str; + str = malloc( (18 + (2*strlen(filename)) + 1) * sizeof(char) ); + sprintf(str, "convert %s -depth 8 %s", filename, filename); system(str); + LWDEBUGF(4, "%s", str); + free(str); } /** @@ -258,12 +263,40 @@ flattenLayers(char* filename) { char *str; str = malloc( (48 + strlen(filename) + 1) * sizeof(char) ); sprintf(str, "convert tmp[0-9].png -background none -flatten %s", filename); + + LWDEBUGF(4, "%s", str); system(str); - system("rm -f tmp[0-9].png"); + // TODO: only remove the tmp files if they exist. + remove("tmp0.png"); + remove("tmp1.png"); + remove("tmp2.png"); + remove("tmp3.png"); + remove("tmp4.png"); + remove("tmp5.png"); free(str); } +// TODO: comments +int +getStyleName(char **styleName, char* line) { + char *ptr = strrchr(line, ';'); + if (ptr == NULL) { + *styleName = malloc( 8 ); + strncpy(*styleName, "Default", 7); + (*styleName)[7] = '\0'; + return 1; + } + else { + *styleName = malloc( ptr - line + 1); + strncpy(*styleName, line, ptr - line); + (*styleName)[ptr - line] = '\0'; + LWDEBUGF( 4, "%s", *styleName ); + return 0; + } +} + + /** * Main Application. Currently, drawing styles are hardcoded in this method. * Future work may entail reading the styles from a .properties file. @@ -275,35 +308,12 @@ int main( int argc, const char* argv[] ) { char *filename; int layerCount; int styleNumber; - LAYERSTYLE styles[3]; - - styles[0].pointSize = 6; - styles[0].pointColor = "Blue"; - styles[0].lineWidth = 7; - styles[0].lineColor = "Blue"; - styles[0].polygonFillColor = "Blue"; - styles[0].polygonStrokeColor = "Blue"; - styles[0].polygonStrokeWidth = 1; - - styles[1].pointSize = 6; - styles[1].pointColor = "Green"; - styles[1].lineWidth = 7; - styles[1].lineColor = "Green"; - styles[1].polygonFillColor = "Green"; - styles[1].polygonStrokeColor = "Green"; - styles[1].polygonStrokeWidth = 1; - - styles[2].pointSize = 6; - styles[2].pointColor = "Red"; - styles[2].lineWidth = 7; - styles[2].lineColor = "Red"; - styles[2].polygonFillColor = "Red"; - styles[2].polygonStrokeColor = "Red"; - styles[2].polygonStrokeWidth = 1; + LAYERSTYLE *styles; + getStyles(&styles); if ( argc != 2 ) { - printf("You must specifiy a wkt filename to convert.\n"); + lwerror("You must specifiy a wkt filename to convert.\n"); return -1; } @@ -312,27 +322,36 @@ int main( int argc, const char* argv[] ) { return -1; } - filename = malloc( (strlen(argv[1])+8) * sizeof(char) ); - strcpy( filename, "../images/" ); + filename = malloc( strlen(argv[1])+11 ); + strncpy( filename, "../images/", 10 ); strncat( filename, argv[1], strlen(argv[1])-3 ); - strcat( filename, "png" ); + strncat( filename, "png", 3 ); printf( "generating %s\n", filename ); layerCount = 0; - while ( fgets ( line, sizeof line, pfile ) != NULL ) { + while ( fgets ( line, sizeof line, pfile ) != NULL && !isspace(*line) ) { - char output [2048]; + char output[2048]; char *ptr = output; + char *styleName; + int useDefaultStyle; + ptr += sprintf( ptr, "convert -size %s xc:none ", imageSize ); - - lwgeom = lwgeom_from_ewkt( line, PARSER_CHECK_NONE ); + + useDefaultStyle = getStyleName(&styleName, line); + LWDEBUGF( 4, "%s", styleName ); + + if (useDefaultStyle) { + printf(" Warning: using Default style for layer %d\n", layerCount); + lwgeom = lwgeom_from_ewkt( line, PARSER_CHECK_NONE ); + } + else + lwgeom = lwgeom_from_ewkt( line+strlen(styleName)+1, PARSER_CHECK_NONE ); LWDEBUGF( 4, "geom = %s", lwgeom_to_ewkt((LWGEOM*)lwgeom,0) ); - styleNumber = layerCount % 3; - LWDEBUGF( 4, "using style %d", styleNumber ); - ptr += drawGeometry( ptr, lwgeom, styles[styleNumber] ); - LWDEBUGF( 4, "%s", "after drawGeometry" ); + styleNumber = layerCount % length(styles); + ptr += drawGeometry( ptr, lwgeom, getStyle(styles, styleName) ); ptr += sprintf( ptr, "-flip tmp%d.png", layerCount ); @@ -341,15 +360,17 @@ int main( int argc, const char* argv[] ) { LWDEBUGF( 4, "%s", output ); system(output); - addHighlight( layerCount ); - addDropShadow( layerCount ); + addHighlight( layerCount ); + addDropShadow( layerCount ); layerCount++; + free(styleName); } - LWDEBUGF(4, "%s", filename); flattenLayers(filename); + optimizeImage(filename); fclose(pfile); free(filename); + freeStyles(&styles); return 0; } diff --git a/doc/html/image_src/st_centroid01.wkt b/doc/html/image_src/st_centroid01.wkt index 416decee4..f95562f4d 100644 --- a/doc/html/image_src/st_centroid01.wkt +++ b/doc/html/image_src/st_centroid01.wkt @@ -1,2 +1,3 @@ -MULTIPOINT ( 8 24, 10 92, 12 154, 17 68, 28 10, 29 52, 29 84, 55 50, 56 24, 131 14, 160 180, 189 180 ) -POINT(60.3333333333333 77.6666666666667) \ No newline at end of file +Style1;MULTIPOINT ( 8 24, 10 92, 12 154, 17 68, 28 10, 29 52, 29 84, 55 50, 56 24, 131 14, 160 180, 189 180 ) +Style2;POINT(60.3333333333333 77.6666666666667) + diff --git a/doc/html/image_src/st_centroid02.wkt b/doc/html/image_src/st_centroid02.wkt index 9833dccdf..12b2025b1 100644 --- a/doc/html/image_src/st_centroid02.wkt +++ b/doc/html/image_src/st_centroid02.wkt @@ -1,2 +1,3 @@ -LINESTRING ( 190 160, 10 190, 40 90, 20 70, 10 10, 30 40, 30 10, 110 40, 70 10, 110 10, 140 40, 140 10, 160 30, 180 10 ) -POINT(76.1907245453253 79.8755933886095) \ No newline at end of file +Style1;LINESTRING ( 190 160, 10 190, 40 90, 20 70, 10 10, 30 40, 30 10, 110 40, 70 10, 110 10, 140 40, 140 10, 160 30, 180 10 ) +Style2;POINT(76.1907245453253 79.8755933886095) + diff --git a/doc/html/image_src/st_centroid03.wkt b/doc/html/image_src/st_centroid03.wkt index 59b2326c3..44050206a 100644 --- a/doc/html/image_src/st_centroid03.wkt +++ b/doc/html/image_src/st_centroid03.wkt @@ -1,2 +1,3 @@ -POLYGON (( 190 190, 10 190, 10 10, 190 10, 190 20, 160 30, 60 30, 60 130, 190 140, 190 190 )) -POINT(80.2508960573477 113.405017921147) \ No newline at end of file +Style1;POLYGON (( 190 190, 10 190, 10 10, 190 10, 190 20, 160 30, 60 30, 60 130, 190 140, 190 190 )) +Style2;POINT(80.2508960573477 113.405017921147) + diff --git a/doc/html/image_src/st_centroid04.wkt b/doc/html/image_src/st_centroid04.wkt index f74d61b81..54e95e3d8 100644 --- a/doc/html/image_src/st_centroid04.wkt +++ b/doc/html/image_src/st_centroid04.wkt @@ -1,2 +1,3 @@ -GEOMETRYCOLLECTION ( POLYGON (( 190 170, 180 100, 80 140, 80 160, 130 160, 110 180, 110 190, 180 180, 190 170 )), LINESTRING ( 80 120, 120 20, 140 70, 150 30, 180 50, 190 10 ), MULTIPOINT ( 19 150, 22 49, 30 13, 32 101, 45 35, 67 88, 75 16 )) -POINT(143.361344537815 148.263305322129) \ No newline at end of file +Style1;GEOMETRYCOLLECTION ( POLYGON (( 190 170, 180 100, 80 140, 80 160, 130 160, 110 180, 110 190, 180 180, 190 170 )), LINESTRING ( 80 120, 120 20, 140 70, 150 30, 180 50, 190 10 ), MULTIPOINT ( 19 150, 22 49, 30 13, 32 101, 45 35, 67 88, 75 16 )) +Style2;POINT(143.361344537815 148.263305322129) + diff --git a/doc/html/image_src/st_crosses01.wkt b/doc/html/image_src/st_crosses01.wkt index 4fdc5b8fd..b97bbe230 100644 --- a/doc/html/image_src/st_crosses01.wkt +++ b/doc/html/image_src/st_crosses01.wkt @@ -1,2 +1,3 @@ -LINESTRING ( 10 190, 60 80, 130 120, 190 10 ) -MULTIPOINT ( 80 170, 120 13, 130 119, 181 142 ) \ No newline at end of file +Style1;LINESTRING ( 10 190, 60 80, 130 120, 190 10 ) +Style2;MULTIPOINT ( 80 170, 120 13, 130 119, 181 142 ) + diff --git a/doc/html/image_src/st_crosses02.wkt b/doc/html/image_src/st_crosses02.wkt index 8f0c81be9..eeaec9127 100644 --- a/doc/html/image_src/st_crosses02.wkt +++ b/doc/html/image_src/st_crosses02.wkt @@ -1,2 +1,3 @@ -POLYGON (( 10 190, 20 10, 90 20, 110 70, 80 130, 10 190 )) -MULTIPOINT ( 56 60, 94 172, 128 125, 145 44, 172 173 ) \ No newline at end of file +Style1;POLYGON (( 30 190, 10 100, 10 10, 90 20, 110 70, 80 130, 30 190 )) +Style2;MULTIPOINT ( 56 60, 120 13, 130 119, 181 142 ) + diff --git a/doc/html/image_src/st_crosses03.wkt b/doc/html/image_src/st_crosses03.wkt index 6799a5d7d..330139851 100644 --- a/doc/html/image_src/st_crosses03.wkt +++ b/doc/html/image_src/st_crosses03.wkt @@ -1,2 +1,3 @@ -POLYGON (( 10 190, 20 10, 90 20, 110 70, 80 130, 10 190 )) -LINESTRING ( 30 40, 70 50, 120 150, 190 190 ) \ No newline at end of file +Style1;POLYGON (( 30 190, 10 100, 10 10, 90 20, 110 70, 80 130, 30 190 )) +Style2;LINESTRING ( 30 40, 70 50, 120 150, 190 190 ) + diff --git a/doc/html/image_src/st_crosses04.wkt b/doc/html/image_src/st_crosses04.wkt index 221a798f8..95953310b 100644 --- a/doc/html/image_src/st_crosses04.wkt +++ b/doc/html/image_src/st_crosses04.wkt @@ -1,2 +1,3 @@ -LINESTRING ( 10 190, 60 110, 110 120, 190 10 ) -LINESTRING ( 10 10, 70 30, 110 120, 190 190 ) +Style1;LINESTRING ( 10 190, 60 80, 130 120, 190 10 ) +Style2;LINESTRING ( 10 10, 70 30, 110 120, 190 190 ) + diff --git a/doc/html/image_src/st_issimple01.wkt b/doc/html/image_src/st_issimple01.wkt index 4af1d5a19..a1006195b 100644 --- a/doc/html/image_src/st_issimple01.wkt +++ b/doc/html/image_src/st_issimple01.wkt @@ -1 +1 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 10 190, 140 130, 70 80, 190 10 ), POINT(10 190), POINT(190 10) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 10 190, 140 130, 70 80, 190 10 ), POINT(10 190), POINT(190 10) ) diff --git a/doc/html/image_src/st_issimple02.wkt b/doc/html/image_src/st_issimple02.wkt index fb68f5966..72b711772 100644 --- a/doc/html/image_src/st_issimple02.wkt +++ b/doc/html/image_src/st_issimple02.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 10 190, 130 40, 170 160, 10 10 ), POINT(10 190), POINT(10 10) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 10 190, 130 40, 170 160, 10 10 ), POINT(10 190), POINT(10 10) ) + diff --git a/doc/html/image_src/st_issimple03.wkt b/doc/html/image_src/st_issimple03.wkt index cdcf5dcc2..5931363f7 100644 --- a/doc/html/image_src/st_issimple03.wkt +++ b/doc/html/image_src/st_issimple03.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 90 190, 120 190, 130 140, 190 50, 70 10, 10 70, 10 150, 90 190 ), POINT(90 190) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 90 190, 120 190, 130 140, 190 50, 70 10, 10 70, 10 150, 90 190 ), POINT(90 190) ) + diff --git a/doc/html/image_src/st_issimple04.wkt b/doc/html/image_src/st_issimple04.wkt index 31221f067..937d04dfe 100644 --- a/doc/html/image_src/st_issimple04.wkt +++ b/doc/html/image_src/st_issimple04.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 90 190, 120 190, 50 60, 130 10, 190 50, 160 90, 10 150, 90 190 ), POINT(90 190) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 90 190, 120 190, 50 60, 130 10, 190 50, 160 90, 10 150, 90 190 ), POINT(90 190) ) + diff --git a/doc/html/image_src/st_issimple05.wkt b/doc/html/image_src/st_issimple05.wkt index 296f3e665..aa870d0cc 100644 --- a/doc/html/image_src/st_issimple05.wkt +++ b/doc/html/image_src/st_issimple05.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING ( 100 190, 180 150, 160 70 ), MULTIPOINT ( 30 190, 170 10, 100 190, 160 70 ) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING ( 100 190, 180 150, 160 70 ), MULTIPOINT ( 30 190, 170 10, 100 190, 160 70 ) ) + diff --git a/doc/html/image_src/st_issimple06.wkt b/doc/html/image_src/st_issimple06.wkt index 31f3a8e6d..6ae475b0b 100644 --- a/doc/html/image_src/st_issimple06.wkt +++ b/doc/html/image_src/st_issimple06.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING ( 30 190, 180 150, 160 70 ), MULTIPOINT( 170 10, 30 190, 170 10 ) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING ( 30 190, 180 150, 160 70 ), MULTIPOINT( 170 10, 30 190, 170 10, 160 70 ) ) + diff --git a/doc/html/image_src/st_issimple07.wkt b/doc/html/image_src/st_issimple07.wkt index 684e6fbe8..70d751c63 100644 --- a/doc/html/image_src/st_issimple07.wkt +++ b/doc/html/image_src/st_issimple07.wkt @@ -1 +1,2 @@ -GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING (100 190, 180 150, 80 10), MULTIPOINT( 30 190, 170 10, 100 190, 80 10 ) ) +Style1;GEOMETRYCOLLECTION ( LINESTRING ( 30 190, 60 60, 170 10 ), LINESTRING (100 190, 180 150, 80 10), MULTIPOINT( 30 190, 170 10, 100 190, 80 10 ) ) + diff --git a/doc/html/image_src/st_isvalid01.wkt b/doc/html/image_src/st_isvalid01.wkt index 99d45f12c..fe8eba625 100644 --- a/doc/html/image_src/st_isvalid01.wkt +++ b/doc/html/image_src/st_isvalid01.wkt @@ -1 +1,2 @@ -POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (50 100, 70 80, 110 100, 110 140, 50 100)) +Style1;POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (50 100, 70 80, 110 100, 110 140, 50 100)) + diff --git a/doc/html/image_src/st_isvalid02.wkt b/doc/html/image_src/st_isvalid02.wkt index ab279131d..b77609a6a 100644 --- a/doc/html/image_src/st_isvalid02.wkt +++ b/doc/html/image_src/st_isvalid02.wkt @@ -1 +1,2 @@ -POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (190 60, 140 40, 110 60, 120 90, 190 60)) +Style1;POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (190 60, 140 40, 110 60, 120 90, 190 60)) + diff --git a/doc/html/image_src/st_isvalid03.wkt b/doc/html/image_src/st_isvalid03.wkt index 451a350be..07f9393db 100644 --- a/doc/html/image_src/st_isvalid03.wkt +++ b/doc/html/image_src/st_isvalid03.wkt @@ -1 +1,2 @@ -POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (130 170, 10 140, 50 120, 110 110, 130 170)) +Style1;POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (130 170, 10 140, 50 120, 110 110, 130 170)) + diff --git a/doc/html/image_src/st_isvalid04.wkt b/doc/html/image_src/st_isvalid04.wkt index 2cfe45b4e..fb162135f 100644 --- a/doc/html/image_src/st_isvalid04.wkt +++ b/doc/html/image_src/st_isvalid04.wkt @@ -1 +1,2 @@ -POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (90 189, 10 139, 80 110, 110 130, 90 189)) +Style1;POLYGON ((10 140, 90 190, 130 170, 190 60, 160 10, 50 20, 10 140), (90 189, 10 139, 80 110, 110 130, 90 189)) + diff --git a/doc/html/image_src/st_isvalid05.wkt b/doc/html/image_src/st_isvalid05.wkt index 9e6bf3152..1c99d0808 100644 --- a/doc/html/image_src/st_isvalid05.wkt +++ b/doc/html/image_src/st_isvalid05.wkt @@ -1 +1,2 @@ -POLYGON (( 10 100, 60 140, 60 190, 62 190, 62 157, 130 170, 190 60, 160 10, 50 20, 10 100 )) +Style1;POLYGON (( 10 100, 60 140, 60 190, 61 190, 61 157, 130 170, 190 60, 160 10, 50 20, 10 100 )) + diff --git a/doc/html/image_src/st_isvalid06.wkt b/doc/html/image_src/st_isvalid06.wkt new file mode 100644 index 000000000..4a6b4a645 --- /dev/null +++ b/doc/html/image_src/st_isvalid06.wkt @@ -0,0 +1,2 @@ +Style1-thinline;GEOMETRYCOLLECTION (POLYGON (( 10 40, 10 100, 130 130, 190 80, 140 20, 50 10, 10 40 )), LINESTRING ( 81 143, 103 143, 112 162, 107 175, 89 183, 71 169, 81 143 )) + diff --git a/doc/html/image_src/st_isvalid07.wkt b/doc/html/image_src/st_isvalid07.wkt new file mode 100644 index 000000000..cbcb298d2 --- /dev/null +++ b/doc/html/image_src/st_isvalid07.wkt @@ -0,0 +1,2 @@ +Style1;GEOMETRYCOLLECTION (POLYGON (( 10 40, 29 118, 120 118, 180 88, 140 30, 70 10, 10 40 )), POLYGON (( 50 170, 100 190, 160 180, 180 140, 180 90, 120 120, 30 120, 50 170 ))) + diff --git a/doc/html/image_src/st_isvalid08.wkt b/doc/html/image_src/st_isvalid08.wkt new file mode 100644 index 000000000..30306da8c --- /dev/null +++ b/doc/html/image_src/st_isvalid08.wkt @@ -0,0 +1,2 @@ +Style1-thinline;GEOMETRYCOLLECTION (POLYGON (( 10 40, 42 93, 113 105, 180 86, 140 30, 70 10, 10 40 )), POLYGON (( 50 170, 100 190, 138 182, 149 156, 146 137, 113 129, 58 140, 50 170 )), LINESTRING ( 113 105, 113 129 )) + diff --git a/doc/html/image_src/st_touches01.wkt b/doc/html/image_src/st_touches01.wkt new file mode 100644 index 000000000..382f31e78 --- /dev/null +++ b/doc/html/image_src/st_touches01.wkt @@ -0,0 +1,2 @@ +Style1;POLYGON (( 10 190, 10 70, 80 70, 80 130, 50 160, 120 160, 120 190, 10 190 )) +Style2;POLYGON (( 81 110, 140 140, 190 110, 180 40, 140 10, 81 50, 81 70, 81 110 )) diff --git a/doc/html/image_src/st_touches02.wkt b/doc/html/image_src/st_touches02.wkt new file mode 100644 index 000000000..0b209a800 --- /dev/null +++ b/doc/html/image_src/st_touches02.wkt @@ -0,0 +1,2 @@ +Style1;POLYGON (( 10 190, 10 70, 80 70, 80 130, 50 160, 120 160, 120 190, 10 190 )) +Style2;POLYGON (( 140 140, 190 110, 180 40, 140 10, 80 70, 140 140 )) diff --git a/doc/html/image_src/st_touches03.wkt b/doc/html/image_src/st_touches03.wkt new file mode 100644 index 000000000..f568fcfb6 --- /dev/null +++ b/doc/html/image_src/st_touches03.wkt @@ -0,0 +1,2 @@ +Style1;POLYGON ((80 10, 50 40, 50 90, 80 130, 140 120, 160 70, 140 30, 80 10)) +Style2;LINESTRING (30 190, 180 150, 160 70) \ No newline at end of file diff --git a/doc/html/image_src/st_touches04.wkt b/doc/html/image_src/st_touches04.wkt new file mode 100644 index 000000000..02df54d8f --- /dev/null +++ b/doc/html/image_src/st_touches04.wkt @@ -0,0 +1,2 @@ +Style1;LINESTRING ( 10 10, 60 140, 140 190 ) +Style2;LINESTRING ( 140 190, 190 10 ) diff --git a/doc/html/image_src/st_touches05.wkt b/doc/html/image_src/st_touches05.wkt new file mode 100644 index 000000000..c52982d57 --- /dev/null +++ b/doc/html/image_src/st_touches05.wkt @@ -0,0 +1,2 @@ +Style1;LINESTRING ( 10 10, 60 140, 140 190 ) +Style2;LINESTRING ( 60 140, 190 10 ) diff --git a/doc/html/image_src/st_touches06.wkt b/doc/html/image_src/st_touches06.wkt new file mode 100644 index 000000000..b87174948 --- /dev/null +++ b/doc/html/image_src/st_touches06.wkt @@ -0,0 +1,2 @@ +Style1;POLYGON (( 30 30, 10 110, 40 190, 120 170, 180 180, 170 100, 130 10, 30 30 )) +Style2;POINT ( 170 100 ) diff --git a/doc/html/image_src/styles.c b/doc/html/image_src/styles.c new file mode 100644 index 000000000..84a9095c3 --- /dev/null +++ b/doc/html/image_src/styles.c @@ -0,0 +1,175 @@ +/********************************************************************** + * $Id: generator.c 3967 2009-05-04 16:48:11Z kneufeld $ + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * Copyright 2008 Kevin Neufeld + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + * TODO: fix segfault bug caused by a referenced style that doesn't exist in + * the .conf file + **********************************************************************/ + +#include +#include +#include +#include + +#include "styles.h" + + +void +getStyles( LAYERSTYLE **headRef ) { + char line [128]; + FILE* pFile; + char *getResults; + + *headRef = NULL; + + if ((pFile = fopen("styles.conf", "r")) == NULL) { + perror ( "styles.properties: No such file or directory" ); + return; + } + + getResults = fgets ( line, sizeof line, pFile ); + while ( getResults != NULL ) { + + // process defined styles + while ( (getResults != NULL) && strncmp(line, "[Style]", 7) == 0) { + char *styleName = "DefaultStyle"; + int pointSize = 5; + char *pointColor = "Grey"; + int lineWidth = 5; + char *lineColor = "Grey"; + char *polygonFillColor = "Grey"; + char *polygonStrokeColor = "Grey"; + int polygonStrokeWidth = 0; + + getResults = fgets ( line, sizeof line, pFile ); + while ( (getResults != NULL) && (strncmp(line, "[Style]", 7) != 0) ) { + char *ptr; + + // loop over all lines until [Style] is reached again + if ( (*line != '#') && (ptr = strchr(line, '=')) ) { + ptr = trim((++ptr)); + + if (strncmp(line, "styleName", 9) == 0) + styleName = ptr; + else if (strncmp(line, "pointSize", 9) == 0) { + pointSize = atoi(ptr); + free(ptr); + } + else if (strncmp(line, "pointColor", 10) == 0) + pointColor = ptr; + else if (strncmp(line, "lineWidth", 9) == 0) { + lineWidth = atoi(ptr); + free(ptr); + } + else if (strncmp(line, "lineColor", 9) == 0) + lineColor = ptr; + else if (strncmp(line, "polygonFillColor", 16) == 0) + polygonFillColor = ptr; + else if (strncmp(line, "polygonStrokeColor", 18) == 0) + polygonStrokeColor = ptr; + else if (strncmp(line, "polygonStrokeWidth", 18) == 0) { + polygonStrokeWidth = atoi(ptr); + free(ptr); + } + + } + getResults = fgets ( line, sizeof line, pFile ); + } + + addStyle(headRef, styleName, pointSize, pointColor, lineWidth, lineColor, polygonFillColor, polygonStrokeColor, polygonStrokeWidth); + } + + getResults = fgets ( line, sizeof line, pFile ); + } + + fclose( pFile ); +} + + +void +freeStyles( LAYERSTYLE **headRef ) { + LAYERSTYLE *curr = *headRef; + LAYERSTYLE *next; + + while (curr != NULL) { + next = curr->next; + free(curr->styleName); + free(curr->pointColor); + free(curr->lineColor); + free(curr->polygonFillColor); + free(curr->polygonStrokeColor); + free(curr); + curr = next; + } + + *headRef = NULL; +} + + +void +addStyle( + LAYERSTYLE **headRef, + char* styleName, + int pointSize, char* pointColor, + int lineWidth, char* lineColor, + char* polygonFillColor, char* polygonStrokeColor, int polygonStrokeWidth) { + LAYERSTYLE *style = malloc( sizeof(LAYERSTYLE) ); + + style->styleName = styleName; + style->pointSize = pointSize; + style->pointColor = pointColor; + style->lineWidth = lineWidth; + style->lineColor = lineColor; + style->polygonFillColor = polygonFillColor; + style->polygonStrokeColor = polygonStrokeColor; + style->polygonStrokeWidth = polygonStrokeWidth; + style->next = *headRef; + *headRef = style; +} + + +int +length( LAYERSTYLE *head ) { + int count = 0; + LAYERSTYLE *curr = head; + + while (curr != NULL) { + count++; + curr = curr->next; + } + + return (count); +} + + +LAYERSTYLE* +getStyle( LAYERSTYLE *headRef, char* styleName ) { + LAYERSTYLE *curr = headRef; + + while (curr != NULL && (strcmp(curr->styleName, styleName) != 0)) + curr = curr->next; + + return (curr); +} + + +char* +trim(char* str) { + int len; + char* result; + char* start = str; + char* end = strchr(start, '\0'); + while (start +#include +#include + +typedef struct layerStyle LAYERSTYLE; + +struct layerStyle { + char *styleName; // A unique name + + int pointSize; + char *pointColor; + + int lineWidth; + char *lineColor; + + char *polygonFillColor; + char *polygonStrokeColor; + int polygonStrokeWidth; + + LAYERSTYLE *next; +}; + +void getStyles( LAYERSTYLE **headRef ); +void freeStyles( LAYERSTYLE **headRef ); +void addStyle( LAYERSTYLE **headRef, char* styleName, int pointSize, char* pointColor, int lineWidth, char* lineColor, char* polygonFillColor, char* polygonStrokeColor, int polygonStrokeWidth ); + +int length( LAYERSTYLE *headRef ); +LAYERSTYLE* getStyle( LAYERSTYLE *headRef, char* styleName ); +char* trim(char* str); diff --git a/doc/reference.xml b/doc/reference.xml index fc1a695b0..c8e73a87d 100644 --- a/doc/reference.xml +++ b/doc/reference.xml @@ -9433,7 +9433,7 @@ FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, - + MULTIPOINT / LINESTRING @@ -9443,7 +9443,7 @@ FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, - + MULTIPOINT / POLYGON @@ -9455,7 +9455,7 @@ FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, - + LINESTRING / POLYGON @@ -9465,7 +9465,7 @@ FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, - + LINESTRING / LINESTRING