presto-geospatial-toolkit/src/main/java/io/prestosql/geospatial/serde/JtsGeometrySerde.java/JtsGeometrySerde/readPolygon
class JtsGeometrySerde:    private static Geometry readPolygon(SliceInput input, boolean multitype)
    {
        skipEsriType(input);
        skipEnvelope(input);
        int partCount = input.readInt();
        if (partCount == 0) {
            if (multitype) {
                return GEOMETRY_FACTORY.createMultiPolygon();
            }
            return GEOMETRY_FACTORY.createPolygon();
        }

        int pointCount = input.readInt();
        int[] startIndexes = new int[partCount];
        for (int i = 0; i < partCount; i++) {
            startIndexes[i] = input.readInt();
        }

        int[] partLengths = new int[partCount];
        if (partCount > 1) {
            partLengths[0] = startIndexes[1];
            for (int i = 1; i < partCount - 1; i++) {
                partLengths[i] = startIndexes[i + 1] - startIndexes[i];
            }
        }
        partLengths[partCount - 1] = pointCount - startIndexes[partCount - 1];

        LinearRing shell = null;
        List<LinearRing> holes = new ArrayList<>();
        List<Polygon> polygons = new ArrayList<>();
        for (int i = 0; i < partCount; i++) {
            Coordinate[] coordinates = readCoordinates(input, partLengths[i]);
            if (isClockwise(coordinates)) {
                // next polygon has started
                if (shell != null) {
                    polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
                    holes.clear();
                }
                else {
                    verify(holes.isEmpty(), "shell is null but holes found");
                }
                shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
            }
            else {
                verifyNotNull(shell, "shell is null but hole found");
                holes.add(GEOMETRY_FACTORY.createLinearRing(coordinates));
            }
        }
        polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));

        if (multitype) {
            return GEOMETRY_FACTORY.createMultiPolygon(polygons.toArray(new Polygon[0]));
        }
        return getOnlyElement(polygons);
    }