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

Public Member Functions

String getURI ()
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Protected Member Functions

Geometry relation (Geometry geom, String value)
 

Member Function Documentation

◆ evaluate()

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

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

Referenced by SwapOrdinatesTest.testSwapOrdinates().

◆ getURI()

String getURI ( )
18  {
19  return POSTGIS.st_swapOrdinates.stringValue();
20  }

References POSTGIS.st_swapOrdinates.

◆ relation()

Geometry relation ( Geometry  geom,
String  value 
)
protected

Reimplemented from GeometricModifierStringFunction.

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  }

References LiteralUtils.createGeometry().