Converting Apache Sedona SQL example to java

108 Views Asked by At

I am trying to convert the Apache Sedona examples code from scala to java, and I am stucked in the line 128 of the SQL example, which says:

assert(boundary.take(1)(0).get(0)==geometryFactory.createPolygon(coordinates))

I am trying to understand it but I am not familiar to the scala syntax. Can somebody help me obtaining a java equivalent command?

1

There are 1 best solutions below

2
On

boundary.take(1) gets an array of Rows from Spark DataFrame.

The following code works for me:

GeometryFactory geomFactory = new GeometryFactory();
Point expectedGeom = geomFactory.createPoint(new Coordinate(-88.331492, 32.324142));
Geometry actualGeom = spatialDf.javaRDD().take(1).get(0).<Geometry>getAs(0);
assert(actualGeom.equals(expectedGeom));

Note that you cannot compare a polygon with a geometry using == although you think they are the same polygon. This is because they technically have different types Polygon vs Geometry. Please use equals method to compare them.