-1

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 Answers1

0

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.

  • I've tried it before. The IDE hints the error "The type of the expression must be an array type but it resolved to Object". I've also tried to do a cast, too, using (((Row[])boundary.take(1))[0].get(0) == geometryFactory.createPolygon(coordinates))). The code runs, but the assert returns false, so I think It is not returning what was intended to. – Dennis Savio Nov 23 '22 at 12:52
  • @DennisSavio please see the updated answer. It should be able to solve your problem. – Jia Yu - Apache Sedona Nov 23 '22 at 18:41