All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geomajas.command.geometry.GeometryConvexHullCommand Maven / Gradle / Ivy

The newest version!
/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2016 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.command.geometry;

import java.util.ArrayList;
import java.util.List;

import org.geomajas.annotation.Api;
import org.geomajas.command.CommandHasRequest;
import org.geomajas.command.dto.GeometryConvexHullRequest;
import org.geomajas.command.dto.GeometryConvexHullResponse;
import org.geomajas.geometry.Geometry;
import org.geomajas.global.ExceptionCode;
import org.geomajas.global.GeomajasException;
import org.geomajas.service.DtoConverterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.vividsolutions.jts.algorithm.ConvexHull;

/**
 * 

* This command returns the convex hull of the given geometries. *

* * @author Emiel Ackermann * @since 1.11.0 */ @Component @Api public class GeometryConvexHullCommand implements CommandHasRequest { @Autowired private DtoConverterService converter; @Override public GeometryConvexHullRequest getEmptyCommandRequest() { return new GeometryConvexHullRequest(); } @Override public GeometryConvexHullResponse getEmptyCommandResponse() { return new GeometryConvexHullResponse(); } @Override public void execute(GeometryConvexHullRequest request, GeometryConvexHullResponse response) throws Exception { List clientGeometries = request.getGeometries(); if (clientGeometries == null || clientGeometries.size() == 0) { throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "request"); } // Convert to internal, apply ConvexHull and convert back to DTO List result = new ArrayList(); for (Geometry clientGeometry : clientGeometries) { result.add(converter.toDto(new ConvexHull(converter.toInternal(clientGeometry)).getConvexHull())); } response.setGeometries(result); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy