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

Public Member Functions

boolean attribute (Geometry geom)
 
String getURI ()
 
Value evaluate (ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException
 

Static Public Member Functions

static boolean isConvex (Polygon p)
 

Member Function Documentation

◆ attribute()

boolean attribute ( Geometry  geom)

References IsConvex.isConvex().

14  {
15  if (geom instanceof LinearRing || geom instanceof Polygon) {
16  boolean isConvex = isConvex((Polygon)geom);
17  return isConvex;
18  }
19  return false;
20  }
static boolean isConvex(Polygon p)
Definition: IsConvex.java:23

◆ evaluate()

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

References GeometricBinaryAttributeFunction.attribute(), and LiteralRegistry.getLiteral().

17  {
18  if (args.length != 1) {
19  throw new ValueExprEvaluationException(getURI() + " requires exactly 1 arguments, got " + args.length);
20  }
21 
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  boolean result = attribute(geom);
26  return valueFactory.createLiteral(result);
27  }
28  throw new ValueExprEvaluationException("Argument given is not a geometry literal");
29 
30  }

◆ getURI()

String getURI ( )

References POSTGIS.st_isConvex.

46  {
47  return POSTGIS.st_isConvex.stringValue();
48  }

◆ isConvex()

static boolean isConvex ( Polygon  p)
static

References Coordinate.x, and Coordinate.y.

Referenced by IsConvex.attribute().

23  {
24  LinearRing r = (LinearRing) p.getExteriorRing();
25  int sign = 0;
26  for(int i = 1; i < r.getNumPoints(); ++i) {
27  Coordinate c0 = r.getCoordinateN(i == 0 ? r.getNumPoints() - 1 : i - 1);
28  Coordinate c1 = r.getCoordinateN(i);
29  Coordinate c2 = r.getCoordinateN(i == r.getNumPoints() - 1 ? 0 : i + 1);
30  double dx1 = c1.x - c0.x;
31  double dy1 = c1.y - c0.y;
32  double dx2 = c2.x - c1.x;
33  double dy2 = c2.y - c2.y;
34  double z = dx1 * dy2 - dy1 * dx2;
35  int s = z >= 0.0 ? 1 : -1;
36  if(sign == 0) {
37  sign = s;
38  } else if(sign != s) {
39  return false;
40  }
41  }
42  return true;
43  }