class SplitPolygonCommand implements CommandHasRequest<SplitPolygonRequest, SplitPolygonResponse> {

	@Override
	public void execute(SplitPolygonRequest request, SplitPolygonResponse response) throws Exception {
		// convert to most accurate precision model
		com.vividsolutions.jts.geom.Geometry jtsGeometry = converter.toInternal(request.getGeometry());
		if (!(jtsGeometry instanceof Polygon)) {
			throw new GeomajasException(ExceptionCode.UNEXPECTED_PROBLEM, "geometry has to be a Polygon");
		}
		Polygon polygon = (Polygon) converter.toInternal(request.getGeometry());

		// Convert to the polygons precision model:
		jtsGeometry = converter.toInternal(request.getSplitter());
		if (!(jtsGeometry instanceof LineString)) {
			throw new GeomajasException(ExceptionCode.UNEXPECTED_PROBLEM, "splitter has to be a LineString");
		}
		LineString preciseLine = (LineString) jtsGeometry;
		int precision = polygon.getPrecisionModel().getMaximumSignificantDigits() - 1;
		com.vividsolutions.jts.geom.Geometry bufferedLine = preciseLine.buffer(Math.pow(10.0, -precision));
		com.vividsolutions.jts.geom.Geometry diff = polygon.difference(bufferedLine);

		if (diff instanceof Polygon) {
			response.setGeometries(new Geometry[] { converter.toDto(diff) });
		} else if (diff instanceof MultiPolygon) {
			Geometry[] polygons = new Geometry[diff.getNumGeometries()];
			for (int i = 0; i < diff.getNumGeometries(); i++) {
				polygons[i] = converter.toDto(diff.getGeometryN(i));
			}
			response.setGeometries(polygons);
		}
	}

}