Hi
I am attempting to create a simple filter function that would allow me to
place a graphic, using a PointSymbolizer, at an offset to the point
geometry.  The function would expect two parameters, an x-offset and a
y-offset (I know this is very simplistic, I will need to take into account
the current map scale later).  I would use the function something like this:

  pointSymbolizer.setGeometry(ff.function("GeometryOffset",
ff.literal(0.0001), ff.literal(0.0001)));

I created a function by extending FunctionExpressionImpl and registered it,
the evaluate method is shown below:

  @Override
  public Object evaluate(Object feature)
  {
    if (!(feature instanceof SimpleFeature))
    {
      return null;
    }
    Expression xOffset = (Expression)getParameters().get(0);
    Expression yOffset = (Expression)getParameters().get(1);

    double first = ((Number)xOffset.evaluate(feature)).doubleValue();
    double second = ((Number)yOffset.evaluate(feature)).doubleValue();

    Object originalPoint = ((SimpleFeature)feature).getDefaultGeometry();
    if (!(originalPoint instanceof Geometry))
    {
      return null;
    }

    Coordinate originalCoordinate =
((Geometry)originalPoint).getCoordinate();
    Coordinate newCoordinate = new Coordinate(originalCoordinate.x + first,
originalCoordinate.y + second);

    GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory(null);
    Point newPoint = geometryFactory.createPoint(newCoordinate);

    return newPoint;
  }

This is not working, the graphic is not displayed at all.  Any hints would
be very appreciated.  I noticed in the javadocs for the
setGeometry/getGeometry methods that 'it is advised that the Expression
implements the SpatialTransformationFunction interface', I have not been
able to locate this interface.

Thanks,
Richard

-- 
View this message in context: 
http://n2.nabble.com/Geometry-offset-function-tp4837712p4837712.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to