rdf4j-postgis  Version 0.1.0.0
Angle Class Reference

Calculates an angle between three given points. More...

Inheritance diagram for Angle:
Collaboration diagram for Angle:

Public Member Functions

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

Static Public Member Functions

static double findAngle (Coordinate a, Coordinate b, Coordinate c)
 Calculates an angle between three different coordinates. More...
 

Protected Member Functions

Double relation (Geometry geom, Geometry geom2, Geometry geom3)
 

Detailed Description

Calculates an angle between three given points.

Member Function Documentation

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
16  {
17  if (args.length != 3) {
18  throw new ValueExprEvaluationException(getURI() + " requires exactly 3 arguments, got " + args.length);
19  }
20 
21  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
22  LiteralType l2=LiteralRegistry.getLiteral(((Literal)args[1]).getDatatype().toString());
23  LiteralType l3=LiteralRegistry.getLiteral(((Literal)args[2]).getDatatype().toString());
24  if(l instanceof VectorLiteral && l2 instanceof VectorLiteral) {
25  Geometry geom=((VectorLiteral)l).read(args[0].stringValue());
26  Geometry geom2=((VectorLiteral)l2).read(args[1].stringValue());
27  Geometry geom3=((VectorLiteral)l3).read(args[2].stringValue());
28  Double result = relation(geom,geom2,geom3);
29  return valueFactory.createLiteral(result);
30  }
31  throw new ValueExprEvaluationException("Argument given is not a geometry literal");
32  }

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

Referenced by AngleTest.testAngle().

◆ findAngle()

static double findAngle ( Coordinate  a,
Coordinate  b,
Coordinate  c 
)
static

Calculates an angle between three different coordinates.

Parameters
athe first coordinate
bthe second coordinate
cthe third coordinate
Returns
the calculated angle
20  {
21  double AB = Math.sqrt(Math.pow(b.x-a.x,2)+ Math.pow(b.y-a.y,2));
22  double BC = Math.sqrt(Math.pow(b.x-c.x,2)+ Math.pow(b.y-c.y,2));
23  double AC = Math.sqrt(Math.pow(c.x-a.x,2)+ Math.pow(c.y-a.y,2));
24  return Math.acos((BC*BC+AB*AB-AC*AC)/(2*BC*AB));
25  }

Referenced by Angle.relation().

◆ getURI()

String getURI ( )
28  {
29  return POSTGIS.st_angle.stringValue();
30  }

References POSTGIS.st_angle.

◆ relation()

Double relation ( Geometry  geom,
Geometry  geom2,
Geometry  geom3 
)
protected

Reimplemented from GeometricDoubleThreeGeometryFunction.

33  {
34  Coordinate coord1,coord2,coord3;
35  if("Point".equals(geom.getGeometryType())) {
36  coord1=geom.getCoordinate();
37  }else {
38  coord1=geom.getCentroid().getCoordinate();
39  }
40  if("Point".equals(geom2.getGeometryType())) {
41  coord2=geom2.getCoordinate();
42  }else {
43  coord2=geom2.getCentroid().getCoordinate();
44  }
45  if("Point".equals(geom3.getGeometryType())) {
46  coord3=geom3.getCoordinate();
47  }else {
48  coord3=geom3.getCentroid().getCoordinate();
49  }
50  return findAngle(coord1,coord2,coord3);
51  }
static double findAngle(Coordinate a, Coordinate b, Coordinate c)
Calculates an angle between three different coordinates.
Definition: Angle.java:20

References Angle.findAngle().