rdf4j-postgis  Version 0.1.0.0
WorldToRasterCoord Class Reference
Inheritance diagram for WorldToRasterCoord:
Collaboration diagram for WorldToRasterCoord:

Public Member Functions

String getURI ()
 
Geometry attribute (GridCoverage raster, Integer longitude, Integer latitude)
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Member Function Documentation

◆ attribute()

Geometry attribute ( GridCoverage  raster,
Integer  longitude,
Integer  latitude 
)

Reimplemented from RasterAttributeIntIntGeomFunction.

24  {
25  try {
26 
27  GridGeometry gg2D = raster.getGridGeometry();
28  MathTransform gridToCRS = gg2D.getGridToCRS(PixelInCell.CELL_CENTER);
29  MathTransform crsToGrid = gridToCRS.inverse();
30  DirectPosition realPos=new DirectPosition2D(latitude, longitude);
31  DirectPosition gridPos = new DirectPosition2D();
32  DirectPosition res=crsToGrid.transform(realPos, gridPos);
33  Coordinate coord=new Coordinate(res.getCoordinate()[0],res.getCoordinate()[1]);
34  GeometryFactory fac=new GeometryFactory();
35  return fac.createPoint(coord);
36  } catch (TransformException e) {
37  return null;
38  }
39  }

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
19  {
20  if (args.length != 3) {
21  throw new ValueExprEvaluationException(getURI() + " requires exactly 1 arguments, got " + args.length);
22  }
23  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
24  if(l instanceof RasterLiteral) {
25  GridCoverage geom=((RasterLiteral)l).read(args[0].stringValue());
26  Integer longitude = Integer.valueOf(args[1].stringValue());
27  Integer latitude = Integer.valueOf(args[2].stringValue());
28  Geometry result = attribute(geom,longitude,latitude);
29  return valueFactory.createLiteral(((VectorLiteral) l).unparse(result),((Literal)args[0]).getDatatype());
30  }
31  return null;
32  }
abstract Geometry attribute(GridCoverage geom, Integer longitude, Integer latitude)

References RasterAttributeIntIntGeomFunction.attribute(), and LiteralRegistry.getLiteral().

Referenced by RasterToWorldCoordTest.testRasterToWorldCoord(), and WorldToRasterCoordTest.testWorldToRasterCoord().

◆ getURI()

String getURI ( )
19  {
20  return POSTGIS.st_worldToRasterCoord.stringValue();
21  }

References POSTGIS.st_worldToRasterCoord.