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

Public Member Functions

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

Protected Member Functions

double relation (Geometry geom1, Geometry geom2)
 

Member Function Documentation

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
17  {
18  if (args.length != 2) {
19  throw new ValueExprEvaluationException(getURI() + " requires exactly 2 arguments, got " + args.length);
20  }
21 
22  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
23  LiteralType l2=LiteralRegistry.getLiteral(((Literal)args[1]).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 transformed=LiteralUtils.transform(geom2, geom);
28  double result = relation(geom,transformed);
29  return valueFactory.createLiteral(result);
30  }
31  throw new ValueExprEvaluationException("Arguments given are not a geometry literal");
32 
33  }

References LiteralRegistry.getLiteral(), GeometricRelationDoubleFunction.relation(), and LiteralUtils.transform().

Referenced by AreaSimilarityTest.testAreaSimilarity(), AreaSimilarityTest.testAreaSimilarity2(), BBOXDistanceTest.testBBOXDistance(), CentroidDistanceTest.testCentroidDistance(), CentroidDistanceTest.testCentroidDistance2(), DistanceSphereTest.testDistanceSphere(), DistanceSphereTest.testDistanceSphere2(), HausdorffDistanceTest.testHausdorffDistance(), IntersectionPercentageTest.testIntersectionPercentage(), IntersectionPercentageTest.testIntersectionPercentage2(), ManhattanDistanceTest.testManhattanDistance(), MaxDistanceTest.testMaxDistance(), and MaxDistance3DTest.testMaxDistance3D().

◆ getURI()

String getURI ( )
12  {
13  return POSTGIS.st_manhattandistance.stringValue();
14  }

References POSTGIS.st_manhattandistance.

◆ relation()

double relation ( Geometry  geom1,
Geometry  geom2 
)
protected

Reimplemented from GeometricRelationDoubleFunction.

18  {
19  Coordinate coord1=null,coord2=null;
20  if(geom1 instanceof Point) {
21  coord1=((Point)geom1).getCoordinate();
22  }else {
23  coord1=geom1.getCentroid().getCoordinate();
24  }
25  if(geom2 instanceof Point) {
26  coord2=((Point)geom2).getCoordinate();
27  }else {
28  coord2=geom2.getCentroid().getCoordinate();
29  }
30  return Math.abs(coord1.x - coord2.x) + Math.abs(coord1.y - coord2.y);
31  }