This is an automated email from the git hooks/post-receive script. New commit to branch feature/6944 in repository observe. See http://git.codelutin.com/observe.git commit 3e38a6adfcf98747c574ea746204a4d35c20f45e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Apr 16 16:09:54 2015 +0200 add point and fix style --- observe-swing/pom.xml | 4 + .../open/impl/seine/TripSeineUIHandler.java | 156 +++++++++++++++++---- pom.xml | 5 + 3 files changed, 141 insertions(+), 24 deletions(-) diff --git a/observe-swing/pom.xml b/observe-swing/pom.xml index 639159b..d7d6a04 100644 --- a/observe-swing/pom.xml +++ b/observe-swing/pom.xml @@ -258,6 +258,10 @@ <groupId>org.geotools</groupId> <artifactId>gt-render</artifactId> </dependency> + <dependency> + <groupId>org.geotools</groupId> + <artifactId>gt-epsg-hsql</artifactId> + </dependency> <!-- Logging --> <dependency> diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index 13bf37f..3908feb 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -22,10 +22,13 @@ package fr.ird.observe.ui.content.open.impl.seine; import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.MultiPoint; import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveDAOHelper; @@ -33,6 +36,7 @@ import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.util.TopiaExecutor2; +import fr.ird.observe.entities.constants.seine.SchoolType; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; @@ -40,12 +44,15 @@ import fr.ird.observe.tripMap.TripMapPoint; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; +import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.geotools.data.FileDataStore; import org.geotools.data.FileDataStoreFinder; import org.geotools.data.simple.SimpleFeatureSource; +import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.DefaultFeatureCollection; +import org.geotools.feature.FeatureCollection; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.geometry.DirectPosition2D; @@ -54,8 +61,10 @@ import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.map.FeatureLayer; import org.geotools.map.Layer; import org.geotools.map.MapContent; +import org.geotools.referencing.CRS; import org.geotools.styling.SLD; import org.geotools.styling.Style; +import org.geotools.styling.StyleFactory; import org.geotools.swing.JMapPane; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -63,8 +72,9 @@ import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.filter.FilterFactory; +import org.opengis.referencing.FactoryException; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; @@ -368,7 +378,6 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { mapContent = new MapContent(); mapContent.setTitle("Un titre"); - // add map layers ObserveConfig config = ui.getContextValue(ObserveConfig.class); @@ -380,44 +389,80 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { mapContent.addLayer(layer); } - // add trip + // add lines DataService dataService = getDataService(); DataSource source = getDataSource(); String tripId = getSelectedId(); - List<TripMapPoint> tripMapPoints = dataService.loadTrip(source, tripId); + List<TripMapPoint> tripMapPoints = dataService.loadTripMapActivityPoints(source, tripId); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); - typeBuilder.setName("a-type-name"); - //typeBuilder.setCRS(CRS.decode("EPSG:4326")); - typeBuilder.add("geom-attr-name", LineString.class); + SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); + lineFeatureTypeBuilder.setName("a-type-name"); + lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); + lineFeatureTypeBuilder.add("geom-attr-name", LineString.class); - SimpleFeatureType type = typeBuilder.buildFeatureType(); - SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); + SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType(); + SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType); + DefaultFeatureCollection featuresDays = new DefaultFeatureCollection(); + DefaultFeatureCollection featuresBetweenTowDays = new DefaultFeatureCollection(); - List <Coordinate> coordinates = Lists.transform(tripMapPoints, new Function<TripMapPoint, Coordinate>() { + List<Coordinate> coordinatesByDay = null; - @Override - public Coordinate apply(TripMapPoint input) { - return new Coordinate(input.getLongitude(), input.getLatitude()); + TripMapPoint previousPoint = null; + + for (TripMapPoint point : tripMapPoints) { + if (previousPoint == null) { + coordinatesByDay = Lists.newLinkedList(); + } else if (!DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) { + + if (coordinatesByDay.size() > 1) { + LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); + lineBuilder.add(line); + featuresDays.add(lineBuilder.buildFeature(null)); + } + + + Coordinate[] coordinates = { + new Coordinate(previousPoint.getLongitude(), previousPoint.getLatitude()), + new Coordinate(point.getLongitude(), point.getLatitude()), + }; + LineString lineBetweenTwoDays = geometryFactory.createLineString(coordinates); + lineBuilder.add(lineBetweenTwoDays); + featuresBetweenTowDays.add(lineBuilder.buildFeature(null)); + + coordinatesByDay = Lists.newLinkedList(); } - }); - LineString line = geometryFactory.createLineString(coordinates.toArray(new Coordinate[0])); + Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude()); + coordinatesByDay.add(coordinate); + + previousPoint = point; + } + + if (coordinatesByDay.size() > 1) { + LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); + lineBuilder.add(line); + featuresDays.add(lineBuilder.buildFeature(null)); + } + + Layer layerDays = new FeatureLayer(featuresDays, getStyleLineDay()); + Layer layerBetweenTowDays = new FeatureLayer(featuresBetweenTowDays, getStyleLineBetweenTwoDays()); + mapContent.addLayer(layerDays); + mapContent.addLayer(layerBetweenTowDays); - builder.add(line); + // add Point + FeatureCollection featurePointsLibres = generateFeaturePoints(tripMapPoints, SchoolType.libre); + FeatureCollection featurePointsObjets = generateFeaturePoints(tripMapPoints, SchoolType.objet); - SimpleFeature tripFeature = builder.buildFeature("trip"); + Layer layerPointsLibres = new FeatureLayer(featurePointsLibres, getStylePointLibre()); + Layer layerPointsObjets = new FeatureLayer(featurePointsObjets, getStylePointObjet()); + mapContent.addLayer(layerPointsLibres); + mapContent.addLayer(layerPointsObjets); - DefaultFeatureCollection features = new DefaultFeatureCollection(); - features.add(tripFeature); - Style style = SLD.createLineStyle(Color.green, 1); - Layer layer = new FeatureLayer(features, style); - mapContent.addLayer(layer); // set zoom @@ -436,6 +481,69 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { return mapContent; } + private Style getStylePointObjet() { + return SLD.createPointStyle("Triangle", Color.BLACK, Color.ORANGE, 1, 16); + } + + protected Style getStylePointLibre() { + return SLD.createPointStyle("X", Color.BLACK, Color.GREEN, 1, 16); + } + + protected FeatureCollection generateFeaturePoints(List<TripMapPoint> tripMapPoints, final SchoolType schoolType) throws FactoryException { + SimpleFeatureTypeBuilder pointFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); + pointFeatureTypeBuilder.setName("a-type-name"); + pointFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); + pointFeatureTypeBuilder.add("geom-attr-name", MultiPoint.class); + + SimpleFeatureType pointFeatureType = pointFeatureTypeBuilder.buildFeatureType(); + SimpleFeatureBuilder pointBuilder = new SimpleFeatureBuilder(pointFeatureType); + + DefaultFeatureCollection featuresPoint = new DefaultFeatureCollection(); + + Iterable<Coordinate> coordinates = Iterables.transform( + Iterables.filter(tripMapPoints, new Predicate<TripMapPoint>() { + @Override + public boolean apply(TripMapPoint input) { + return input.getSchoolType() == schoolType; + } + }), + new Function<TripMapPoint, Coordinate>() { + @Override + public Coordinate apply(TripMapPoint input) { + return new Coordinate(input.getLongitude(), input.getLatitude()); + } + }); + + GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); + + MultiPoint points = geometryFactory.createMultiPoint(Lists.newArrayList(coordinates).toArray(new Coordinate[0])); + pointBuilder.add(points); + featuresPoint.add(pointBuilder.buildFeature(null)); + + return featuresPoint; + } + + protected Style getStyleLineDay() { + return SLD.createLineStyle(Color.BLACK, 1); + } + + protected Style getStyleLineBetweenTwoDays() { + StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); + FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); + float[] dashArray = {5f, 5f}; + org.geotools.styling.Stroke stroke = sf.createStroke(ff.literal(Color.BLACK), + ff.literal(1), + null, + null, + null, + dashArray, + null, + null, + null); + + return SLD.wrapSymbolizers(sf.createLineSymbolizer(stroke, null)); + } + private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { @Override @@ -486,7 +594,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { @Override public void mouseDragged(MouseEvent e) { - endMove(e.getPoint()); +// endMove(e.getPoint()); } @Override diff --git a/pom.xml b/pom.xml index 19b1a56..2b048c0 100644 --- a/pom.xml +++ b/pom.xml @@ -511,6 +511,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.geotools</groupId> + <artifactId>gt-epsg-hsql</artifactId> + <version>${geoToolsVersion}</version> + </dependency> <!-- logging --> <dependency> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.