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

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...
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Protected Member Functions

Geometry relation (Geometry geom, String value)
 

Static Package Functions

 [static initializer]
 

Member Function Documentation

◆ [static initializer]()

[static initializer] ( )
staticpackage

◆ evaluate()

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

References LiteralRegistry.getLiteral(), and GeometricModifierStringFunction.relation().

16  {
17  if (args.length != 2) {
18  throw new ValueExprEvaluationException(getURI() + " requires exactly 2 arguments, got " + args.length);
19  }
20 
21  String value=args[1].stringValue();
22  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
23  if(l instanceof VectorLiteral) {
24  Geometry geom=((VectorLiteral)l).read(args[0].stringValue());
25  Geometry result = relation(geom,value);
26  return valueFactory.createLiteral(((VectorLiteral) l).unparse(result),((Literal)args[0]).getDatatype());
27  }
28  throw new ValueExprEvaluationException("Arguments given are not geometry literals");
29  }

◆ 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.

87  {
88  return ValueType.GEOMETRY;
89  }

◆ getMaxArgs()

int getMaxArgs ( )

Return the maximum number of arguments this function can take.

Returns
107  {
108  return 1;
109  }

◆ getMinArgs()

int getMinArgs ( )

Return the minimum number of arguments this function requires.

Returns
97  {
98  return 1;
99  }

◆ 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_swapOrdinates.

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

◆ getReturnType()

ValueType getReturnType ( )

Get the return type of the function.

This is needed for SQL type casting inside KiWi.

Returns

References ValueType.GEOMETRY.

74  {
75  return ValueType.GEOMETRY;
76  }

◆ getURI()

String getURI ( )

References FN_POSTGIS.st_swapOrdinates.

20  {
21  return FN_POSTGIS.st_swapOrdinates.stringValue();
22  }

◆ isSupported()

boolean isSupported ( KiWiDialect  dialect)

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

Parameters
dialect
Returns
32  {
33  return dialect instanceof PostgreSQLDialect;
34  }

◆ relation()

Geometry relation ( Geometry  geom,
String  value 
)
protectedinherited

References LiteralUtils.createGeometry().

23  {
24  String ords = value;
25  List<Coordinate> newcoords=new ArrayList<Coordinate>();
26  if(ords.equalsIgnoreCase("xy")) {
27  for(Coordinate coord:geom.getCoordinates()) {
28  if(coord instanceof CoordinateXYM) {
29  newcoords.add(new CoordinateXYM(coord.getY(),coord.getX(),coord.getM()));
30  }else if(coord instanceof CoordinateXYZM) {
31  newcoords.add(new CoordinateXYZM(coord.getY(),coord.getX(),coord.getZ(),coord.getM()));
32  }else {
33  newcoords.add(new Coordinate(coord.getY(),coord.getX()));
34  }
35  }
36  }else if(ords.equalsIgnoreCase("xz")) {
37  for(Coordinate coord:geom.getCoordinates()) {
38  if(coord instanceof CoordinateXYM) {
39  throw new RuntimeException("Coordinates do not contain a Z value");
40  }else if(coord instanceof CoordinateXYZM) {
41  newcoords.add(new CoordinateXYZM(coord.getZ(),coord.getY(),coord.getX(),coord.getM()));
42  }else {
43  newcoords.add(new Coordinate(coord.getZ(),coord.getY(),coord.getX()));
44  }
45  }
46  }else if(ords.equalsIgnoreCase("yz")) {
47  for(Coordinate coord:geom.getCoordinates()) {
48  if(coord instanceof CoordinateXYM) {
49  throw new RuntimeException("Coordinates do not contain a Z value");
50  }else if(coord instanceof CoordinateXYZM) {
51  newcoords.add(new CoordinateXYZM(coord.getX(),coord.getZ(),coord.getY(),coord.getM()));
52  }else {
53  newcoords.add(new Coordinate(coord.getX(),coord.getZ(),coord.getY()));
54  }
55  }
56  }else if(ords.equalsIgnoreCase("xm")) {
57  for(Coordinate coord:geom.getCoordinates()) {
58  if(coord instanceof CoordinateXYM) {
59  newcoords.add(new CoordinateXYM(coord.getM(),coord.getY(),coord.getX()));
60  }else if(coord instanceof CoordinateXYZM) {
61  newcoords.add(new CoordinateXYZM(coord.getM(),coord.getY(),coord.getZ(),coord.getX()));
62  }else {
63  throw new RuntimeException("Coordinates do not contain a M value");
64  }
65  }
66  }else if(ords.equalsIgnoreCase("ym")) {
67  for(Coordinate coord:geom.getCoordinates()) {
68  if(coord instanceof CoordinateXYM) {
69  newcoords.add(new CoordinateXYM(coord.getX(),coord.getM(),coord.getY()));
70  }else if(coord instanceof CoordinateXYZM) {
71  newcoords.add(new CoordinateXYZM(coord.getX(),coord.getM(),coord.getZ(),coord.getY()));
72  }else {
73  throw new RuntimeException("Coordinates do not contain a M value");
74  }
75  }
76  }else if(ords.equalsIgnoreCase("zm")) {
77  for(Coordinate coord:geom.getCoordinates()) {
78  if(coord instanceof CoordinateXYM) {
79  throw new RuntimeException("Coordinates do not contain a M and Z value");
80  }else if(coord instanceof CoordinateXYZM) {
81  newcoords.add(new CoordinateXYZM(coord.getX(),coord.getY(),coord.getM(),coord.getZ()));
82  }else {
83  throw new RuntimeException("Coordinates do not contain a M and Z value");
84  }
85  }
86  }else {
87  throw new RuntimeException("Invalid second argument");
88  }
89  return LiteralUtils.createGeometry(newcoords, geom.getGeometryType(), geom.getSRID());
90  }