def test_st_start_point(self): point_df = create_sample_points_df(self.spark, 5) polygon_df = create_sample_polygons_df(self.spark, 5) linestring_df = create_sample_lines_df(self.spark, 5) expected_points = [ "POINT (-112.506968 45.98186)", "POINT (-112.519856 45.983586)", "POINT (-112.504872 45.919281)", "POINT (-112.574945 45.987772)", "POINT (-112.520691 42.912313)" ] points = point_df.selectExpr("ST_StartPoint(geom) as geom").filter( "geom IS NOT NULL") polygons = polygon_df.selectExpr("ST_StartPoint(geom) as geom").filter( "geom IS NOT NULL") linestrings = linestring_df.selectExpr( "ST_StartPoint(geom) as geom").filter("geom IS NOT NULL") assert ([line[0] for line in linestrings.collect() ] == [wkt.loads(el) for el in expected_points]) assert (not points.count()) assert (not polygons.count())
def test_st_y(self): point_df = create_sample_points_df(self.spark, 5) polygon_df = create_sample_polygons_df(self.spark, 5) linestring_df = create_sample_lines_df(self.spark, 5) points = point_df \ .selectExpr("ST_Y(geom)").collect() polygons = polygon_df.selectExpr("ST_Y(geom) as y").filter("y IS NOT NULL") linestrings = linestring_df.selectExpr("ST_Y(geom) as y").filter("y IS NOT NULL") assert([point[0] for point in points] == [42.28787, 32.324142, 32.324142, 5.3324324, -88.331492]) assert(not linestrings.count()) assert(not polygons.count())
def test_st_x(self): point_df = create_sample_points_df(self.spark, 5) polygon_df = create_sample_polygons_df(self.spark, 5) linestring_df = create_sample_lines_df(self.spark, 5) points = point_df \ .selectExpr("ST_X(geom)").collect() polygons = polygon_df.selectExpr("ST_X(geom) as x").filter("x IS NOT NULL") linestrings = linestring_df.selectExpr("ST_X(geom) as x").filter("x IS NOT NULL") assert([point[0] for point in points] == [-71.064544, -88.331492, 88.331492, 1.0453, 32.324142]) assert(not linestrings.count()) assert(not polygons.count())