From: Mathieu Baudier Date: Sat, 8 May 2010 14:59:10 +0000 (+0000) Subject: Improve SLC GIS Position X-Git-Tag: argeo-slc-2.1.7~1300 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=77c154bbed62738179f6c710a7734a008a8d9798;hp=d3a5063833293cf77e680aa856dc28533414f5c4;p=gpl%2Fargeo-slc.git Improve SLC GIS Position git-svn-id: https://svn.argeo.org/slc/trunk@3574 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/demo/pom.xml b/demo/pom.xml index eecd25513..37ab5507c 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -37,15 +37,8 @@ maven-argeo-osgi-plugin target/exec/server + server.properties - - 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 - ${basedir}/site;in=*;ex=pom.xml;ex=target, ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*, @@ -78,14 +71,8 @@ maven-argeo-osgi-plugin target/exec/server + server_jcr.properties - - org.springframework.osgi.extender, - org.argeo.server.ads.server, - org.argeo.slc.server.jcr, - org.argeo.slc.server.main, - org.argeo.slc.ria - ${basedir}/site;in=*;ex=pom.xml;ex=target, ${basedir}/../modules/server;in=*;ex=pom.xml;ex=target;ex=.*, @@ -118,13 +105,8 @@ maven-argeo-osgi-plugin target/exec/agent + agent.properties - - org.springframework.osgi.extender, - org.argeo.slc.support.equinox, - org.argeo.slc.agent, - org.argeo.slc.agent.jms - ${basedir}/site;in=*;ex=pom.xml;ex=target, ${basedir}/../modules/agent;in=*;ex=pom.xml;ex=target @@ -142,6 +124,34 @@ + + slc_gis_position + + + + org.argeo.maven.plugins + maven-argeo-osgi-plugin + + target/exec/agent + slc_gis_position.properties + + + ${basedir}/site;in=*;ex=pom.xml;ex=target, + ${basedir}/../modules/gis;in=*;ex=pom.xml;ex=target + + + + + + + + + org.argeo.slc.dep + org.argeo.slc.dep.sdk + ${project.version} + + + detached diff --git a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF index c911e9df6..a6c59e2d3 100644 --- a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF @@ -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" diff --git a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml index c8691ff32..9c6e89b4b 100644 --- a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml @@ -6,8 +6,8 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + \ No newline at end of file diff --git a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml index 195d9dc1e..425fcb3e3 100644 --- a/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml @@ -1,22 +1,46 @@ + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd + "> - + - - - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.gis/build.properties b/runtime/org.argeo.slc.support.gis/build.properties index 8c835be67..f667d5dd5 100644 --- a/runtime/org.argeo.slc.support.gis/build.properties +++ b/runtime/org.argeo.slc.support.gis/build.properties @@ -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 index 000000000..a67dc76f1 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/BeanFeatureTypeBuilder.java @@ -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 implements FactoryBean { + private final BeanWrapper classBeanWrapper; + + private SimpleFeatureType cachedFeatureType; + private List cachedAttributeList; + + public BeanFeatureTypeBuilder(Class clss) { + this.classBeanWrapper = new BeanWrapperImpl(clss); + cachedFeatureType = doBuildFeatureType(); + } + + protected SimpleFeatureType doBuildFeatureType() { + SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); + + builder + .setName(getClassBeanWrapper().getWrappedClass() + .getSimpleName()); + + cachedAttributeList = new ArrayList(); + 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 getWrappedClass() { + return (Class) classBeanWrapper.getWrappedClass(); + } + + protected void resetFeatureType() { + cachedFeatureType = null; + if (cachedAttributeList != null) { + cachedAttributeList.clear(); + cachedAttributeList = null; + } + } + + protected List 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 index 000000000..1eb7d5eb6 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/FeatureTypes.java @@ -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 index 000000000..cc82062c3 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/GeoToolsUtils.java @@ -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 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 index 29832cff4..000000000 --- a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/SimpleGisFieldViewer.java +++ /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 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 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 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 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 index 000000000..a79cfb5f9 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/GisFieldViewer.java @@ -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 = new BeanFeatureTypeBuilder( + 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 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 index 000000000..7cc069329 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gis/model/Position.java @@ -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; + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelPositionProvider.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelPositionProvider.java index b77a71c52..83aca1d84 100644 --- a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelPositionProvider.java +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/gpsbabel/GpsBabelPositionProvider.java @@ -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) { diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/jts/PositionProvider.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/jts/PositionProvider.java index caae525c9..808b71c5e 100644 --- a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/jts/PositionProvider.java +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/jts/PositionProvider.java @@ -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(); }