Permalink
Browse files

implementation of geomtransform at the layer level

  • Loading branch information...
1 parent c5a2921 commit 5c2bd2e0f5958ed77e12af87df6927fb30a167ee Alan Boudreault committed Feb 4, 2013
Showing with 87 additions and 45 deletions.
  1. +6 −1 mapdraw.c
  2. +13 −9 mapfile.c
  3. +59 −24 mapgeomtransform.c
  4. +3 −0 maplayer.c
  5. +4 −9 mapserver.h
  6. +2 −2 maputil.c
View
@@ -1044,7 +1044,12 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
if (layer->type == MS_LAYER_LINE && msLayerGetProcessingKey(layer, "POLYLINE_NO_CLIP")) {
drawmode |= MS_DRAWMODE_UNCLIPPEDLINES;
}
-
+
+ /* Apply GeomTransform */
+ if(layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE) {
+ msGeomTransformShape(&shape, &layer->_geomtransform);
+ }
+
if (cache) {
styleObj *pStyle = layer->class[shape.classindex]->styles[0];
colorObj tmp;
View
@@ -2705,7 +2705,7 @@ int loadStyle(styleObj *style)
int s;
if((s = getSymbol(2, MS_STRING, MS_EXPRESSION)) == -1) return(MS_FAILURE);
if(s == MS_STRING)
- msStyleSetGeomTransform(style, msyystring_buffer);
+ msSetGeomTransform(&style->_geomtransform, msyystring_buffer);
else {
/* handle expression case here for the moment */
msFree(style->_geomtransform.string);
@@ -4196,10 +4196,13 @@ int loadLayer(layerObj *layer, mapObj *map)
}
}
break;
- case(GEOMTRANSFORM): {
+ case(GEOMTRANSFORM): {
int s;
- if((s = getSymbol(1, MS_STRING)) == -1) return(MS_FAILURE);
- msLayerSetGeomTransform(layer, msyystring_buffer);
+ if((s = getSymbol(1, MS_EXPRESSION)) == -1) return(MS_FAILURE);
+ /* handle expression case here for the moment */
+ msFree(layer->_geomtransform.string);
+ layer->_geomtransform.string = msStrdup(msyystring_buffer);
+ layer->_geomtransform.type = MS_GEOMTRANSFORM_EXPRESSION;
}
break;
case(HEADER):
@@ -4498,11 +4501,12 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer)
writeString(stream, indent, "FILTERITEM", NULL, layer->filteritem);
writeString(stream, indent, "FOOTER", NULL, layer->footer);
writeString(stream, indent, "GROUP", NULL, layer->group);
- if(layer->_geomtransform.type != MS_GEOMTRANSFORM_NONE) {
- writeKeyword(stream, indent, "GEOMTRANSFORM", layer->_geomtransform.type, 1,
- MS_LAYER_GEOMTRANSFORM_SIMPLIFY, "\"simplify\""
- );
- }
+
+ if(layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION) {
+ writeIndent(stream, indent + 1);
+ fprintf(stream, "GEOMTRANSFORM (%s)\n", layer->_geomtransform.string);
+ }
+
writeString(stream, indent, "HEADER", NULL, layer->header);
/* join - see below */
writeKeyword(stream, indent, "LABELCACHE", layer->labelcache, 1, MS_OFF, "OFF");
View
@@ -32,29 +32,29 @@
extern int yyparse(parseObj *p);
-void msStyleSetGeomTransform(styleObj *s, char *transform)
+void msSetGeomTransform(expressionObj *g, char *transform)
{
- msFree(s->_geomtransform.string);
- s->_geomtransform.string = msStrdup(transform);
+ msFree(g->string);
+ g->string = msStrdup(transform);
if(!strncasecmp("start",transform,5)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_START;
+ g->type = MS_GEOMTRANSFORM_START;
} else if(!strncasecmp("end",transform,3)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_END;
+ g->type = MS_GEOMTRANSFORM_END;
} else if(!strncasecmp("vertices",transform,8)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_VERTICES;
+ g->type = MS_GEOMTRANSFORM_VERTICES;
} else if(!strncasecmp("bbox",transform,4)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_BBOX;
+ g->type = MS_GEOMTRANSFORM_BBOX;
} else if(!strncasecmp("labelpnt",transform,8)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOINT;
+ g->type = MS_GEOMTRANSFORM_LABELPOINT;
} else if(!strncasecmp("labelpoly",transform,9)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_LABELPOLY;
+ g->type = MS_GEOMTRANSFORM_LABELPOLY;
} else if(!strncasecmp("centroid",transform,8)) {
- s->_geomtransform.type = MS_GEOMTRANSFORM_CENTROID;
+ g->type = MS_GEOMTRANSFORM_CENTROID;
} else {
- s->_geomtransform.type = MS_GEOMTRANSFORM_NONE;
- msSetError(MS_MISCERR,"unknown transform expression","msStyleSetGeomTransform()");
- msFree(s->_geomtransform.string);
- s->_geomtransform.string = NULL;
+ g->type = MS_GEOMTRANSFORM_NONE;
+ msSetError(MS_MISCERR,"unknown transform expression","msSetGeomTransform()");
+ msFree(g->string);
+ g->string = NULL;
}
}
@@ -210,16 +210,51 @@ int msDrawTransformedShape(mapObj *map, symbolSetObj *symbolset, imageObj *image
return MS_SUCCESS;
}
-void msLayerSetGeomTransform(layerObj *layer, char *transform)
+/*
+ * RFCXX implementation:
+ * - transform directly the shapeobj
+ * - Only shape depression supported for layers
+ */
+int msGeomTransformShape(shapeObj *shape, expressionObj *e)
{
- msFree(layer->_geomtransform.string);
- layer->_geomtransform.string = msStrdup(transform);
- if(!strncasecmp("simplify",transform,8)) {
- layer->_geomtransform.type = MS_LAYER_GEOMTRANSFORM_SIMPLIFY;
- } else {
- layer->_geomtransform.type = MS_LAYER_GEOMTRANSFORM_NONE;
- msSetError(MS_MISCERR,"unknown transform expression","msLayerSetGeomTransform()");
- msFree(layer->_geomtransform.string);
- layer->_geomtransform.string = NULL;
+ int i;
+
+ switch(e->type) {
+ case MS_GEOMTRANSFORM_EXPRESSION: {
+ int status;
+ shapeObj *tmpshp;
+ parseObj p;
+
+ p.shape = shape; /* set a few parser globals (hence the lock) */
+ p.expr = e;
+ p.expr->curtoken = p.expr->tokens; /* reset */
+ p.type = MS_PARSE_TYPE_SHAPE;
+ //p.dblval = map->cellsize/MS_MAX(image->width, image->height);
+
+ status = yyparse(&p);
+ if (status != 0) {
+ msSetError(MS_PARSEERR, "Failed to process shape expression: %s", "msGeomTransformShape()", e->string);
+ return MS_FAILURE;
+ }
+
+ tmpshp = p.result.shpval;
+
+ for (i= 0; i < shape->numlines; i++)
+ free(shape->line[i].point);
+ shape->numlines = 0;
+ if (shape->line) free(shape->line);
+
+ for(i=0; i<tmpshp->numlines; i++)
+ msAddLine(shape, &(tmpshp->line[i])); /* copy each line */
+
+ msFreeShape(tmpshp);
+ msFree(tmpshp);
+ }
+ break;
+ default:
+ msSetError(MS_MISCERR, "unknown geomtransform", "msGeomTransformShape()");
+ return MS_FAILURE;
}
+
+ return MS_SUCCESS;
}
View
@@ -616,6 +616,9 @@ int msLayerWhichItems(layerObj *layer, int get_all, char *metadata)
if(layer->labelitem) nt++;
+ if(layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION)
+ msTokenizeExpression(&layer->_geomtransform, layer->items, &(layer->numitems));
+
/* class level counts */
for(i=0; i<layer->numclasses; i++) {
View
@@ -2656,20 +2656,15 @@ extern "C" {
MS_GEOMTRANSFORM_BUFFER,
MS_GEOMTRANSFORM_CONVEXHULL,
MS_GEOMTRANSFORM_LABELPOINT,
- MS_GEOMTRANSFORM_LABELPOLY,
- MS_GEOMTRANSFORM_SIMPLIFY
+ MS_GEOMTRANSFORM_LABELPOLY
};
- enum MS_LAYER_GEOMTRANSFORM_TYPE {
- MS_LAYER_GEOMTRANSFORM_NONE,
- MS_LAYER_GEOMTRANSFORM_SIMPLIFY,
- };
-
MS_DLL_EXPORT int msDrawTransformedShape(mapObj *map, symbolSetObj *symbolset, imageObj *image, shapeObj *shape, styleObj *style, double scalefactor);
- MS_DLL_EXPORT void msStyleSetGeomTransform(styleObj *style, char *transform);
+ MS_DLL_EXPORT void msSetGeomTransform(expressionObj *e, char *transform);
MS_DLL_EXPORT char *msStyleGetGeomTransform(styleObj *style);
- MS_DLL_EXPORT void msLayerSetGeomTransform(layerObj *layer, char *transform);
+ MS_DLL_EXPORT int msGeomTransformShape(shapeObj *shape, expressionObj *e);
+
/* ==================================================================== */
/* end of prototypes for functions in mapgeomtransform.c */
/* ==================================================================== */
View
@@ -2391,8 +2391,8 @@ int msMapSetLayerProjections(mapObj* map)
return(MS_SUCCESS);
}
-/* Generalize a shape based of the tolerance. The function modify the shape
- directly. Ref: http://trac.osgeo.org/gdal/ticket/966 */
+/* Generalize a shape based of the tolerance.
+ Ref: http://trac.osgeo.org/gdal/ticket/966 */
shapeObj* msGeneralize(shapeObj *shape, double tolerance)
{
shapeObj *newShape;

0 comments on commit 5c2bd2e

Please sign in to comment.