MultiPolygon Example - Java
The following shows a Java example that returns a MultiPolygon object.
public static MultiPolygon buildMultiPolygon() throws Exception
{
MultiPolygon multiPolygon = new MultiPolygon();
multiPolygon.setSrsName("EPSG:4326");
Polygon polygon = new Polygon();
//polygon.setSrsName("EPSG:4326");
Ring exteriorRing = new Ring();
LineString lineString = new LineString();
//lineString.setDimension("2");
//lineString.setSrsName("EPSG:4326");
Pos pos = new Pos();
pos.setX(-75.66);
pos.setY(42.33);
pos.setMValue(new Double(-12.33));
lineString.getPos().add(pos);
//add the viaPoint
Pos pos1 = new Pos();
pos1.setX(-77.66);
pos1.setY(43.33);
pos1.setMValue(new Double(-17.33));
lineString.getPos().add(pos1);
//add the end Point.
Pos pos2 = new Pos();
pos2.setX(-78.66);
pos2.setY(44.33);
pos2.setMValue(new Double(-19.33));
lineString.getPos().add(pos2);
Pos pos3 = new Pos();
pos3.setX(-75.66);
pos3.setY(45.33);
pos3.setMValue(new Double(-12.33));
lineString.getPos().add(pos3);
exteriorRing.getLineString().add(lineString);
polygon.setExterior(exteriorRing);
//set the interior ring.
Ring interiorRing = new Ring();
LineString interiorlineString = new LineString();
// lineString.setDimension("2");
//interiorlineString.setSrsName("EPSG:4326");
Pos interiorPos = new Pos();
interiorPos = new Pos();
interiorPos.setX(-75.66);
interiorPos.setY(45.33);
interiorPos.setMValue(new Double(-12.33));
interiorlineString.getPos().add(interiorPos);
//add the viaPoint
Pos interiorPos1 = new Pos();
interiorPos1.setX(-77.66);
interiorPos1.setY(46.33);
interiorPos1.setMValue(new Double(-17.33));
interiorlineString.getPos().add(interiorPos1);
//add the end Point.
Pos interiorPos2 = new Pos();
interiorPos2.setX(-78.66);
interiorPos2.setY(49.33);
interiorPos2.setMValue(new Double(-19.33));
interiorlineString.getPos().add(interiorPos2);
//add the end point
Pos interiorPos3 = new Pos();
interiorPos3.setX(-75.66);
interiorPos3.setY(45.33);
interiorPos3.setMValue(new Double(-12.33));
interiorlineString.getPos().add(interiorPos3);
interiorRing.getLineString().add(interiorlineString);
InteriorList interiorList = new InteriorList();
polygon.setInteriorList(interiorList);
//polygon.getInteriorList().getRing().add(interiorRing);
multiPolygon.getPolygon().add(polygon);
return multiPolygon;
}