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

Public Member Functions

String getURI ()
 
Coordinate getGeoMedian (Coordinate start, Coordinate[] points)
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Protected Member Functions

Geometry operation (Geometry geom)
 

Static Private Member Functions

static double distance (double x1, double y1, double x2, double y2)
 

Member Function Documentation

◆ distance()

static double distance ( double  x1,
double  y1,
double  x2,
double  y2 
)
staticprivate
51  {
52  x1 -= x2;
53  y1 -= y2;
54  return Math.sqrt(x1 * x1 + y1 * y1);
55 }

Referenced by GeometricMedian.getGeoMedian().

◆ evaluate()

Value evaluate ( ValueFactory  valueFactory,
Value...  args 
) throws ValueExprEvaluationException
inherited
16  {
17  if (args.length != 1) {
18  throw new ValueExprEvaluationException(getURI() + " requires exactly 1 argument, got " + args.length);
19  }
20 
21  LiteralType l=LiteralRegistry.getLiteral(((Literal)args[0]).getDatatype().toString());
22  if(l instanceof VectorLiteral) {
23  Geometry geom=((VectorLiteral)l).read(args[0].stringValue());
24  Geometry result = operation(geom);
25  return valueFactory.createLiteral(((VectorLiteral) l).unparse(result),((Literal)args[0]).getDatatype());
26  }
27  throw new ValueExprEvaluationException("Argument given is not a geometry literal");
28  }

References LiteralRegistry.getLiteral(), and GeometricUnaryFunction.operation().

Referenced by BoundaryTest.testBoundary(), BoundingDiagonalTest.testBoundingDiagonal(), CentroidTest.testCentroid(), StartPointTest.testCircularString(), CircumcentreTest.testCircumcentre1(), CollectionHomogenizeTest.testCollectionHomogenize(), FlipCoordinatesTest.testFlipCoordinates(), Force2DTest.testForce2D(), Force3DTest.testForce3D(), Force3DMTest.testForce3DM(), Force3DMTest.testForce3DM2(), Force4DTest.testForce4D(), ForceCollectionTest.testForceCollection(), ForceCollectionTest.testForceCollectionZ(), ForcePolygonCCWTest.testForcePolygonCCW(), ForcePolygonCWTest.testForcePolygonCW(), EndPointTest.testLineString2D(), StartPointTest.testLineString2D(), EndPointTest.testLineString3D(), StartPointTest.testLineString3D(), MinimumBoundingCircleCenterTest.testMinimumBoundingCircle(), MinimumBoundingCircleTest.testMinimumBoundingCircle(), MinimumClearanceLineTest.testMinimumClearanceLine(), MinimumDiameterLineTest.testMinimumDiameterLine(), MinimumRectangleTest.testMinimumRectangle(), MultiTest.testMulti2D(), MultiTest.testMulti3D(), SelfIntersectionsTest.testNoSelfIntersections(), EndPointTest.testPoint(), StartPointTest.testPoint(), PointsTest.testPoints(), PointsTest.testPoints3D(), ReverseTest.testReverse(), SelfIntersectionsTest.testSelfIntersections(), ShiftLongitudeTest.testShiftLongitude(), SimplifyPreserveTopologyTest.testSimplifyVW(), and TransScaleTest.testTransScale().

◆ getGeoMedian()

Coordinate getGeoMedian ( Coordinate  start,
Coordinate[]  points 
)
27  {
28  double cx = 0;
29  double cy = 0;
30 
31  double centroidx = start.x;
32  double centroidy = start.y;
33  do {
34  double totalWeight = 0;
35  for (int i = 0; i < points.length; i++) {
36  Coordinate pt = points[i];
37  double weight = 1 / distance(pt.x, pt.y, centroidx, centroidy);
38  cx += pt.x * weight;
39  cy += pt.y * weight;
40  totalWeight += weight;
41  }
42  cx /= totalWeight;
43  cy /= totalWeight;
44  } while (Math.abs(cx - centroidx) > 0.5
45  || Math.abs(cy - centroidy) > 0.5);// Probably this condition
46  // needs to change
47 
48  return new Coordinate(cx, cy);
49 }
static double distance(double x1, double y1, double x2, double y2)
Definition: GeometricMedian.java:51

References GeometricMedian.distance().

Referenced by GeometricMedian.operation().

◆ getURI()

String getURI ( )
13  {
14  return POSTGIS.st_geometricMedian.stringValue();
15  }

References POSTGIS.st_geometricMedian.

◆ operation()

Geometry operation ( Geometry  geom)
protected

Reimplemented from GeometricUnaryFunction.

18  {
19  Coordinate median=getGeoMedian(geom.getCentroid().getCoordinate(), geom.getCoordinates());
20  GeometryFactory fac=new GeometryFactory();
21  return fac.createPoint(median);
22  }
Coordinate getGeoMedian(Coordinate start, Coordinate[] points)
Definition: GeometricMedian.java:27

References GeometricMedian.getGeoMedian().