Skip to content

Commit 2ec733e

Browse files
authored
Merge pull request #235 from cloudimpl/create-multi-polygon
create-multi-polygon
2 parents 551f7f7 + 4083811 commit 2ec733e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

outstack-spring-repo/src/main/java/com/cloudimpl/outstack/repo/core/geo/GeoUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public static byte[] convertToGeo(GeoMetry geo) {
2828
return GeoUtil.WKB_WRITER.write(GeoUtil.GEOMETRY_FACTORY.createPolygon(convertCoordinates(polygon.getPoints())));
2929
// Geometry geometry = GeoUtil.GEOMETRY_FACTORY.createPolygon(convertCoordinates(polygon.getPoints()));
3030
// return WKB_WRITER.write(getGeometryForPolygon(getPolygon(convertCoordinates(polygon.getPoints()))));
31+
} else if (geo instanceof Polygons) {
32+
Polygons polygons = (Polygons) geo;
33+
return GeoUtil.WKB_WRITER.write(GeoUtil.GEOMETRY_FACTORY.createMultiPolygon(convertToMultiPolygon(polygons.getPolygons())));
3134
}
3235
throw new RepoException("uknown geometry " + geo.getClass().getName());
3336
}
@@ -54,4 +57,11 @@ public static Coordinate[] convertCoordinates(double[][] geometry) {
5457
.map(points -> new Coordinate(points[0], points[1]))
5558
.toArray(Coordinate[]::new);
5659
}
60+
61+
public static com.vividsolutions.jts.geom.Polygon[] convertToMultiPolygon(double[][][] geometry) {
62+
return Arrays.stream(geometry)
63+
.map(GeoUtil::convertCoordinates)
64+
.map(GEOMETRY_FACTORY::createPolygon)
65+
.toArray(com.vividsolutions.jts.geom.Polygon[]::new);
66+
}
5767
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.cloudimpl.outstack.repo.core.geo;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
7+
@AllArgsConstructor
8+
@Getter
9+
public class Polygons implements GeoMetry{
10+
11+
private double[][][] polygons;
12+
13+
}

0 commit comments

Comments
 (0)