Commit 1b2434ba authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade posibilidad de configurar cluster de track

parent e82eb929
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -41,10 +41,10 @@ public class ProcessClusterMultiElementFunction
		implements IProcessItemFunction<GeoHitWrapper<GeoDataProperties, Point>> {

	int zoomLevel;
	int minPixelsToCluster;
	String elementUuid;

	private static String CRS_NAME = "EPSG:4326";
	private static int MIN_PIXELS_TO_CLUSTER = 8;

	private CoordinateReferenceSystem crs = GeometryUtils.getCRS(CRS_NAME);

@@ -52,9 +52,10 @@ public class ProcessClusterMultiElementFunction

	protected ObjectMapper objectMapper;

	public ProcessClusterMultiElementFunction(ObjectMapper objectMapper, int zoomLevel) {
	public ProcessClusterMultiElementFunction(ObjectMapper objectMapper, int zoomLevel, int minPixelsToCluster) {
		this.objectMapper = objectMapper;
		this.zoomLevel = zoomLevel;
		this.minPixelsToCluster = minPixelsToCluster;
	}

	@Override
@@ -70,7 +71,7 @@ public class ProcessClusterMultiElementFunction
		} else {
			BaseTrackingClusterDTO cluster = clustersByElements.get(clustersByElements.size() - 1);

			if (checkPointBelongsToCluster(cluster.getCentroid(), feature.getGeometry(), zoomLevel))
			if (checkPointBelongsToCluster(cluster.getCentroid(), feature.getGeometry(), zoomLevel, minPixelsToCluster))
				cluster.addPoinInCluster(feature);
			else if (TrackingLinestringClusterDTO.class.isInstance(cluster)) {
				((TrackingLinestringClusterDTO) cluster).addAxis(feature);
@@ -95,7 +96,7 @@ public class ProcessClusterMultiElementFunction
		return (GeoPointData) item.get_source();
	}

	public boolean checkPointBelongsToCluster(Point cluster, Point point, int zoomLevel) {
	public boolean checkPointBelongsToCluster(Point cluster, Point point, int zoomLevel, int minPixelsToCluster) {

		Double distanceInMeters = GeometryUtils.getDistanceInMeters(cluster.getCoordinate(),
									point.getCoordinate(), crs);
@@ -104,7 +105,7 @@ public class ProcessClusterMultiElementFunction

		Double pixels = distanceInMeters / meterByPixel;

		return !(pixels > MIN_PIXELS_TO_CLUSTER);
		return !(pixels > minPixelsToCluster);
	}

	@Override
+5 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Value;

import es.redmic.es.common.queryFactory.geodata.GeoDataQueryUtils;
import es.redmic.es.common.repository.ProcessClusterMultiElementFunction;
@@ -42,6 +43,9 @@ import es.redmic.models.es.geojson.tracking.common.BaseTrackingClusterDTO;
public abstract class ClusterTrackingESRepository<TModel extends Feature<GeoDataProperties, ?>>
		extends GeoPresenceESRepository<TModel> {

	@Value("${redmic.elasticsearch.MIN_PIXELS_TO_CLUSTER}")
	private int minPixelsToCluster;

	protected final static String BASE_PATH = "properties.inTrack", DATE_PATH = "properties.inTrack.date",
			PLATFORM_PATH = "properties.inTrack.platform.uuid", ANIMAL_PATH = "properties.collect.animal.uuid",
			QFLAG_PATH = "properties.inTrack.qFlag", ACCEPTED_QFLAG = "1";
@@ -82,7 +86,7 @@ public abstract class ClusterTrackingESRepository<TModel extends Feature<GeoData

		@SuppressWarnings("unchecked")
		List<BaseTrackingClusterDTO> result = (List<BaseTrackingClusterDTO>) scrollQueryReturnItems(queryBuilder,
				new ProcessClusterMultiElementFunction(objectMapper, zoomLevel));
				new ProcessClusterMultiElementFunction(objectMapper, zoomLevel, minPixelsToCluster));

		GeoJSONFeatureCollectionDTO collection = new GeoJSONFeatureCollectionDTO();

+4 −3
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public class ProcessClusterMultiElementFunctionTest {

	ObjectMapper objectMapper = new ObjectMapper();
	int zoomLevel = 19;
	int minPixelsToCluster = 8;

	private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH);
	static GeometryFactory geomFactory = new GeometryFactory();
@@ -136,7 +137,7 @@ public class ProcessClusterMultiElementFunctionTest {
	@Test
	public void should_returnListWithATrackingClusterDTO_when_processFirstPoint() throws Exception {

		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel);
		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel, minPixelsToCluster);

		f1.getProperties().getInTrack().setPlatform(pl1);

@@ -152,7 +153,7 @@ public class ProcessClusterMultiElementFunctionTest {
	@Test
	public void should_returnListWithATrackingLinestringClusterDTO_when_processTwoPoint() throws Exception {

		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel);
		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel, minPixelsToCluster);

		f1.getProperties().getInTrack().setPlatform(pl1);
		f2.getProperties().getInTrack().setPlatform(pl1);
@@ -170,7 +171,7 @@ public class ProcessClusterMultiElementFunctionTest {
	@Test
	public void should_returnListWithTwoTrackingCluster_when_processDifferentPlatformPoints() throws Exception {

		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel);
		ProcessClusterMultiElementFunction process = new ProcessClusterMultiElementFunction(objectMapper, zoomLevel, minPixelsToCluster);

		f1.getProperties().getInTrack().setPlatform(pl1);
		f2.getProperties().getInTrack().setPlatform(pl1);