kiwi-postgis  Version 0.1.0.0
RasterToWorldCoordX Class Reference
Inheritance diagram for RasterToWorldCoordX:
Collaboration diagram for RasterToWorldCoordX:

Public Member Functions

String getURI ()
 
boolean isSupported (KiWiDialect dialect)
 Return true if this function has available native support for the given dialect. More...
 
String getNative (KiWiDialect dialect, String... args)
 Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect. More...
 
ValueType getReturnType ()
 Get the return type of the function. More...
 
ValueType getArgumentType (int arg)
 Get the argument type of the function for the arg'th argument (starting to count at 0). More...
 
int getMinArgs ()
 Return the minimum number of arguments this function requires. More...
 
int getMaxArgs ()
 Return the maximum number of arguments this function can take. More...
 
Double attribute (GridCoverage raster, Integer longitude, Integer latitude)
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Static Package Functions

 [static initializer]
 

Member Function Documentation

◆ [static initializer]()

[static initializer] ( )
staticpackage

◆ attribute()

Double attribute ( GridCoverage  raster,
Integer  longitude,
Integer  latitude 
)
inherited

References Coordinate.x.

22  {
23  try {
24  GridGeometry gg2D = raster.getGridGeometry();
25  MathTransform gridToCRS = gg2D.getGridToCRS(PixelInCell.CELL_CENTER);
26  DirectPosition realPos=new DirectPosition2D(latitude, longitude);
27  DirectPosition gridPos = new DirectPosition2D();
28  DirectPosition res=gridToCRS.transform(realPos, gridPos);
29  Coordinate coord=new Coordinate(res.getCoordinate()[0],res.getCoordinate()[1]);
30  return coord.x;
31  } catch (TransformException e) {
32  return (Double) null;
33  }
34  }

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited

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

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

◆ getArgumentType()

ValueType getArgumentType ( int  arg)

Get the argument type of the function for the arg'th argument (starting to count at 0).

This is needed for SQL type casting inside KiWi.

Parameters
arg
Returns

References ValueType.GEOMETRY.

91  {
92  return ValueType.GEOMETRY;
93  }

◆ getMaxArgs()

int getMaxArgs ( )

Return the maximum number of arguments this function can take.

Returns
111  {
112  return 3;
113  }

◆ getMinArgs()

int getMinArgs ( )

Return the minimum number of arguments this function requires.

Returns
101  {
102  return 3;
103  }

◆ getNative()

String getNative ( KiWiDialect  dialect,
String...  args 
)

Return a string representing how this GeoSPARQL function is translated into SQL ( Postgis Function ) in the given dialect.

Parameters
dialect
args
Returns

References FN_POSTGIS.st_rasterToWorldCoordX.

48  {
49  if (dialect instanceof PostgreSQLDialect) {
50  if (args.length == 1) {
51  String geom1 = args[0];
52  Integer longitude=Integer.valueOf(args[1]);
53  Integer latitude=Integer.valueOf(args[2]);
54  String SRID_default = "4326";
55  /*
56  * The following condition is required to read WKT inserted directly into args[0] and create a geometries with SRID
57  * POINT, MULTIPOINT, LINESTRING ... and MULTIPOLYGON conditions:
58  * example: geof:convexHull("POLYGON(( -7 43, -2 43, -2 38, -7 38, -7 43))"^^geo:wktLiteral)
59  * st_AsText condition: It is to use the geometry that is the result of another function geosparql.
60  * example: geof:convexHull(geof:buffer(?geom, 50, units:meter))
61  */
62  if (args[0].contains("POINT") || args[0].contains("MULTIPOINT") || args[0].contains("LINESTRING") || args[0].contains("MULTILINESTRING") || args[0].contains("POLYGON") || args[0].contains("MULTIPOLYGON") || args[0].contains("ST_AsText")) {
63  geom1 = String.format("ST_GeomFromText(%s,%s)", args[0], SRID_default);
64  }
65  return String.format("ST_RasterToWorldCoordX(%s,%s,%s)", geom1,longitude,latitude);
66  }
67  }
68  throw new UnsupportedOperationException(FN_POSTGIS.st_rasterToWorldCoordX.toString()+" function not supported by dialect " + dialect);
69  }

◆ getReturnType()

ValueType getReturnType ( )

Get the return type of the function.

This is needed for SQL type casting inside KiWi.

Returns

References ValueType.DOUBLE.

78  {
79  return ValueType.DOUBLE;
80  }

◆ getURI()

String getURI ( )

References FN_POSTGIS.st_rasterToWorldCoordX.

23  {
24  return FN_POSTGIS.st_rasterToWorldCoordX.stringValue();
25  }

◆ isSupported()

boolean isSupported ( KiWiDialect  dialect)

Return true if this function has available native support for the given dialect.

Parameters
dialect
Returns
35  {
36  return dialect instanceof PostgreSQLDialect;
37  }