def test_ST_Intersection(): data1 = pandas.Series(["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POINT (0 1)"]) data2 = pandas.Series(["POLYGON ((2 1,3 1,3 2,2 2,2 1))", "POINT (0 1)"]) rst = arctern.ST_AsText( arctern.ST_Intersection(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))) assert len(rst) == 2 assert rst[0] == "LINESTRING (2 2,2 1)" assert rst[1] == "POINT (0 1)" rst = arctern.ST_AsText( arctern.ST_Intersection(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText("POINT (0 1)")[0])) assert len(rst) == 2 assert rst[0] == "GEOMETRYCOLLECTION EMPTY" assert rst[1] == "POINT (0 1)" rst = arctern.ST_AsText( arctern.ST_Intersection( arctern.ST_GeomFromText("POINT (0 1)")[0], arctern.ST_GeomFromText(data1))) assert len(rst) == 2 assert rst[0] == "GEOMETRYCOLLECTION EMPTY" assert rst[1] == "POINT (0 1)" rst = arctern.ST_AsText( arctern.ST_Intersection( arctern.ST_GeomFromText("POINT (0 1)")[0], arctern.ST_GeomFromText("POINT (0 1)")[0])) assert len(rst) == 1 assert rst[0] == "POINT (0 1)"
def test_ST_Union_Aggr(): p1 = "POLYGON ((1 1,1 2,2 2,2 1,1 1))" p2 = "POLYGON ((2 1,3 1,3 2,2 2,2 1))" data = pandas.Series([p1, p2]) rst = arctern.ST_AsText( arctern.ST_Union_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == "POLYGON ((1 1,1 2,2 2,3 2,3 1,2 1,1 1))" p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))" p2 = "POLYGON ((3 1,5 1,5 2,3 2,3 1))" data = pandas.Series([p1, p2]) rst = arctern.ST_AsText( arctern.ST_Union_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == "POLYGON ((4 1,4 0,0 0,0 4,4 4,4 2,5 2,5 1,4 1))" p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))" p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))" data = pandas.Series([p1, p2]) rst = arctern.ST_AsText( arctern.ST_Union_Aggr(arctern.ST_GeomFromText(data))) assert rst[ 0] == "MULTIPOLYGON (((0 0,4 0,4 4,0 4,0 0)),((5 1,7 1,7 2,5 2,5 1)))" p1 = "POLYGON ((0 0,0 4,4 4,4 0,0 0))" p2 = "POINT (2 3)" data = pandas.Series([p1, p2]) rst = arctern.ST_AsText( arctern.ST_Union_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == p1
def test_ST_GeomFromText(): p0 = "POINT (1 2)" p1 = "LINESTRING (1 2,4 5,7 8)" p2 = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" data = pandas.Series([p0, p1, p2]) str_ptr = arctern.ST_AsText(arctern.ST_GeomFromText(data)) assert str_ptr[0] == "POINT (1 2)" assert str_ptr[1] == "LINESTRING (1 2,4 5,7 8)" assert str_ptr[2] == "POLYGON ((0 0,0 1,1 1,1 0,0 0))" wkb_array = arctern.ST_GeomFromText('POINT (1 2)') wkt_array = arctern.ST_AsText(wkb_array[0]) assert wkt_array[0] == "POINT (1 2)"
def test_tuple(self): p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))" p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))" data = (p1, p2) rst = arctern.ST_AsText( arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == "POLYGON ((0 0,0 4,7 4,7 0,0 0))"
def test_ndarray(self): p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))" p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))" import numpy as np data = np.array([p1, p2]) rst = arctern.ST_AsText(arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == "POLYGON ((0 0,0 4,7 4,7 0,0 0))"
def test_ST_Buffer(): data = ["POLYGON((0 0,1 0,1 1,0 0))"] data = pandas.Series(data) rst = arctern.ST_AsText(arctern.ST_Buffer(arctern.ST_GeomFromText(data), 1.2)) expect = "POLYGON ((-0.848528137423857 0.848528137423857,0.151471862576143 1.84852813742386,0.19704327236937 1.89177379057287,0.244815530740195 1.93257515374836,0.294657697249032 1.97082039324994,0.346433157981967 2.00640468153451,0.4 2.03923048454133,0.455211400312543 2.06920782902604,0.511916028309039 2.09625454917112,0.569958460545639 2.12029651179664,0.629179606750062 2.14126781955418,0.689417145876974 2.15911099154688,0.750505971018688 2.17377712088057,0.812278641951722 2.18522600871417,0.874565844078815 2.19342627444193,0.937196852508467 2.19835544170549,1.0 2.2,1.06280314749153 2.19835544170549,1.12543415592118 2.19342627444193,1.18772135804828 2.18522600871417,1.24949402898131 2.17377712088057,1.31058285412302 2.15911099154688,1.37082039324994 2.14126781955418,1.43004153945436 2.12029651179664,1.48808397169096 2.09625454917112,1.54478859968746 2.06920782902604,1.6 2.03923048454133,1.65356684201803 2.00640468153451,1.70534230275097 1.97082039324994,1.75518446925981 1.93257515374836,1.80295672763063 1.89177379057287,1.84852813742386 1.84852813742386,1.89177379057287 1.80295672763063,1.93257515374837 1.7551844692598,1.97082039324994 1.70534230275097,2.00640468153451 1.65356684201803,2.03923048454133 1.6,2.06920782902604 1.54478859968746,2.09625454917112 1.48808397169096,2.12029651179664 1.43004153945436,2.14126781955418 1.37082039324994,2.15911099154688 1.31058285412302,2.17377712088057 1.24949402898131,2.18522600871417 1.18772135804828,2.19342627444193 1.12543415592118,2.19835544170549 1.06280314749153,2.2 1.0,2.2 0.0,2.19835544170549 -0.062803147491532,2.19342627444193 -0.125434155921184,2.18522600871417 -0.187721358048277,2.17377712088057 -0.249494028981311,2.15911099154688 -0.310582854123025,2.14126781955418 -0.370820393249937,2.12029651179664 -0.43004153945436,2.09625454917112 -0.48808397169096,2.06920782902604 -0.544788599687456,2.03923048454133 -0.6,2.00640468153451 -0.653566842018033,1.97082039324994 -0.705342302750968,1.93257515374836 -0.755184469259805,1.89177379057287 -0.80295672763063,1.84852813742386 -0.848528137423857,1.80295672763063 -0.891773790572873,1.75518446925981 -0.932575153748365,1.70534230275097 -0.970820393249937,1.65356684201803 -1.00640468153451,1.6 -1.03923048454133,1.54478859968746 -1.06920782902604,1.48808397169096 -1.09625454917112,1.43004153945436 -1.12029651179664,1.37082039324994 -1.14126781955418,1.31058285412302 -1.15911099154688,1.24949402898131 -1.17377712088057,1.18772135804828 -1.18522600871417,1.12543415592118 -1.19342627444193,1.06280314749153 -1.19835544170549,1.0 -1.2,0.0 -1.2,-0.062803147491532 -1.19835544170549,-0.125434155921184 -1.19342627444193,-0.187721358048276 -1.18522600871417,-0.24949402898131 -1.17377712088057,-0.310582854123024 -1.15911099154688,-0.370820393249936 -1.14126781955418,-0.430041539454359 -1.12029651179664,-0.488083971690959 -1.09625454917112,-0.544788599687455 -1.06920782902604,-0.6 -1.03923048454133,-0.653566842018031 -1.00640468153451,-0.705342302750966 -0.970820393249938,-0.755184469259804 -0.932575153748366,-0.802956727630628 -0.891773790572875,-0.848528137423855 -0.848528137423859,-0.891773790572871 -0.802956727630632,-0.932575153748363 -0.755184469259807,-0.970820393249935 -0.70534230275097,-1.00640468153451 -0.653566842018035,-1.03923048454132 -0.6,-1.06920782902604 -0.544788599687459,-1.09625454917112 -0.488083971690964,-1.12029651179664 -0.430041539454364,-1.14126781955418 -0.370820393249941,-1.15911099154688 -0.310582854123029,-1.17377712088057 -0.249494028981315,-1.18522600871416 -0.187721358048281,-1.19342627444193 -0.125434155921189,-1.19835544170549 -0.062803147491537,-1.2 -0.0,-1.19835544170549 0.062803147491527,-1.19342627444193 0.125434155921179,-1.18522600871417 0.187721358048272,-1.17377712088057 0.249494028981306,-1.15911099154688 0.310582854123019,-1.14126781955419 0.370820393249931,-1.12029651179664 0.430041539454355,-1.09625454917112 0.488083971690954,-1.06920782902604 0.54478859968745,-1.03923048454133 0.6,-1.00640468153451 0.653566842018027,-0.970820393249941 0.705342302750962,-0.93257515374837 0.755184469259799,-0.891773790572878 0.802956727630624,-0.848528137423857 0.848528137423857))" assert rst[0] == expect
def test_nearest_road(): roads = pandas.Series(["LINESTRING (0 0,2 0)", "LINESTRING (5 0,5 5)"]) gps_points = pandas.Series("POINT (1.0001 1)") rst = arctern.ST_AsText( arctern.nearest_road(arctern.ST_GeomFromText(roads), arctern.ST_GeomFromText(gps_points))) assert len(rst) == 0
def to_wkt(data): """ Convert GeoArray or np.ndarray or list to a numpy string array of wkt formed string. """ if not isinstance(data, (GeoArray, np.ndarray, list)): raise ValueError("'data' must be a GeoArray or np.ndarray or list.") return np.asarray(arctern.ST_AsText(data), dtype=str)
def test_ST_ConvexHull(): data = ["POINT (1.1 101.1)"] data = pandas.Series(data) rst = arctern.ST_AsText( arctern.ST_ConvexHull(arctern.ST_GeomFromText(data))) assert rst[0] == "POINT (1.1 101.1)"
def test_ST_Centroid(): data = ["POLYGON((0 0,1 0,1 1,0 1,0 0))", "POLYGON((0 0,0 8,8 8,8 0,0 0))"] data = pandas.Series(data) rst = arctern.ST_AsText(arctern.ST_Centroid(arctern.ST_GeomFromText(data))) assert rst[0] == "POINT (0.5 0.5)" assert rst[1] == "POINT (4 4)"
def test_ST_Intersection(): data1 = pandas.Series(["POLYGON ((1 1,1 2,2 2,2 1,1 1))"]) data2 = pandas.Series(["POLYGON ((2 1,3 1,3 2,2 2,2 1))"]) rst = arctern.ST_AsText( arctern.ST_Intersection(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))) assert rst[0] == "LINESTRING (2 2,2 1)"
def test_ST_CurveToLine(): data = ["CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0))"] data = pandas.Series(data) rst = arctern.ST_AsText( arctern.ST_CurveToLine(arctern.ST_GeomFromText(data))) assert str(rst[0]).startswith("POLYGON")
def test_ST_Point(): data1 = pandas.Series([1.3, 2.5]) data2 = pandas.Series([3.8, 4.9]) string_ptr = arctern.ST_AsText(arctern.ST_Point(data1, data2)) assert len(string_ptr) == 2 assert string_ptr[0] == "POINT (1.3 3.8)" assert string_ptr[1] == "POINT (2.5 4.9)"
def test_ST_Envelope_Aggr(): geo = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" arr = [geo for x in range(1, 10000001)] data = pandas.Series(arr) rst = arctern.ST_AsText( arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data))) assert len(rst) == 1
def test_ST_Envelope_Aggr(): p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))" p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))" data = pandas.Series([p1, p2]) rst = arctern.ST_AsText( arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data))) assert rst[0] == "POLYGON ((0 0,0 4,7 4,7 0,0 0))"
def test_ST_PrecisionReduce(): geo = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" arr = [geo for x in range(1, 10000001)] data = pandas.Series(arr) rst = arctern.ST_AsText( arctern.ST_PrecisionReduce(arctern.ST_GeomFromText(data), 3)) assert len(rst) == 10000000
def test_ST_SimplifyPreserveTopology(): data = pandas.Series( ["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((1 1,1 2,2 2,2 1,1 1))"]) rst = arctern.ST_AsText( arctern.ST_SimplifyPreserveTopology(arctern.ST_GeomFromText(data), 10000)) assert rst[0] == "POLYGON ((1 1,1 2,2 2,2 1,1 1))"
def python_test(data1, data2): TIME_START(func_name) arctern.ST_AsText( arctern.ST_Intersection(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))) TIME_END(func_name) return TIME_INFO()
def test_nearest_location_on_road(): roads = pandas.Series("LINESTRING (1 2,1 3)") gps_points = pandas.Series("POINT (1.0001 2.5)") rst = arctern.ST_AsText( arctern.nearest_location_on_road(arctern.ST_GeomFromText(roads), arctern.ST_GeomFromText(gps_points))) assert len(rst) == 1 assert rst[0] == "POINT (1.0 2.5)"
def test_ST_Transform(): geo = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" arr = [geo for x in range(1, 10000001)] data = pandas.Series(arr) rst = arctern.ST_AsText( arctern.ST_Transform(arctern.ST_GeomFromText(data), "EPSG:4326", "EPSG:3857")) assert len(rst) == 10000000
def test_ST_SimplifyPreserveTopology(): geo = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" arr = [geo for x in range(1, 10000001)] data = pandas.Series(arr) rst = arctern.ST_AsText( arctern.ST_SimplifyPreserveTopology(arctern.ST_GeomFromText(data), 10000)) assert len(rst) == 10000000
def python_test(data): TIME_START(func_name) arctern.ST_AsText( arctern.ST_Transform(arctern.ST_GeomFromText(data), "EPSG:4326", "EPSG:3857")) TIME_END(func_name) return TIME_INFO()
def python_test(data): TIME_START(func_name) arctern.ST_AsText( arctern.ST_SimplifyPreserveTopology(arctern.ST_GeomFromText(data), 10000)) TIME_END(func_name) return TIME_INFO()
def test_ST_PolygonFromEnvelope(): x_min = pandas.Series([0.0 for x in range(1, 10000001)]) x_max = pandas.Series([1.0 for x in range(1, 10000001)]) y_min = pandas.Series([0.0 for x in range(1, 10000001)]) y_max = pandas.Series([1.0 for x in range(1, 10000001)]) rst = arctern.ST_AsText( arctern.ST_PolygonFromEnvelope(x_min, y_min, x_max, y_max)) assert len(rst) == 10000000
def test_ST_GeomFromGeoJSON(): j0 = "{\"type\":\"Point\",\"coordinates\":[1,2]}" j1 = "{\"type\":\"LineString\",\"coordinates\":[[1,2],[4,5],[7,8]]}" j2 = "{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[0,1],[1,1],[1,0],[0,0]]]}" data = pandas.Series([j0, j1, j2]) str_ptr = arctern.ST_AsText(arctern.ST_GeomFromGeoJSON(data)) assert str_ptr[0] == "POINT (1 2)" assert str_ptr[1] == "LINESTRING (1 2,4 5,7 8)" assert str_ptr[2] == "POLYGON ((0 0,0 1,1 1,1 0,0 0))"
def test_ST_PolygonFromEnvelope(): x_min = pandas.Series([0.0]) x_max = pandas.Series([1.0]) y_min = pandas.Series([0.0]) y_max = pandas.Series([1.0]) rst = arctern.ST_AsText(arctern.ST_PolygonFromEnvelope(x_min, y_min, x_max, y_max)) assert rst[0] == "POLYGON ((0 0,0 1,1 1,1 0,0 0))"
def test_ST_Point(): geo1 = 1.1 geo2 = 2.1 arr1 = [geo1 for x in range(1, 10000001)] arr2 = [geo2 for x in range(1, 10000001)] data1 = pandas.Series(arr1) data2 = pandas.Series(arr2) rst = arctern.ST_AsText(arctern.ST_Point(data1, data2)) assert len(rst) == 10000000
def test_ST_Transform(): data = ["POINT (10 10)"] data = pandas.Series(data) rst = arctern.ST_AsText(arctern.ST_Transform( arctern.ST_GeomFromText(data), "EPSG:4326", "EPSG:3857")) wkt = rst[0] rst_point = ogr.CreateGeometryFromWkt(str(wkt)) assert abs(rst_point.GetX() - 1113194.90793274 < 0.01) assert abs(rst_point.GetY() - 1118889.97485796 < 0.01)
def test_ST_Point(): data1 = pandas.Series([1.3, 2.5]) data2 = pandas.Series([3.8, 4.9]) string_ptr = arctern.ST_AsText(arctern.ST_Point(data1, data2)) assert len(string_ptr) == 2 assert string_ptr[0] == "POINT (1.3 3.8)" assert string_ptr[1] == "POINT (2.5 4.9)" string_ptr = arctern.ST_AsText(arctern.ST_Point(pandas.Series([1, 2], dtype='double'), 5)) assert len(string_ptr) == 2 assert string_ptr[0] == "POINT (1 5)" assert string_ptr[1] == "POINT (2 5)" string_ptr = arctern.ST_AsText(arctern.ST_Point(5, pandas.Series([1, 2], dtype='double'))) assert len(string_ptr) == 2 assert string_ptr[0] == "POINT (5 1)" assert string_ptr[1] == "POINT (5 2)" string_ptr = arctern.ST_AsText(arctern.ST_Point(5.0, 1.0)) assert len(string_ptr) == 1 assert string_ptr[0] == "POINT (5 1)"
def test_ST_Intersects(): geo1 = "POLYGON ((0 0,0 1,1 1,1 0,0 0))" geo2 = "POLYGON ((0 0,0 2,2 2,2 0,0 0))" arr1 = [geo1 for x in range(1, 10000001)] arr2 = [geo2 for x in range(1, 10000001)] data1 = pandas.Series(arr1) data2 = pandas.Series(arr2) rst = arctern.ST_AsText( arctern.ST_Intersects(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))) assert len(rst) == 10000000