def test_st_exterior_ring(self): polygon_df = create_simple_polygons_df(self.spark, 5) additional_wkt = "POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))" additional_wkt_df = self.spark.createDataFrame( [[wkt.loads(additional_wkt)]], self.geo_schema) polygons_df = polygon_df.union(additional_wkt_df) other_geometry_df = create_sample_lines_df(self.spark, 5).union( create_sample_points_df(self.spark, 5)) linestring_df = polygons_df.selectExpr( "ST_ExteriorRing(geom) as geom").filter("geom IS NOT NULL") empty_df = other_geometry_df.selectExpr( "ST_ExteriorRing(geom) as geom").filter("geom IS NOT NULL") linestring_wkt = [ wkt_row[0] for wkt_row in linestring_df.selectExpr( "ST_AsText(geom)").collect() ] assert (linestring_wkt == [ "LINESTRING (0 0, 0 1, 1 1, 1 0, 0 0)", "LINESTRING (0 0, 1 1, 1 2, 1 1, 0 0)" ]) assert (not empty_df.count())
def test_st_dump_points(self): expected_points = [ "POINT (-112.506968 45.98186)", "POINT (-112.506968 45.983586)", "POINT (-112.504872 45.983586)", "POINT (-112.504872 45.98186)", "POINT (-71.064544 42.28787)", "POINT (0 0)", "POINT (0 1)", "POINT (1 1)", "POINT (1 0)", "POINT (0 0)" ] geometry_df = create_sample_lines_df(self.spark, 1) \ .union(create_sample_points_df(self.spark, 1)) \ .union(create_simple_polygons_df(self.spark, 1)) dumped_points = geometry_df.selectExpr("ST_DumpPoints(geom) as geom") \ .select(explode(col("geom")).alias("geom")) assert (dumped_points.count() == 10) collected_points = [ geom_row[0] for geom_row in dumped_points.selectExpr( "ST_AsText(geom)").collect() ] assert (collected_points == expected_points)