use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.
the class TestPolygonFactory method makeRegularConvexPolygons.
/**
* Create many regular convex polygons. In returnValue.get(n).get(k) we put an
* (n+3)-sided polygon with the given center and start vertex, with hole size
* equal to k/numHoleSizes. If k == 0 there is no hole. Note that k ranges between
* 0 and 4, so k/NumHoleSizes ranges between 0 and (1-1/numHoleSizes). If k == 0
* there is no hole.
*
* @return
*/
private static List<List<GeographyValue>> makeRegularConvexPolygons(GeographyPointValue firstCenter, GeographyPointValue firstFirstVertex, int minNumberVertices, int maxNumberVertices, int numHoleSizes, double xmul, double ymul) {
List<List<GeographyValue>> answer = new ArrayList<List<GeographyValue>>();
for (int numVertices = minNumberVertices; numVertices <= maxNumberVertices; numVertices += 1) {
int idx = numVertices - minNumberVertices;
List<GeographyValue> oneSize = new ArrayList<GeographyValue>();
// The x coordinate is humHoleSizes*idx.
GeographyPointValue sCenter = firstCenter.add(x.mul(numHoleSizes * idx));
for (int hidx = 0; hidx < numHoleSizes; hidx += 1) {
// The y coordinate is ymul * hidx.
GeographyPointValue offset = sCenter.add(y.mul(ymul * hidx));
GeographyPointValue center = firstCenter.add(offset);
GeographyPointValue firstVertex = firstFirstVertex.add(offset);
oneSize.add(PolygonFactory.CreateRegularConvex(center, firstVertex, numVertices, (hidx + 0.0) / numHoleSizes));
}
answer.add(oneSize);
}
return answer;
}
use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.
the class TestPolygonFactory method main.
/**
* This main routine is useful for manual testing. The idea is that one
* runs this routine and WKT polygons are printed. These can be displayed
* with qgis or some other display tool.
*
* @param arg
*/
public static void main(String[] args) {
boolean doStars = false;
boolean doRegs = false;
int minVerts = 3;
int maxVerts = 12;
int numIRs = 5;
int numHoles = 5;
double xmul = 3.0;
double ymul = 3.0;
for (int arg = 0; arg < args.length; arg += 1) {
if (args[arg].equals("--stars")) {
doStars = true;
} else if (args[arg].equals("--reg")) {
doRegs = true;
} else if (args[arg].equals("--minVerts")) {
minVerts = getIntArg(args, ++arg, "--minVerts expects one integer parameters");
} else if (args[arg].equals("--maxVerts")) {
maxVerts = getIntArg(args, ++arg, "--maxVerts expects one integer parameters");
} else if (args[arg].equals("--numHoles")) {
numHoles = getIntArg(args, ++arg, "--numHoles expects one integer parameter");
} else if (args[arg].equals("--numIRs")) {
numIRs = getIntArg(args, ++arg, "--numIRs expects one integer parameter");
} else if (args[arg].equals("--xmul")) {
xmul = getDoubleArg(args, ++arg, "--xmul expects one double parameter");
} else if (args[arg].equals("--ymul")) {
ymul = getDoubleArg(args, ++arg, "--ymul expects one double parameter");
} else {
System.err.printf("Unknown command line parameter \"%s\"\n", args[arg]);
System.exit(100);
}
}
GeographyPointValue center = origin.add(x.mul(10).add(y.mul(10)));
GeographyPointValue firstVertex = center.add(x.mul(CENTER_SHRINK * xmul).add(y.mul(CENTER_SHRINK * ymul)));
if (doRegs) {
List<List<GeographyValue>> polys = makeRegularConvexPolygons(center, firstVertex, minVerts, maxVerts, numHoles, xmul, ymul);
for (int nsides = 0; nsides < polys.size(); nsides += 1) {
for (int holeSize = 0; holeSize < 5; holeSize += 1) {
System.out.printf("%s\n", formatWKT(polys.get(nsides).get(holeSize).toString()));
}
}
}
if (doStars) {
GeographyPointValue scenter = center;
GeographyPointValue sfirstVertex = firstVertex;
List<List<List<GeographyValue>>> stars = makeStarPolygons(scenter, sfirstVertex, minVerts, maxVerts, numIRs, numHoles, xmul, ymul);
for (int nsides = 0; nsides < stars.size(); nsides += 1) {
List<List<GeographyValue>> oneSize = stars.get(nsides);
for (int innerRadiusIdx = 0; innerRadiusIdx < oneSize.size(); innerRadiusIdx += 1) {
List<GeographyValue> oneInnerRadius = oneSize.get(innerRadiusIdx);
for (int holeSizeIdx = 0; holeSizeIdx < oneInnerRadius.size(); holeSizeIdx += 1) {
GeographyValue oneStar = oneInnerRadius.get(holeSizeIdx);
System.out.printf("%s\n", formatWKT(oneStar.toString()));
}
}
}
}
}
use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.
the class TestPolygonFactory method testRegularConvexPolygon.
public void testRegularConvexPolygon() throws Exception {
// Test a triangle.
GeographyValue pt3 = PolygonFactory.CreateRegularConvex(origin, y.mul(20.0), 3, 0);
String triangle = "POLYGON ((0.0 20.0, -17.320508075689 -10.0, 17.320508075689 -10.0, 0.0 20.0))";
assertEquals(triangle, pt3.toString());
// Test a square.
GeographyValue pt4 = PolygonFactory.CreateRegularConvex(origin, y.mul(20).add(x.mul(20)), 4, 0);
String square = "POLYGON ((20.0 20.0, -20.0 20.0, -20.0 -20.0, 20.0 -20.0, 20.0 20.0))";
assertEquals(square, pt4.toString());
GeographyPointValue offset = x.mul(20).add(y.mul(20));
GeographyValue pt4plus = pt4.add(offset);
String squareOff = "POLYGON ((40.0 40.0, 0.0 40.0, 0.0 0.0, 40.0 0.0, 40.0 40.0))";
assertEquals(squareOff, pt4plus.toString());
// For n = 3 to 10, generate a regular polygon with n points
// centered at the origin starting at the given start vertex.
GeographyPointValue startVertex = x.add(y);
for (int npts = 3; npts < 10; npts += 1) {
GeographyValue regularConvex = PolygonFactory.CreateRegularConvex(origin, startVertex, npts, 0.0);
List<List<GeographyPointValue>> loops = regularConvex.getRings();
assertEquals(1, loops.size());
List<GeographyPointValue> loop = loops.get(0);
assertEquals(npts + 1, loop.size());
regularConvex = PolygonFactory.CreateRegularConvex(origin, startVertex, npts, 0.5);
loops = regularConvex.getRings();
assertEquals(2, loops.size());
assertEquals(npts + 1, loops.get(0).size());
assertEquals(npts + 1, loops.get(1).size());
}
}
use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.
the class SampleGeoRecord method nextGeography.
// POLYGON ( ( 1.5 3.0, 0.0 0.0, 3.0 0.0, 1.5 3.0 ) )
private static Object nextGeography(Random rand, boolean isNullable, int minLength, int maxLength) {
if (isNullable && rand.nextBoolean())
return null;
// we need to have at least 4 vertices
int numVertices = rand.nextInt(6) + 4;
double sizeOfHole = rand.nextDouble();
GeographyPointValue center = GeographyPointValue.fromWKT("POINT(0 0)");
GeographyPointValue firstVertex = GeographyPointValue.fromWKT("POINT(1 1)");
GeographyValue poly = PolygonFactory.CreateRegularConvex(center, firstVertex, numVertices, sizeOfHole);
return poly;
}
use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.
the class ProcToTestTypeConversion method getInListParameter.
private Object getInListParameter(byte valueTypeToPopulateWith, boolean strTs) {
VoltType toType = VoltType.get(valueTypeToPopulateWith);
switch(toType) {
case TINYINT:
byte[] tinyValue = { m_byteVal, m_byteVal };
return tinyValue;
case SMALLINT:
short[] shortValue = { m_shortVal, m_shortVal };
return shortValue;
case INTEGER:
int[] intValue = { m_intVal, m_intVal };
return intValue;
case BIGINT:
long[] bigintValue = { m_bigIntVal, m_bigIntVal };
return bigintValue;
case FLOAT:
double[] floatValue = { m_floatVal, m_floatVal };
return floatValue;
case DECIMAL:
BigDecimal[] bigdecValue = { m_bigDecVal, m_bigDecVal };
return bigdecValue;
case TIMESTAMP:
TimestampType[] tsValue = { m_tsVal, m_tsVal };
return tsValue;
case STRING:
String str = strTs ? m_strTs : m_strNum;
String[] strValue = { str, str };
return strValue;
case VARBINARY:
byte[][] binValue = { { m_byteVal, m_byteVal }, { m_byteVal, m_byteVal } };
return binValue;
case GEOGRAPHY_POINT:
GeographyPointValue[] ptValue = { m_pt, m_pt };
return ptValue;
case GEOGRAPHY:
GeographyValue[] polyValue = { m_poly, m_poly };
return polyValue;
default:
assert (false);
break;
}
return null;
}
Aggregations