Search in sources :

Example 16 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeospatialIndexes method populateGeoTables.

// function generates and fills table with polygon and points. For each generated polygon, there are corresponding points
// generated such that:
// - n points that are inside polygon's (this number is equal to number of vertex the polygon has)
// - 8 random points (4 in valgrind env) that are inside polygon's outer shell and along the axis line of vertex
// - 4 points that are outside polygon and near cell covering polygon
// - another one that is outside the bounding box of polygon.
// All the generated data is populated in (indexed/non-indexed) borders and places tables.
// Polygons are generated along horizontal grid
// Generated data is cached in m_polygonPoints list and used in data verification later
private void populateGeoTables(Client client) throws NoConnectionsException, IOException, ProcCallException {
    final int polygonRadius = 3;
    final int numberOfPolygonPointsForEachShape;
    if (isValgrind()) {
        // limit the data for valgrind environment as IPC can't handle data beyond 5000 rows.
        // Not Contains query hangs otherwise in valgrind environment
        numberOfPolygonPointsForEachShape = 2;
    } else {
        numberOfPolygonPointsForEachShape = 10;
    }
    // generate latitude and longitudes for somewhere in north-west hemisphere
    // generate longitude between -178 to -168
    final int longitude = m_random.nextInt(10) - 178;
    // generate latitude between 82 to 72
    final int latitude = m_random.nextInt(10) + 72;
    GeographyPointValue center = new GeographyPointValue(longitude, latitude);
    // offset to use for generating new center of polygon. this is not randomized, it will generate polygons in same order
    // in horizontal grid running along latitude line
    final GeographyPointValue centerShiftOffset = new GeographyPointValue(0.33 * polygonRadius, 0);
    // triangles without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 3, 0, numberOfPolygonPointsForEachShape);
    // triangles with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 3, 0.33, numberOfPolygonPointsForEachShape);
    // pentagons without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 5, 0, numberOfPolygonPointsForEachShape);
    // pentagons with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 5, 0.33, numberOfPolygonPointsForEachShape);
    // octagon without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 8, 0, numberOfPolygonPointsForEachShape);
    // octagons with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 8, 0.33, numberOfPolygonPointsForEachShape);
    int polygonEntries = 0;
    int pointEntries = 0;
    List<GeographyPointValue> listOfPoints;
    for (PolygonPoints polygonPoints : m_generatedPolygonPoints) {
        listOfPoints = polygonPoints.getPoints();
        for (GeographyPointValue point : listOfPoints) {
            client.callProcedure("PLACES.Insert", pointEntries, point);
            pointEntries++;
        }
        client.callProcedure("BORDERS.Insert", polygonEntries, polygonPoints.getPolygon());
        client.callProcedure("INDEXED_BORDERS.Insert", polygonEntries, polygonPoints.getPolygon());
        polygonEntries++;
    }
}
Also used : GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 17 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeospatialIndexes method subTestParameterizedContains.

private void subTestParameterizedContains(Client client, Boolean testContains) throws NoConnectionsException, IOException, ProcCallException {
    VoltTable resultsUsingGeoIndex, resultsFromNonGeoIndex;
    String indexedProcName, nonIndexProcName, predicate;
    String prefixMsg;
    if (testContains) {
        indexedProcName = "P_CONTAINS_INDEXED";
        nonIndexProcName = "P_CONTAINS";
        predicate = "Contains";
    } else {
        indexedProcName = "P_NOT_CONTAINS_INDEXED";
        nonIndexProcName = "P_NOT_CONTAINS";
        predicate = "Not Contains";
    }
    int maxPolygonsContainSamePoint = 0;
    prefixMsg = "Assertion failed comparing results of " + predicate + " on indexed with non-indexed tables: ";
    List<GeographyPointValue> points;
    for (PolygonPoints polygonPoints : m_generatedPolygonPoints) {
        points = polygonPoints.getPoints();
        for (GeographyPointValue point : points) {
            resultsUsingGeoIndex = client.callProcedure(indexedProcName, point).getResults()[0];
            resultsFromNonGeoIndex = client.callProcedure(nonIndexProcName, point).getResults()[0];
            assertTablesAreEqual(prefixMsg, resultsFromNonGeoIndex, resultsUsingGeoIndex);
            maxPolygonsContainSamePoint = (maxPolygonsContainSamePoint < resultsUsingGeoIndex.getRowCount()) ? resultsUsingGeoIndex.getRowCount() : maxPolygonsContainSamePoint;
        }
    }
    System.out.println("Max polygons for predicate '" + predicate + "': " + maxPolygonsContainSamePoint);
}
Also used : VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 18 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeospatialFunctions method testPointAsText.

public void testPointAsText() throws Exception {
    Client client = getClient();
    populateTables(client);
    // test for border case of rounding up the decimal number
    client.callProcedure("places.Insert", 50, "Someplace1", GeographyPointValue.fromWKT("POINT(13.4999999999995 17)"));
    // test for border case of rounding up the decimal number
    client.callProcedure("places.Insert", 51, "Someplace2", GeographyPointValue.fromWKT("POINT(-13.499999999999999995 -17)"));
    // get WKT representation using asText()
    VoltTable asTextVT = client.callProcedure("@AdHoc", "select loc, asText(loc) from places order by pk").getResults()[0];
    // get WKT representation using cast(point as varchar)
    VoltTable castVT = client.callProcedure("@AdHoc", "select loc, cast(loc as VARCHAR) from places order by pk").getResults()[0];
    // verify results of asText from EE matches WKT format defined in frontend/java
    while (asTextVT.advanceRow()) {
        GeographyPointValue gpv = asTextVT.getGeographyPointValue(0);
        if (gpv == null) {
            assertEquals(null, asTextVT.getString(1));
        } else {
            assertEquals(gpv.toString(), asTextVT.getString(1));
        }
    }
    // verify WKT from asText and cast(point as varchar) results in same result WKT.
    assertEquals(asTextVT, castVT);
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 19 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestPolygonFactory method testStarPolygon.

public void testStarPolygon() throws Exception {
    for (int idx = 3; idx < 10; idx += 1) {
        GeographyValue star = PolygonFactory.CreateStar(origin, y.mul(20.0), idx, 0.5, 0.0);
        List<List<GeographyPointValue>> loops = star.getRings();
        assertEquals(1, loops.size());
        List<GeographyPointValue> shell = loops.get(0);
        assertEquals(2 * idx + 1, shell.size());
        star = PolygonFactory.CreateStar(origin, y.mul(20).add(x.mul(20)), idx, 0.5, 0.1);
        loops = star.getRings();
        assertEquals(2, loops.size());
        shell = loops.get(0);
        List<GeographyPointValue> hole = loops.get(1);
        assertEquals(2 * idx + 1, shell.size());
        assertEquals(2 * idx + 1, hole.size());
    }
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) List(java.util.List) ArrayList(java.util.ArrayList) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 20 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestPolygonFactory method makeStarPolygons.

/**
     * Create many star-like polygons.  In returnValue.get(n).get(s).get(k) we put an
     * n-pointed polygon with the given center and start vertex.  The inner radius is
     * (numIrLevels-s+1)/numIrLevels.  The hole size is k/numHoleSizeLevels.
     * If k == 0, there is no hole.
     *
     * Note that n ranges between minNumPoints and maxNumPoints inclusive,
     * s between 0 numIrLevels-1, k between 0 and numHoleSizeLevels-1.  Since
     * the hole size and inner radius must both be less than 1, and the inner radius
     * must be greater than zero.  The hole size can be zero.
     *
     * @return A 3-dimensional list list of polygons.
     */
private static List<List<List<GeographyValue>>> makeStarPolygons(GeographyPointValue firstCenter, GeographyPointValue firstFirstVertex, int minNumPoints, int maxNumPoints, int numIRLevels, int numHoleSizeLevels, double xmul, double ymul) {
    List<List<List<GeographyValue>>> answer = new ArrayList<List<List<GeographyValue>>>();
    for (int numSides = minNumPoints; numSides <= maxNumPoints; numSides += 1) {
        int idx = numSides - minNumPoints;
        // The x coordinate is xmul * idx
        GeographyPointValue column = x.mul(xmul * idx);
        List<List<GeographyValue>> oneSize = new ArrayList<List<GeographyValue>>();
        for (int ratioLevel = 0; ratioLevel < numIRLevels; ratioLevel += 1) {
            GeographyPointValue irCenter = column.add(y.mul(numHoleSizeLevels * ymul * ratioLevel));
            List<GeographyValue> oneRadius = new ArrayList<GeographyValue>();
            for (int holeNumber = 0; holeNumber < numHoleSizeLevels; holeNumber += 1) {
                GeographyPointValue offset = irCenter.add(y.mul(ymul * holeNumber));
                GeographyPointValue center = firstCenter.add(offset);
                GeographyPointValue firstVertex = firstFirstVertex.add(offset);
                oneRadius.add(PolygonFactory.CreateStar(center, firstVertex, numSides, (ratioLevel + 1.0) / numIRLevels, (holeNumber + 0.0) / numHoleSizeLevels));
            }
            oneSize.add(oneRadius);
        }
        answer.add(oneSize);
    }
    return answer;
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Aggregations

GeographyPointValue (org.voltdb.types.GeographyPointValue)38 GeographyValue (org.voltdb.types.GeographyValue)23 VoltTable (org.voltdb.VoltTable)11 BigDecimal (java.math.BigDecimal)10 TimestampType (org.voltdb.types.TimestampType)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Client (org.voltdb.client.Client)7 IOException (java.io.IOException)5 JSONString (org.json_voltpatches.JSONString)3 VoltType (org.voltdb.VoltType)3 ByteBuffer (java.nio.ByteBuffer)2 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)2 NullCallback (org.voltdb.client.NullCallback)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 SimpleDateFormat (java.text.SimpleDateFormat)1