Improve SLC GIS Position
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 8 May 2010 14:59:10 +0000 (14:59 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 8 May 2010 14:59:10 +0000 (14:59 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3574 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

13 files changed:
demo/pom.xml
modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF
modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml
modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml
runtime/org.argeo.slc.support.gis/build.properties
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/BeanFeatureTypeBuilder.java [new file with mode: 0644]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/FeatureTypes.java [new file with mode: 0644]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/GeoToolsUtils.java [new file with mode: 0644]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/SimpleGisFieldViewer.java [deleted file]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/GisFieldViewer.java [new file with mode: 0644]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gis/model/Position.java [new file with mode: 0644]
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelPositionProvider.java
runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/jts/PositionProvider.java

index eecd2551310910f53e400ea2de1644b60df4146d..37ab5507c4acb171a8a2eeca28880586753b3a54 100644 (file)
                                                <artifactId>maven-argeo-osgi-plugin</artifactId>
                                                <configuration>
                                                        <execDir>target/exec/server</execDir>
+                                                       <systemPropertiesFile>server.properties</systemPropertiesFile>
                                                        <systemProperties>
-                                                               <argeo.osgi.start>
-                                                                       org.springframework.osgi.extender,
-                                                                       org.argeo.server.ads.server,
-                                                                       org.argeo.slc.server.hsqldb,
-                                                                       org.argeo.slc.server.hibernate,
-                                                                       org.argeo.slc.server.main,
-                                                                       org.argeo.slc.ria
-                                                               </argeo.osgi.start>
                                                                <argeo.osgi.bundles>
                                                                        ${basedir}/site;in=*;ex=pom.xml;ex=target,
                                                                        ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*,
                                                <artifactId>maven-argeo-osgi-plugin</artifactId>
                                                <configuration>
                                                        <execDir>target/exec/server</execDir>
+                                                       <systemPropertiesFile>server_jcr.properties</systemPropertiesFile>
                                                        <systemProperties>
-                                                               <argeo.osgi.start>
-                                                                       org.springframework.osgi.extender,
-                                                                       org.argeo.server.ads.server,
-                                                                       org.argeo.slc.server.jcr,
-                                                                       org.argeo.slc.server.main,
-                                                                       org.argeo.slc.ria
-                                                               </argeo.osgi.start>
                                                                <argeo.osgi.bundles>
                                                                        ${basedir}/site;in=*;ex=pom.xml;ex=target,
                                                                        ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*,
                                                <artifactId>maven-argeo-osgi-plugin</artifactId>
                                                <configuration>
                                                        <execDir>target/exec/agent</execDir>
+                                                       <systemPropertiesFile>agent.properties</systemPropertiesFile>
                                                        <systemProperties>
-                                                               <argeo.osgi.start>
-                                                                       org.springframework.osgi.extender,
-                                                                       org.argeo.slc.support.equinox,
-                                                                       org.argeo.slc.agent,
-                                                                       org.argeo.slc.agent.jms
-                                                               </argeo.osgi.start>
                                                                <argeo.osgi.bundles>
                                                                        ${basedir}/site;in=*;ex=pom.xml;ex=target,
                                                                        ${basedir}/../modules/agent;in=*;ex=pom.xml;ex=target
                                </dependency>
                        </dependencies>
                </profile>
+               <profile>
+                       <id>slc_gis_position</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               <groupId>org.argeo.maven.plugins</groupId>
+                                               <artifactId>maven-argeo-osgi-plugin</artifactId>
+                                               <configuration>
+                                                       <execDir>target/exec/agent</execDir>
+                                                       <systemPropertiesFile>slc_gis_position.properties</systemPropertiesFile>
+                                                       <systemProperties>
+                                                               <argeo.osgi.bundles>
+                                                                       ${basedir}/site;in=*;ex=pom.xml;ex=target,
+                                                                       ${basedir}/../modules/gis;in=*;ex=pom.xml;ex=target
+                                                               </argeo.osgi.bundles>
+                                                       </systemProperties>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+                       <dependencies>
+                               <dependency>
+                                       <groupId>org.argeo.slc.dep</groupId>
+                                       <artifactId>org.argeo.slc.dep.sdk</artifactId>
+                                       <version>${project.version}</version>
+                               </dependency>
+                       </dependencies>
+               </profile>
                <profile>
                        <id>detached</id>
                        <build>
index c911e9df6f4222f701007d1c6021dc57a80f3bd2..a6c59e2d3710abae0b43da588126f476226202a8 100644 (file)
@@ -3,6 +3,8 @@ Bundle-ManifestVersion: 2
 Bundle-Name: Ui
 Bundle-SymbolicName: org.argeo.slc.gis.position.ui
 Bundle-Version: 1.0.0.qualifier
-Import-Package: org.argeo.slc.geotools;version="0.12.2.SNAPSHOT-r3562",
+Import-Package: org.argeo.slc.core.deploy;version="0.12.2.SNAPSHOT-r3503",
+ org.argeo.slc.geotools;version="0.12.2.SNAPSHOT-r3562",
+ org.argeo.slc.geotools.swing;version="0.12.2.SNAPSHOT-r3565",
  org.argeo.slc.jts;version="0.12.2.SNAPSHOT-r3562",
  org.springframework.osgi.util;version="1.2.1"
index c8691ff325bab05dac0020385c7b702da5634851..9c6e89b4b51f37806fb7c477971c970de794c13c 100644 (file)
@@ -6,8 +6,8 @@
        http://www.springframework.org/schema/beans   \r
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
 \r
-       <reference id="positionProvider" interface="org.argeo.slc.jts.PositionProvider" />\r
+       <reference id="positionProvider" interface="org.argeo.slc.jts.PositionProvider" /><!--\r
 \r
        <bundle id="geotools" symbolic-name="org.argeo.dep.osgi.geotools" />\r
        <bundle id="jai.imageio" symbolic-name="org.argeo.dep.osgi.jai.imageio" />\r
-</beans:beans>
\ No newline at end of file
+--></beans:beans>
\ No newline at end of file
index 195d9dc1e4883274d8ec82fe59456c0305ee86da..425fcb3e388cd764dbb0b2b2d36ff466d5f090b7 100644 (file)
@@ -1,22 +1,46 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <beans xmlns="http://www.springframework.org/schema/beans"\r
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xmlns:p="http://www.springframework.org/schema/p"\r
        xsi:schemaLocation="\r
-       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
+       http://www.springframework.org/schema/beans\r
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/osgi  \r
+       http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd\r
+    ">\r
 \r
-       <bean id="ui" class="org.argeo.slc.geotools.SimpleGisFieldViewer"\r
-               init-method="run">\r
+       <bean id="ui" class="org.argeo.slc.geotools.swing.GisFieldViewer">\r
                <property name="positionProvider" ref="positionProvider" />\r
-               <property name="jaiImageIoClassLoader">\r
-                       <bean class="org.springframework.osgi.util.BundleDelegatingClassLoader"\r
-                               factory-method="createBundleClassLoaderFor">\r
-                               <constructor-arg>\r
-                                       <ref bean="jai.imageio" />\r
-                                       <!--\r
-                                               <bean factory-bean="bundleContext" factory-method="getBundle" />\r
-                                       -->\r
-                               </constructor-arg>\r
+               <property name="jaiImageIoClassLoader" ref="jai.imageio.bdClassLoader" />\r
+               <property name="vectors">\r
+                       <bean class="org.argeo.slc.core.deploy.DefaultResourceSet">\r
+                               <property name="base"\r
+                                       value="file:/home/mbaudier/gis/projects/100122-EasternBalkans2010/data" />\r
+                               <property name="include" value="*.shp" />\r
+                       </bean>\r
+                       <!--\r
+                               <list>\r
+                               <value>file:/home/mbaudier/gis/projects/100122-EasternBalkans2010/data/countries-EuroMed-NEarth.shp\r
+                               </value>\r
+                               <value>file:/home/mbaudier/gis/projects/100122-EasternBalkans2010/data/highways-EastBalkan-OSM.shp\r
+                               </value> </list>\r
+                       -->\r
+               </property>\r
+               <property name="rasters">\r
+                       <bean class="org.argeo.slc.core.deploy.DefaultResourceSet">\r
+                               <property name="base"\r
+                                       value="file:/home/mbaudier/gis/data/100501-Poehali" />\r
+                               <property name="include" value="*.gif" />\r
                        </bean>\r
                </property>\r
        </bean>\r
+\r
+       <bean id="jai.imageio.bdClassLoader"\r
+               class="org.springframework.osgi.util.BundleDelegatingClassLoader"\r
+               factory-method="createBundleClassLoaderFor">\r
+               <constructor-arg>\r
+                       <osgi:bundle symbolic-name="org.argeo.dep.osgi.jai.imageio" />\r
+               </constructor-arg>\r
+       </bean>\r
+\r
 </beans>
\ No newline at end of file
index 8c835be67da118b4b4b9e4bf0eff8a1bfe93da37..f667d5dd575ee5dc2c77108d50d97bed0d32396e 100644 (file)
@@ -14,4 +14,5 @@ additional.bundles = com.springsource.slf4j.api,\
                      com.springsource.org.apache.commons.beanutils,\
                      com.springsource.javax.media.jai.codec,\
                      com.springsource.javax.media.jai.core,\
-                     org.argeo.dep.osgi.jai.imageio
+                     org.argeo.dep.osgi.jai.imageio,\
+                     org.springframework.context
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/BeanFeatureTypeBuilder.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/BeanFeatureTypeBuilder.java
new file mode 100644 (file)
index 0000000..a67dc76
--- /dev/null
@@ -0,0 +1,114 @@
+package org.argeo.slc.geotools;
+
+import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.argeo.slc.SlcException;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
+import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.springframework.beans.BeanWrapper;
+import org.springframework.beans.BeanWrapperImpl;
+import org.springframework.beans.factory.FactoryBean;
+
+public class BeanFeatureTypeBuilder<T> implements FactoryBean {
+       private final BeanWrapper classBeanWrapper;
+
+       private SimpleFeatureType cachedFeatureType;
+       private List<String> cachedAttributeList;
+
+       public BeanFeatureTypeBuilder(Class<? extends T> clss) {
+               this.classBeanWrapper = new BeanWrapperImpl(clss);
+               cachedFeatureType = doBuildFeatureType();
+       }
+
+       protected SimpleFeatureType doBuildFeatureType() {
+               SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
+
+               builder
+                               .setName(getClassBeanWrapper().getWrappedClass()
+                                               .getSimpleName());
+
+               cachedAttributeList = new ArrayList<String>();
+               for (PropertyDescriptor pd : getClassBeanWrapper()
+                               .getPropertyDescriptors()) {
+                       builder.add(pd.getName(), pd.getPropertyType());
+                       cachedAttributeList.add(pd.getName());
+               }
+
+               // TODO: make it configurable
+               builder.setNamespaceURI("http://localhost/");
+               builder.setCRS(DefaultGeographicCRS.WGS84);
+
+               return builder.buildFeatureType();
+       }
+
+       public SimpleFeatureType getFeatureType() {
+               if (cachedFeatureType == null) {
+                       cachedFeatureType = doBuildFeatureType();
+               }
+               return cachedFeatureType;
+       }
+
+       @SuppressWarnings("unchecked")
+       public Class<? extends T> getWrappedClass() {
+               return (Class<? extends T>) classBeanWrapper.getWrappedClass();
+       }
+
+       protected void resetFeatureType() {
+               cachedFeatureType = null;
+               if (cachedAttributeList != null) {
+                       cachedAttributeList.clear();
+                       cachedAttributeList = null;
+               }
+       }
+
+       protected List<String> getCachedAttributeList() {
+               if (cachedAttributeList == null)
+                       throw new SlcException(
+                                       "Cached attribute list not set: initialize the object properly before calling this method");
+               return cachedAttributeList;
+       }
+
+       public SimpleFeature buildFeature(T object) {
+               return buildFeature(object, null);
+       }
+
+       public SimpleFeature buildFeature(Object object, String id) {
+               if (!((Class<?>) classBeanWrapper.getWrappedClass())
+                               .isAssignableFrom(object.getClass())) {
+                       throw new SlcException("Object type " + object.getClass()
+                                       + " not compatible with wrapped class "
+                                       + classBeanWrapper.getWrappedClass());
+               }
+
+               BeanWrapper instanceWrapper = new BeanWrapperImpl(object);
+               SimpleFeatureType type = getFeatureType();
+               SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
+               for (String attr : getCachedAttributeList()) {
+                       featureBuilder.add(instanceWrapper.getPropertyValue(attr));
+               }
+
+               return featureBuilder.buildFeature(id);
+       }
+
+       protected BeanWrapper getClassBeanWrapper() {
+               return classBeanWrapper;
+       }
+
+       public Object getObject() throws Exception {
+               return getFeatureType();
+       }
+
+       public Class<?> getObjectType() {
+               return classBeanWrapper.getWrappedClass();
+       }
+
+       public boolean isSingleton() {
+               return true;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/FeatureTypes.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/FeatureTypes.java
new file mode 100644 (file)
index 0000000..1eb7d5e
--- /dev/null
@@ -0,0 +1,5 @@
+package org.argeo.slc.geotools;
+
+public interface FeatureTypes {
+
+}
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/GeoToolsUtils.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/GeoToolsUtils.java
new file mode 100644 (file)
index 0000000..cc82062
--- /dev/null
@@ -0,0 +1,23 @@
+package org.argeo.slc.geotools;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.geotools.data.FileDataStoreFactorySpi;
+import org.geotools.data.FileDataStoreFinder;
+
+public class GeoToolsUtils {
+       private final static Log log = LogFactory.getLog(GeoToolsUtils.class);
+
+       public static void debugAvailableDataStores() {
+               Iterator<FileDataStoreFactorySpi> ps = FileDataStoreFinder
+                               .getAvailableDataStores();
+               log.debug("Available datastores:");
+               while (ps.hasNext()) {
+                       log.debug(ps.next());
+               }
+
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/SimpleGisFieldViewer.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/SimpleGisFieldViewer.java
deleted file mode 100644 (file)
index 29832cf..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- *    GeoTools - The Open Source Java GIS Tookit
- *    http://geotools.org
- *
- *    (C) 2006-2008, Open Source Geospatial Foundation (OSGeo)
- *
- *    This file is hereby placed into the Public Domain. This means anyone is
- *    free to do whatever they wish with this file. Use it well and enjoy!
- */
-package org.argeo.slc.geotools;
-
-import java.awt.Color;
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.media.jai.JAI;
-import javax.swing.SwingUtilities;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.geotools.swing.VersatileZoomTool;
-import org.argeo.slc.jts.PositionProvider;
-import org.geotools.data.FileDataStoreFactorySpi;
-import org.geotools.data.FileDataStoreFinder;
-import org.geotools.data.WorldFileReader;
-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.gce.image.WorldImageFormat;
-import org.geotools.map.DefaultMapContext;
-import org.geotools.map.DefaultMapLayer;
-import org.geotools.map.MapContext;
-import org.geotools.map.MapLayer;
-import org.geotools.referencing.crs.DefaultGeographicCRS;
-import org.geotools.styling.RasterSymbolizer;
-import org.geotools.styling.SLD;
-import org.geotools.styling.Style;
-import org.geotools.styling.StyleBuilder;
-import org.geotools.swing.JMapFrame;
-import org.geotools.swing.JMapPane;
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-import com.vividsolutions.jts.geom.Point;
-
-/**
- * GeoTools Quickstart demo application. Prompts the user for a shapefile and
- * displays its contents on the screen in a map frame
- * 
- * @source $URL:
- *         http://svn.osgeo.org/geotools/trunk/demo/example/src/main/java/org
- *         /geotools/demo/Quickstart.java $
- */
-public class SimpleGisFieldViewer implements Runnable {
-       private final static Log log = LogFactory
-                       .getLog(SimpleGisFieldViewer.class);
-
-       private PositionProvider positionProvider;
-
-       private ClassLoader jaiImageIoClassLoader;
-
-       public static void main(String[] args) throws Exception {
-               new SimpleGisFieldViewer().run();
-       }
-
-       public void run() {
-               Iterator<FileDataStoreFactorySpi> ps = FileDataStoreFinder
-                               .getAvailableDataStores();
-               log.debug("Available datastores:");
-               while (ps.hasNext()) {
-                       log.debug(ps.next());
-               }
-
-               // display a data store file chooser dialog for shapefiles
-               // File file = JFileDataStoreChooser.showOpenFile("shp", null);
-               // if (file == null) {
-               // return;
-               // }
-               File dir = new File(
-                               "/home/mbaudier/gis/projects/100122-EasternBalkans2010/data");
-
-               // FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
-               // FileDataStoreFinder
-               // .getDataStore(new File(dir, "countries-EuroMed-NEarth.shp"))
-               // .getFeatureSource();
-
-               // Create a map context and add our shapefile to it
-               MapContext mapContext = new DefaultMapContext();
-               mapContext.setTitle("Quickstart");
-
-               // Now display the map
-               // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-
-               final JMapFrame frame = new JMapFrame(mapContext);
-               frame.enableStatusBar(true);
-               frame.enableToolBar(false);
-               frame.enableLayerTable(false);
-               frame.initComponents();
-
-               frame.setSize(800, 600);
-
-               final JMapPane mapPane = frame.getMapPane();
-               mapPane.setCursorTool(new VersatileZoomTool());
-
-               SwingUtilities.invokeLater(new Runnable() {
-                       public void run() {
-                               frame.setVisible(true);
-                       }
-               });
-
-               // Create position type
-               SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
-               builder.setName("Position");
-               builder.setNamespaceURI("http://localhost/");
-               builder.setCRS(DefaultGeographicCRS.WGS84);
-
-               // add attributes in order
-               builder.add("Location", Point.class);
-               builder.add("ID", Integer.class);
-               builder.add("Name", String.class);
-
-               // build the type
-               final SimpleFeatureType POSITION = builder.buildFeatureType();
-
-               // PositionProvider positionProvider = new GpsBabelPositionProvider();
-
-               try {
-                       // FeatureSource<SimpleFeatureType, SimpleFeature> fs =
-                       // FileDataStoreFinder
-                       // .getDataStore(new File(dir, "countries-EuroMed-NEarth.shp"))
-                       // .getFeatureSource();
-
-                       // mapContext.addLayer(FileDataStoreFinder.getDataStore(
-                       // new File(dir, "cities-EuroMed-NEarth.shp")).getFeatureSource(),
-                       // null);
-
-                       // Raster
-                       if (jaiImageIoClassLoader != null) {
-                               Thread.currentThread().setContextClassLoader(
-                                               jaiImageIoClassLoader);
-                               JAI.getDefaultInstance().getOperationRegistry()
-                                               .registerServices(
-                                                               WorldFileReader.class.getClassLoader());
-//                             OperationDescriptor odesc = (OperationDescriptor) JAI
-//                                             .getDefaultInstance().getOperationRegistry()
-//                                             .getDescriptor("rendered", "ImageRead");
-                       }
-
-                       // Raster style
-                       StyleBuilder styleBuilder = new StyleBuilder();
-                       RasterSymbolizer rasterSymbolizer = styleBuilder
-                                       .createRasterSymbolizer();
-                       rasterSymbolizer.setGeometryPropertyName("geom");
-                       Style rasterStyle = styleBuilder.createStyle(rasterSymbolizer);
-                       WorldImageFormat worldImageFormat = new WorldImageFormat();
-
-                       File rasterDir = new File("/home/mbaudier/gis/data/100501-Poehali");
-                       mapContext.addLayer(worldImageFormat.getReader(
-                                       new File(rasterDir, "500k--l36-1--(1984).gif")).read(null),
-                                       rasterStyle);
-                       mapContext.addLayer(worldImageFormat.getReader(
-                                       new File(rasterDir, "500k--l35-4--(1978).gif")).read(null),
-                                       rasterStyle);
-                       mapContext.addLayer(worldImageFormat.getReader(
-                                       new File(rasterDir, "500k--l35-2--(1980).gif")).read(null),
-                                       rasterStyle);
-                       mapContext.addLayer(worldImageFormat.getReader(
-                                       new File(rasterDir, "100k--l36-050--(1982).gif")).read(null),
-                                       rasterStyle);
-
-                       mapContext.addLayer(FileDataStoreFinder.getDataStore(
-                                       new File(dir, "countries-EuroMed-NEarth.shp"))
-                                       .getFeatureSource(), null);
-                       // mapContext.addLayer(FileDataStoreFinder.getDataStore(
-                       // new File(dir, "highways-EastBalkan-OSM.shp"))
-                       // .getFeatureSource(), null);
-               } catch (IOException e1) {
-                       throw new SlcException("Cannot load sta stores", e1);
-               }
-
-               MapLayer mapLayer = null;
-               while (true) {
-                       SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
-                                       POSITION);
-
-                       // add the attributes
-                       featureBuilder.add(positionProvider.currentPosition());
-                       featureBuilder.add(12);
-                       featureBuilder.add("My Name");
-
-                       // build the feature
-                       SimpleFeature feature = featureBuilder.buildFeature("Flag.12");
-                       FeatureCollection<SimpleFeatureType, SimpleFeature> collection = new DefaultFeatureCollection(
-                                       "testCollection", POSITION);
-                       collection.add(feature);
-                       if (mapLayer != null)
-                               mapContext.removeLayer(mapLayer);
-                       Style style = SLD.createSimpleStyle(POSITION, Color.RED);
-                       mapLayer = new DefaultMapLayer(collection, style, "");
-                       mapContext.addLayer(mapLayer);
-                       // mapContext.addLayer(collection,null);
-
-                       try {
-                               Thread.sleep(1000);
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       }
-               }
-       }
-
-       public void setPositionProvider(PositionProvider positionProvider) {
-               this.positionProvider = positionProvider;
-       }
-
-       public void setJaiImageIoClassLoader(ClassLoader classLoader) {
-               this.jaiImageIoClassLoader = classLoader;
-       }
-
-}
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/GisFieldViewer.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/GisFieldViewer.java
new file mode 100644 (file)
index 0000000..a79cfb5
--- /dev/null
@@ -0,0 +1,213 @@
+package org.argeo.slc.geotools.swing;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import javax.media.jai.JAI;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.core.deploy.DefaultResourceSet;
+import org.argeo.slc.core.deploy.ResourceSet;
+import org.argeo.slc.geotools.BeanFeatureTypeBuilder;
+import org.argeo.slc.gis.model.Position;
+import org.argeo.slc.jts.PositionProvider;
+import org.geotools.data.FileDataStoreFinder;
+import org.geotools.data.WorldFileReader;
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.gce.image.WorldImageFormat;
+import org.geotools.map.DefaultMapContext;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.MapContext;
+import org.geotools.map.MapLayer;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.SLD;
+import org.geotools.styling.Style;
+import org.geotools.styling.StyleBuilder;
+import org.geotools.swing.JMapFrame;
+import org.geotools.swing.JMapPane;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+
+/**
+ * GeoTools Quickstart demo application. Prompts the user for a shapefile and
+ * displays its contents on the screen in a map frame
+ * 
+ * @source $URL:
+ *         http://svn.osgeo.org/geotools/trunk/demo/example/src/main/java/org
+ *         /geotools/demo/Quickstart.java $
+ */
+public class GisFieldViewer implements InitializingBean {
+       private final static Log log = LogFactory.getLog(GisFieldViewer.class);
+
+       protected final static BeanFeatureTypeBuilder<Position> POSITION = new BeanFeatureTypeBuilder<Position>(
+                       Position.class);
+
+       private DateFormat fieldPositionDateFormat = new SimpleDateFormat(
+                       "yyyyMMdd-HHmmss");
+
+       private PositionProvider positionProvider;
+
+       private ClassLoader jaiImageIoClassLoader;
+
+       private ResourceSet vectors = new DefaultResourceSet();
+       private ResourceSet rasters = new DefaultResourceSet();
+
+       private JMapPane mapPane;
+
+       /** in s */
+       private Integer positionRefreshPeriod = 10;
+
+       public static void main(String[] args) throws Exception {
+               new GisFieldViewer().afterPropertiesSet();
+       }
+
+       public void afterPropertiesSet() {
+
+               // Create map context
+               MapContext mapContext = new DefaultMapContext();
+               mapContext.setTitle("GIS Field Viewer");
+
+               // Now display the map
+               // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+               final JMapFrame frame = new JMapFrame(mapContext);
+               frame.enableStatusBar(true);
+               frame.enableToolBar(false);
+               frame.enableLayerTable(true);
+               frame.initComponents();
+               frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+
+               frame.setSize(800, 600);
+
+               mapPane = frame.getMapPane();
+               mapPane.setCursorTool(new VersatileZoomTool());
+
+               SwingUtilities.invokeLater(new Runnable() {
+                       public void run() {
+                               frame.setVisible(true);
+                       }
+               });
+
+               // Rasters
+               prepareJaiForRasters();
+               StyleBuilder styleBuilder = new StyleBuilder();
+               RasterSymbolizer rs = styleBuilder.createRasterSymbolizer();
+               rs.setGeometryPropertyName("geom");
+               Style rasterStyle = styleBuilder.createStyle(rs);
+               WorldImageFormat worldImageFormat = new WorldImageFormat();
+
+               for (Resource raster : rasters.listResources().values()) {
+                       try {
+                               mapContext.addLayer(worldImageFormat.getReader(raster.getURL())
+                                               .read(null), rasterStyle);
+                       } catch (Exception e) {
+                               log.error("Could not load raster " + raster + ": " + e);
+                               if (log.isTraceEnabled())
+                                       log.trace("Stack", e);
+                       }
+               }
+
+               // Vectors
+               for (Resource vector : vectors.listResources().values()) {
+                       try {
+                               mapContext.addLayer(FileDataStoreFinder.getDataStore(
+                                               vector.getURL()).getFeatureSource(), null);
+                       } catch (Exception e) {
+                               log.error("Could not load vector " + vector + ": " + e);
+                               if (log.isTraceEnabled())
+                                       log.trace("Stack", e);
+                       }
+               }
+
+               new Thread(new PositionUpdater()).start();
+       }
+
+       private void prepareJaiForRasters() {
+               if (jaiImageIoClassLoader != null) {
+                       Thread.currentThread().setContextClassLoader(jaiImageIoClassLoader);
+                       try {
+                               JAI.getDefaultInstance().getOperationRegistry()
+                                               .registerServices(
+                                                               WorldFileReader.class.getClassLoader());
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+                       // OperationDescriptor odesc = (OperationDescriptor) JAI
+                       // .getDefaultInstance().getOperationRegistry()
+                       // .getDescriptor("rendered", "ImageRead");
+               }
+       }
+
+       public void setPositionProvider(PositionProvider positionProvider) {
+               this.positionProvider = positionProvider;
+       }
+
+       public void setJaiImageIoClassLoader(ClassLoader classLoader) {
+               this.jaiImageIoClassLoader = classLoader;
+       }
+
+       public void setVectors(ResourceSet vectors) {
+               this.vectors = vectors;
+       }
+
+       public void setRasters(ResourceSet rasters) {
+               this.rasters = rasters;
+       }
+
+       private class PositionUpdater implements Runnable {
+
+               public void run() {
+                       MapLayer mapLayer = null;
+                       while (true) {
+                               Position currentPosition = positionProvider.currentPosition();
+
+                               if (mapPane.getDisplayArea().contains(
+                                               currentPosition.getLocation().getCoordinate())) {
+                                       SimpleFeature feature = POSITION
+                                                       .buildFeature(currentPosition);
+                                       FeatureCollection<SimpleFeatureType, SimpleFeature> collection = new DefaultFeatureCollection(
+                                                       "Field Position "
+                                                                       + fieldPositionDateFormat
+                                                                                       .format(currentPosition
+                                                                                                       .getTimestamp()), POSITION
+                                                                       .getFeatureType());
+                                       collection.add(feature);
+                                       if (mapLayer != null)
+                                               mapPane.getMapContext().removeLayer(mapLayer);
+                                       Style style = SLD.createSimpleStyle(POSITION
+                                                       .getFeatureType(), Color.RED);
+                                       mapLayer = new DefaultMapLayer(collection, style, "");
+                                       mapPane.getMapContext().addLayer(mapLayer);
+                               }
+                               try {
+                                       Thread.sleep(positionRefreshPeriod * 1000);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+               }
+       }
+}
+
+// File rasterDir = new
+// File("/home/mbaudier/gis/data/100501-Poehali");
+// mapContext.addLayer(worldImageFormat.getReader(
+// new File(rasterDir, "500k--l36-1--(1984).gif")).read(null),
+// rasterStyle);
+// mapContext.addLayer(worldImageFormat.getReader(
+// new File(rasterDir, "500k--l35-4--(1978).gif")).read(null),
+// rasterStyle);
+// mapContext.addLayer(worldImageFormat.getReader(
+// new File(rasterDir, "500k--l35-2--(1980).gif")).read(null),
+// rasterStyle);
+// mapContext.addLayer(worldImageFormat.getReader(
+// new File(rasterDir, "100k--l36-050--(1982).gif"))
+// .read(null), rasterStyle);
+
diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gis/model/Position.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gis/model/Position.java
new file mode 100644 (file)
index 0000000..7cc0693
--- /dev/null
@@ -0,0 +1,50 @@
+package org.argeo.slc.gis.model;
+
+import java.util.Date;
+
+import com.vividsolutions.jts.geom.Point;
+
+public class Position {
+       private Point location;
+       private Date timestamp;
+       private String comment;
+
+       public Position() {
+       }
+
+       public Position(Point location) {
+               this.location = location;
+               this.timestamp = new Date();
+       }
+
+       public Position(Point location, Date timestamp, String comment) {
+               this.location = location;
+               this.timestamp = timestamp;
+               this.comment = comment;
+       }
+
+       public Point getLocation() {
+               return location;
+       }
+
+       public void setLocation(Point location) {
+               this.location = location;
+       }
+
+       public Date getTimestamp() {
+               return timestamp;
+       }
+
+       public void setTimestamp(Date timestamp) {
+               this.timestamp = timestamp;
+       }
+
+       public String getComment() {
+               return comment;
+       }
+
+       public void setComment(String comment) {
+               this.comment = comment;
+       }
+
+}
index b77a71c5236c09a7356e982c526705f3e9ceea8f..83aca1d845dc770348765a22c4761309604367fb 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.slc.gpsbabel;
 
 import java.util.StringTokenizer;
 
+import org.argeo.slc.gis.model.Position;
 import org.argeo.slc.jts.PositionProvider;
 
 import com.vividsolutions.jts.geom.Coordinate;
@@ -20,7 +21,7 @@ public class GpsBabelPositionProvider implements PositionProvider {
                gpsBabelCall = new GpsBabelCall(inputFormat, inputFile, "csv", "-");
        }
 
-       public Point currentPosition() {
+       public Position currentPosition() {
                // lazy init
                if (gpsBabelCall == null)
                        init();
@@ -31,7 +32,7 @@ public class GpsBabelPositionProvider implements PositionProvider {
                Double longitude = Double.parseDouble(st.nextToken());
                Point position = geometryFactory.createPoint(new Coordinate(longitude,
                                latitude));
-               return position;
+               return new Position(position);
        }
 
        public void setInputFormat(String inputFormat) {
index caae525c91199aa109741827eb74cf091828408c..808b71c5e943c8d35229c2ff6482ee2efea64650 100644 (file)
@@ -1,7 +1,7 @@
 package org.argeo.slc.jts;
 
-import com.vividsolutions.jts.geom.Point;
+import org.argeo.slc.gis.model.Position;
 
 public interface PositionProvider {
-       public Point currentPosition();
+       public Position currentPosition();
 }