Пример #1
0
def test_read_from_table_success():
    fixture_file = open('./test/integration/center_fixtures/in/wkts.txt', 'r')
    points = fixture_file.readlines()
    fixture_file.close()

    cursor = get_cursor()

    cursor.execute(
        f"""
        CREATE TEMP TABLE test_data AS
        SELECT ST_GEOMFROMTEXT('{points[0].rstrip()}') AS geom, 1 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[1].rstrip()}') AS geom, 2 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[2].rstrip()}') AS geom, 3 AS idx
        """
    )

    cursor.execute(
        """
        SELECT ST_ASTEXT(@@RS_PREFIX@@carto.ST_CENTERMEAN(geom))
        FROM test_data ORDER BY idx
        """.replace(
            '@@RS_PREFIX@@', os.environ['RS_SCHEMA_PREFIX']
        )
    )

    results = cursor.fetchall()

    assert str(results[0][0]) == 'POINT(4.84119415283 45.7580714303)'
    assert str(results[1][0]) == 'POINT(25 27.5)'
    assert str(results[2][0]) == 'POINT(-58.75 22.5)'
def test_read_from_table_success():
    fixture_file = open('./test/integration/center_fixtures/in/wkts.txt', 'r')
    points = fixture_file.readlines()
    fixture_file.close()

    cursor = get_cursor()

    cursor.execute(
        f"""
        CREATE TEMP TABLE test_data AS
        SELECT ST_GEOMFROMTEXT('{points[0].rstrip()}') AS geom, 1 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[1].rstrip()}') AS geom, 2 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[2].rstrip()}') AS geom, 3 AS idx
        """
    )

    cursor.execute(
        """
        SELECT ST_ASTEXT(@@RS_PREFIX@@carto.ST_CENTEROFMASS(geom))
        FROM test_data ORDER BY idx
        """.replace(
            '@@RS_PREFIX@@', os.environ['RS_SCHEMA_PREFIX']
        )
    )

    results = cursor.fetchall()

    assert str(results[0][0]) == 'POINT(4.84072896514 45.7558120999)'
    assert str(results[1][0]) == 'POINT(25.4545454545 26.9696969697)'
    assert str(results[2][0]) == 'POINT(-50.197740113 19.1525423729)'
Пример #3
0
def test_read_from_table_success():
    cursor = get_cursor()

    cursor.execute(
        """
        CREATE TEMP TABLE test_data AS
        SELECT ST_MakePoint(0, 0) AS geom, 10 AS distance, 90 AS bearing,
            'kilometers' AS units, 1 AS idx UNION ALL
        SELECT ST_MakePoint(-3.70325, 40.4167) AS geom, 5 AS distance, 45 AS bearing,
            'kilometers' AS units, 2 AS idx UNION ALL
        SELECT ST_MakePoint(-43.7625, -20) AS geom, 150 AS distance, -20 AS bearing,
            'miles' AS units, 3 AS idx
        """
    )

    cursor.execute(
        """
        SELECT ST_ASTEXT(@@RS_PREFIX@@carto.ST_DESTINATION(
            geom, distance, bearing, units))
        FROM test_data ORDER BY idx
        """.replace(
            '@@RS_PREFIX@@', os.environ['RS_SCHEMA_PREFIX']
        )
    )

    results = cursor.fetchall()

    assert str(results[0][0]) == 'POINT(0.0899320363725 0)'
    assert str(results[1][0]) == 'POINT(-3.6614678544 40.4484882583)'
    assert str(results[2][0]) == 'POINT(-44.542881219 -17.9582789435)'
Пример #4
0
def test_read_from_table_success():
    cursor = get_cursor()

    cursor.execute(
        """
        CREATE TEMP TABLE test_data AS
        SELECT ST_MakePoint(0,0) AS start_point,
            ST_MakePoint(0,10) AS end_point,
            11 AS npoints, 1 AS idx UNION ALL
        SELECT ST_MakePoint(-1.70325, 1.4167) AS start_point,
            ST_MakePoint(1.70325, -1.4167) AS end_point,
            5 AS npoints, 2 AS idx UNION ALL
        SELECT ST_MakePoint(5, 5) AS start_points,
            ST_MakePoint(-5,-5) AS end_point,
            9 AS npoints, 3 AS idx
        """
    )

    cursor.execute(
        """
        SELECT ST_ASTEXT(@@RS_PREFIX@@carto.ST_GREATCIRCLE(
            start_point, end_point, npoints))
        FROM test_data ORDER BY idx
        """.replace(
            '@@RS_PREFIX@@', os.environ['RS_SCHEMA_PREFIX']
        )
    )

    results = cursor.fetchall()

    fixture_file = open(
        './test/integration/greatcircle_fixtures/out/wkts_table.txt', 'r'
    )
    lines = fixture_file.readlines()
    fixture_file.close()

    for idx, result in enumerate(results):
        assert str(result[0]) == lines[idx].rstrip()
def test_read_from_table_success():
    fixture_file = open('./test/integration/center_fixtures/in/wkts.txt', 'r')
    points = fixture_file.readlines()
    fixture_file.close()

    cursor = get_cursor()

    cursor.execute(f"""
        CREATE TEMP TABLE test_data AS
        SELECT ST_GEOMFROMTEXT('{points[0].rstrip()}') AS geom, 1 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[1].rstrip()}') AS geom, 2 AS idx UNION ALL
        SELECT ST_GEOMFROMTEXT('{points[2].rstrip()}') AS geom, 3 AS idx
        """)

    cursor.execute("""
        SELECT ST_ASTEXT(@@RS_PREFIX@@carto.ST_CENTERMEDIAN(geom))
        FROM test_data ORDER BY idx
        """.replace('@@RS_PREFIX@@', os.environ['RS_SCHEMA_PREFIX']))

    results = cursor.fetchall()

    assert str(results[0][0]) == 'POINT(4.82410599215 45.7653117302)'
    assert str(results[1][0]) == 'POINT(26.3841869726 19.0088147377)'
    assert str(results[2][0]) == 'POINT(-92.2112940392 33.5479292546)'