From: Mathieu Baudier Date: Fri, 7 May 2010 19:20:56 +0000 (+0000) Subject: Improve GIS support X-Git-Tag: argeo-slc-2.1.7~1301 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d3a5063833293cf77e680aa856dc28533414f5c4;p=gpl%2Fargeo-slc.git Improve GIS support git-svn-id: https://svn.argeo.org/slc/trunk@3573 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/demo/slc_gis_position.properties b/demo/slc_gis_position.properties new file mode 100644 index 000000000..559f5c3e7 --- /dev/null +++ b/demo/slc_gis_position.properties @@ -0,0 +1,4 @@ +argeo.osgi.start=\ +org.springframework.osgi.extender,\ +org.argeo.slc.gis.position.gpsbabel,\ +org.argeo.slc.gis.position.ui diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/.project b/modules/gis/org.argeo.slc.gis.position.gpsbabel/.project new file mode 100644 index 000000000..8ea04f80c --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/.project @@ -0,0 +1,22 @@ + + + org.argeo.slc.gis.position.gpsbabel + + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + + diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/.settings/org.eclipse.pde.core.prefs b/modules/gis/org.argeo.slc.gis.position.gpsbabel/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..c3f23293b --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Fri May 07 11:03:14 CEST 2010 +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/MANIFEST.MF b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/MANIFEST.MF new file mode 100644 index 000000000..15780388c --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SLC GIS Position GpsBabel +Bundle-SymbolicName: org.argeo.slc.gis.position.gpsbabel +Bundle-Version: 1.0.0.qualifier +Import-Package: org.argeo.slc.gpsbabel;version="0.12.2.SNAPSHOT-r3562", + org.argeo.slc.jts;version="0.12.2.SNAPSHOT-r3562" diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel-osgi.xml b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel-osgi.xml new file mode 100644 index 000000000..40b7d8639 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel-osgi.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel.xml b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel.xml new file mode 100644 index 000000000..4ef2af7e8 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/META-INF/spring/gpsbabel.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/modules/gis/org.argeo.slc.gis.position.gpsbabel/build.properties b/modules/gis/org.argeo.slc.gis.position.gpsbabel/build.properties new file mode 100644 index 000000000..5f22cdd44 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.gpsbabel/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/modules/gis/org.argeo.slc.gis.position.ui/.project b/modules/gis/org.argeo.slc.gis.position.ui/.project new file mode 100644 index 000000000..19e593ffb --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/.project @@ -0,0 +1,22 @@ + + + org.argeo.slc.gis.position.ui + + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + + diff --git a/modules/gis/org.argeo.slc.gis.position.ui/.settings/org.eclipse.pde.core.prefs b/modules/gis/org.argeo.slc.gis.position.ui/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..3ef6632e7 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Fri May 07 16:28:04 CEST 2010 +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false 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 new file mode 100644 index 000000000..c911e9df6 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +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", + 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/registryFile.jai b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/registryFile.jai new file mode 100644 index 000000000..76e43bb4c --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/registryFile.jai @@ -0,0 +1,225 @@ +# +# The registry file for Geotools Grid Coverage implementation. This file should be automatically +# parsed by JAI under initialization. If it is not, then Registry.registerServices(...) can parse +# it. This may happen if this file is unreachable from the JAI class loader. +# +# If this file is updated, remember to update Registry.registerServices(...) accordingly. +# +# Version: $Id: registryFile.jai 34781 2010-01-13 11:56:07Z simonegiannecchini $ +# +################################################################################################## +# +# Each line can be in one of the formats described below. Space or tab characters separate +# keywords in each line. The comment character is '#'; on each line all characters following +# the first comment character are ignored. The file must be encoded in UTF-8. +# +# 1. To register descriptors : +# +# descriptor +# +# 2. To register factory objects under a product against a specific mode : +# +# +# +# The is (only) used later on in this file to set preferences +# between factory objects, if wanted. +# +################################################################################################## +# +# Image operation descriptors : +# +descriptor org.geotools.image.jai.CombineDescriptor +descriptor org.geotools.image.jai.HysteresisDescriptor +descriptor org.geotools.image.jai.NodataFilterDescriptor +descriptor org.geotools.image.palette.ColorReductionDescriptor +descriptor org.geotools.image.palette.ColorInversionDescriptor + + +# +# "rendered" factory objects +# +rendered org.geotools.image.jai.CombineCRIF org.geotools org.geotools.Combine Combine +rendered org.geotools.image.jai.HysteresisCRIF org.geotools org.geotools.Hysteresis Hysteresis +rendered org.geotools.image.jai.NodataFilterCRIF org.geotools org.geotools.NodataFilter NodataFilter +rendered org.geotools.image.palette.ColorReductionCRIF org.geotools org.geotools.ColorReduction ColorReduction +rendered org.geotools.image.palette.ColorInversionCRIF org.geotools org.geotools.ColorInversion ColorInversion +# +# The registry file for Geotools Grid Coverage implementation. This file should be automatically +# parsed by JAI under initialization. If it is not, then Registry.registerServices(...) can parse +# it. This may happen if this file is unreachable from the JAI class loader. +# +# If this file is updated, remember to update Registry.registerServices(...) accordingly. +# +# Version: $Id: registryFile.jai 34781 2010-01-13 11:56:07Z simonegiannecchini $ +# +################################################################################################## +# +# Each line can be in one of the formats described below. Space or tab characters separate +# keywords in each line. The comment character is '#'; on each line all characters following +# the first comment character are ignored. The file must be encoded in UTF-8. +# +# 1. To register descriptors : +# +# descriptor +# +# 2. To register factory objects under a product against a specific mode : +# +# +# +# The is (only) used later on in this file to set preferences +# between factory objects, if wanted. +# +################################################################################################## +# +# Image operation descriptors : +# +descriptor org.geotools.image.jai.CombineDescriptor +descriptor org.geotools.image.jai.HysteresisDescriptor +descriptor org.geotools.image.jai.NodataFilterDescriptor +descriptor org.geotools.image.palette.ColorReductionDescriptor +descriptor org.geotools.image.palette.ColorInversionDescriptor + + +# +# "rendered" factory objects +# +rendered org.geotools.image.jai.CombineCRIF org.geotools org.geotools.Combine Combine +rendered org.geotools.image.jai.HysteresisCRIF org.geotools org.geotools.Hysteresis Hysteresis +rendered org.geotools.image.jai.NodataFilterCRIF org.geotools org.geotools.NodataFilter NodataFilter +rendered org.geotools.image.palette.ColorReductionCRIF org.geotools org.geotools.ColorReduction ColorReduction +rendered org.geotools.image.palette.ColorInversionCRIF org.geotools org.geotools.ColorInversion ColorInversion +# +# The registry file for Geotools Grid Coverage implementation. This file should be automatically +# parsed by JAI under initialization. If it is not, then Registry.registerServices(...) can parse +# it. This may happen if this file is unreachable from the JAI class loader. +# +# If this file is updated, remember to update Registry.registerServices(...) accordingly. +# +# Version: $Id: registryFile.jai 34781 2010-01-13 11:56:07Z simonegiannecchini $ +# +################################################################################################## +# +# Each line can be in one of the formats described below. Space or tab characters separate +# keywords in each line. The comment character is '#'; on each line all characters following +# the first comment character are ignored. The file must be encoded in UTF-8. +# +# 1. To register descriptors : +# +# descriptor +# +# 2. To register factory objects under a product against a specific mode : +# +# +# +# The is (only) used later on in this file to set preferences +# between factory objects, if wanted. +# +################################################################################################## +# +# Image operation descriptors : +# +descriptor org.geotools.image.jai.CombineDescriptor +descriptor org.geotools.image.jai.HysteresisDescriptor +descriptor org.geotools.image.jai.NodataFilterDescriptor +descriptor org.geotools.image.palette.ColorReductionDescriptor +descriptor org.geotools.image.palette.ColorInversionDescriptor + + +# +# "rendered" factory objects +# +rendered org.geotools.image.jai.CombineCRIF org.geotools org.geotools.Combine Combine +rendered org.geotools.image.jai.HysteresisCRIF org.geotools org.geotools.Hysteresis Hysteresis +rendered org.geotools.image.jai.NodataFilterCRIF org.geotools org.geotools.NodataFilter NodataFilter +rendered org.geotools.image.palette.ColorReductionCRIF org.geotools org.geotools.ColorReduction ColorReduction +rendered org.geotools.image.palette.ColorInversionCRIF org.geotools org.geotools.ColorInversion ColorInversion +# +# The registry file for Geotools Grid Coverage implementation. This file should be automatically +# parsed by JAI under initialization. If it is not, then Registry.registerServices(...) can parse +# it. This may happen if this file is unreachable from the JAI class loader. +# +# If this file is updated, remember to update Registry.registerServices(...) accordingly. +# +# Version: $Id: registryFile.jai 34781 2010-01-13 11:56:07Z simonegiannecchini $ +# +################################################################################################## +# +# Each line can be in one of the formats described below. Space or tab characters separate +# keywords in each line. The comment character is '#'; on each line all characters following +# the first comment character are ignored. The file must be encoded in UTF-8. +# +# 1. To register descriptors : +# +# descriptor +# +# 2. To register factory objects under a product against a specific mode : +# +# +# +# The is (only) used later on in this file to set preferences +# between factory objects, if wanted. +# +################################################################################################## +# +# Image operation descriptors : +# +descriptor org.geotools.image.jai.CombineDescriptor +descriptor org.geotools.image.jai.HysteresisDescriptor +descriptor org.geotools.image.jai.NodataFilterDescriptor +descriptor org.geotools.image.palette.ColorReductionDescriptor +descriptor org.geotools.image.palette.ColorInversionDescriptor + + +# +# "rendered" factory objects +# +rendered org.geotools.image.jai.CombineCRIF org.geotools org.geotools.Combine Combine +rendered org.geotools.image.jai.HysteresisCRIF org.geotools org.geotools.Hysteresis Hysteresis +rendered org.geotools.image.jai.NodataFilterCRIF org.geotools org.geotools.NodataFilter NodataFilter +rendered org.geotools.image.palette.ColorReductionCRIF org.geotools org.geotools.ColorReduction ColorReduction +rendered org.geotools.image.palette.ColorInversionCRIF org.geotools org.geotools.ColorInversion ColorInversion +# +# The registry file for Geotools Grid Coverage implementation. This file should be automatically +# parsed by JAI under initialization. If it is not, then Registry.registerServices(...) can parse +# it. This may happen if this file is unreachable from the JAI class loader. +# +# If this file is updated, remember to update Registry.registerServices(...) accordingly. +# +# Version: $Id: registryFile.jai 34781 2010-01-13 11:56:07Z simonegiannecchini $ +# +################################################################################################## +# +# Each line can be in one of the formats described below. Space or tab characters separate +# keywords in each line. The comment character is '#'; on each line all characters following +# the first comment character are ignored. The file must be encoded in UTF-8. +# +# 1. To register descriptors : +# +# descriptor +# +# 2. To register factory objects under a product against a specific mode : +# +# +# +# The is (only) used later on in this file to set preferences +# between factory objects, if wanted. +# +################################################################################################## +# +# Image operation descriptors : +# +descriptor org.geotools.image.jai.CombineDescriptor +descriptor org.geotools.image.jai.HysteresisDescriptor +descriptor org.geotools.image.jai.NodataFilterDescriptor +descriptor org.geotools.image.palette.ColorReductionDescriptor +descriptor org.geotools.image.palette.ColorInversionDescriptor + + +# +# "rendered" factory objects +# +rendered org.geotools.image.jai.CombineCRIF org.geotools org.geotools.Combine Combine +rendered org.geotools.image.jai.HysteresisCRIF org.geotools org.geotools.Hysteresis Hysteresis +rendered org.geotools.image.jai.NodataFilterCRIF org.geotools org.geotools.NodataFilter NodataFilter +rendered org.geotools.image.palette.ColorReductionCRIF org.geotools org.geotools.ColorReduction ColorReduction +rendered org.geotools.image.palette.ColorInversionCRIF org.geotools org.geotools.ColorInversion ColorInversion 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 new file mode 100644 index 000000000..c8691ff32 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui-osgi.xml @@ -0,0 +1,13 @@ + + + + + + + + \ 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 new file mode 100644 index 000000000..195d9dc1e --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/META-INF/spring/ui.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/gis/org.argeo.slc.gis.position.ui/build.properties b/modules/gis/org.argeo.slc.gis.position.ui/build.properties new file mode 100644 index 000000000..5f22cdd44 --- /dev/null +++ b/modules/gis/org.argeo.slc.gis.position.ui/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/runtime/org.argeo.slc.support.gis/.settings/org.eclipse.jdt.core.prefs b/runtime/org.argeo.slc.support.gis/.settings/org.eclipse.jdt.core.prefs index 4e4b533ef..d91f61990 100644 --- a/runtime/org.argeo.slc.support.gis/.settings/org.eclipse.jdt.core.prefs +++ b/runtime/org.argeo.slc.support.gis/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,12 @@ -#Thu May 06 12:24:28 CEST 2010 +#Fri May 07 21:03:36 CEST 2010 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.5 diff --git a/runtime/org.argeo.slc.support.gis/build.properties b/runtime/org.argeo.slc.support.gis/build.properties index 73ed796e9..8c835be67 100644 --- a/runtime/org.argeo.slc.support.gis/build.properties +++ b/runtime/org.argeo.slc.support.gis/build.properties @@ -11,4 +11,7 @@ additional.bundles = com.springsource.slf4j.api,\ org.argeo.dep.osgi.jsr275,\ org.argeo.dep.osgi.java3d,\ org.argeo.dep.osgi.jts,\ - com.springsource.org.apache.commons.beanutils + com.springsource.org.apache.commons.beanutils,\ + com.springsource.javax.media.jai.codec,\ + com.springsource.javax.media.jai.core,\ + org.argeo.dep.osgi.jai.imageio diff --git a/runtime/org.argeo.slc.support.gis/pom.xml b/runtime/org.argeo.slc.support.gis/pom.xml index 8a5b14c5a..c689f2829 100644 --- a/runtime/org.argeo.slc.support.gis/pom.xml +++ b/runtime/org.argeo.slc.support.gis/pom.xml @@ -84,6 +84,20 @@ org.apache.commons com.springsource.org.apache.commons.beanutils + + + javax.media.jai + com.springsource.javax.media.jai.core + + + javax.media.jai + com.springsource.javax.media.jai.codec + + + org.argeo.dep.osgi + org.argeo.dep.osgi.jai.imageio + + diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/Quickstart.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/Quickstart.java deleted file mode 100644 index 48ff7d003..000000000 --- a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/Quickstart.java +++ /dev/null @@ -1,194 +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.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.io.File; -import java.util.Iterator; - -import javax.swing.SwingUtilities; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.gpsbabel.GpsBabelPositionProvider; -import org.argeo.slc.jts.PositionProvider; -import org.geotools.data.FileDataStoreFactorySpi; -import org.geotools.data.FileDataStoreFinder; -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.jts.ReferencedEnvelope; -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.SLD; -import org.geotools.styling.Style; -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 Quickstart { - private final static Log log = LogFactory.getLog(Quickstart.class); - - /** - * GeoTools Quickstart demo application. Prompts the user for a shapefile - * and displays its contents on the screen in a map frame - */ - public static void main(String[] args) throws Exception { - 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(true); - frame.enableLayerTable(true); - frame.initComponents(); - - frame.setSize(800, 600); - - final double clickToZoom = 0.1; // 1 wheel click is 10% zoom - final JMapPane mapPane = frame.getMapPane(); - mapPane.addMouseWheelListener(new MouseWheelListener() { - - public void mouseWheelMoved(MouseWheelEvent ev) { - int clicks = ev.getWheelRotation(); - // -ve means wheel moved up, +ve means down - int sign = (clicks < 0 ? -1 : 1); - - ReferencedEnvelope env = mapPane.getDisplayArea(); - double width = env.getWidth(); - double delta = width * clickToZoom * sign; - - env.expandBy(delta); - mapPane.setDisplayArea(env); - mapPane.repaint(); - } - }); - // mapPane.addMouseListener(new MapMouseAdapter() { - // // wheel event handler - // public void handleMouseWheelEvent(MouseWheelEvent ev) { - // int clicks = ev.getWheelRotation(); - // // -ve means wheel moved up, +ve means down - // int sign = (clicks < 0 ? -1 : 1); - // - // ReferencedEnvelope env = mapPane.getDisplayArea(); - // double width = env.getWidth(); - // double delta = width * clickToZoom * sign; - // - // env.expandBy(delta); - // mapPane.setDisplayArea(env); - // mapPane.repaint(); - // } - // }); - - 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(); - - // 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); - 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); - - 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); - - Thread.sleep(1000); - } - } - -} \ No newline at end of file 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 new file mode 100644 index 000000000..29832cff4 --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/SimpleGisFieldViewer.java @@ -0,0 +1,222 @@ +/* + * 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/WorldFileTest.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/WorldFileTest.java new file mode 100644 index 000000000..05e5e6b6f --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/WorldFileTest.java @@ -0,0 +1,21 @@ +package org.argeo.slc.geotools; + +import java.io.File; + +import org.geotools.coverage.grid.GridCoverage2D; +import org.geotools.gce.image.WorldImageFormat; +import org.geotools.gce.image.WorldImageReader; + +public class WorldFileTest { + + @SuppressWarnings("restriction") + public static void main(String[] args) throws Exception { + File dir = new File("/home/mbaudier/gis/data/100501-Poehali"); + WorldImageFormat worldImageFormat = new WorldImageFormat(); + WorldImageReader worldImageReader = worldImageFormat + .getReader(new File(dir, "500k--l36-1--(1984).gif")); + GridCoverage2D gridCoverage2D = worldImageReader.read(null); + gridCoverage2D.show(); + } + +} diff --git a/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/VersatileZoomTool.java b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/VersatileZoomTool.java new file mode 100644 index 000000000..862e0a82d --- /dev/null +++ b/runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/geotools/swing/VersatileZoomTool.java @@ -0,0 +1,247 @@ +package org.argeo.slc.geotools.swing; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.awt.geom.Point2D; + +import javax.swing.SwingUtilities; +import javax.swing.event.MouseInputAdapter; + +import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.Envelope2D; +import org.geotools.geometry.jts.ReferencedEnvelope; +import org.geotools.swing.JMapPane; +import org.geotools.swing.event.MapMouseEvent; +import org.geotools.swing.tool.AbstractZoomTool; + +public class VersatileZoomTool extends AbstractZoomTool { + // private Log log = LogFactory.getLog(VersatileZoomTool.class); + + // private static final ResourceBundle stringRes = ResourceBundle + // .getBundle("org/geotools/swing/Text"); + + // Cursors + private Cursor zoomInCursor; + private Cursor panCursor; + private Cursor defaultCursor; + + // Variable values + private Point2D startDragPos; + private Point panePos; + private boolean computingZoomBox; + private boolean panning; + + /** + * Constructor + */ + public VersatileZoomTool() { + // Toolkit tk = Toolkit.getDefaultToolkit(); + // zoomInCursor = tk.createCustomCursor(new ImageIcon(getClass() + // .getResource("/org/geotools/swing/icons/mActionZoomIn.png")) + // .getImage(), new Point(14, 9), stringRes + // .getString("tool_name_zoom_in")); + zoomInCursor = new Cursor(Cursor.SE_RESIZE_CURSOR); + // panCursor = tk.createCustomCursor(new + // ImageIcon(getClass().getResource( + // "/org/geotools/swing/icons/mActionPan.png")).getImage(), + // new Point(15, 15), stringRes.getString("tool_name_pan")); + panCursor = new Cursor(Cursor.HAND_CURSOR); + defaultCursor = new Cursor(Cursor.CROSSHAIR_CURSOR); + + startDragPos = new DirectPosition2D(); + computingZoomBox = false; + panning = false; + + } + + /** + * Zoom in by the currently set increment, with the map centred at the + * location (in world coords) of the mouse click + * + * @param e + * map mapPane mouse event + */ + @Override + public void onMouseClicked(MapMouseEvent e) { + centerMapToEvent(e); + } + + protected void centerMapToEvent(MapMouseEvent e) { + Rectangle paneArea = getMapPane().getVisibleRect(); + DirectPosition2D mapPos = e.getMapPosition(); + + double scale = getMapPane().getWorldToScreenTransform().getScaleX(); + // double newScale = scale * zoom; + // + DirectPosition2D corner = new DirectPosition2D(mapPos.getX() - 0.5d + * paneArea.getWidth() / scale, mapPos.getY() + 0.5d + * paneArea.getHeight() / scale); + + Envelope2D newMapArea = new Envelope2D(); + newMapArea.setFrameFromCenter(mapPos, corner); + getMapPane().setDisplayArea(newMapArea); + } + + /** + * Records the map position of the mouse event in case this button press is + * the beginning of a mouse drag + * + * @param ev + * the mouse event + */ + @Override + public void onMousePressed(MapMouseEvent ev) { + if (SwingUtilities.isLeftMouseButton(ev)) { + startDragPos = new DirectPosition2D(); + startDragPos.setLocation(ev.getMapPosition()); + } else if (SwingUtilities.isMiddleMouseButton(ev)) { + panePos = ev.getPoint(); + panning = true; + } + } + + /** + * Records that the mouse is being dragged + * + * @param ev + * the mouse event + */ + @Override + public void onMouseDragged(MapMouseEvent ev) { + if (SwingUtilities.isLeftMouseButton(ev)) { + computingZoomBox = true; + } else if (panning) { + Point pos = ev.getPoint(); + if (!pos.equals(panePos)) { + getMapPane().moveImage(pos.x - panePos.x, pos.y - panePos.y); + panePos = pos; + } + } + getMapPane().setCursor(getCursor()); + } + + /** + * If the mouse was dragged, determines the bounds of the box that the user + * defined and passes this to the mapPane's + * {@link org.geotools.swing.JMapPane#setDisplayArea(org.opengis.geometry.Envelope) } + * method + * + * @param ev + * the mouse event + */ + @Override + public void onMouseReleased(MapMouseEvent ev) { + if (computingZoomBox && !ev.getPoint().equals(startDragPos)) { + Envelope2D env = new Envelope2D(); + env.setFrameFromDiagonal(startDragPos, ev.getMapPosition()); + computingZoomBox = false; + getMapPane().setDisplayArea(env); + } else if (panning) { + panning = false; + getMapPane().repaint(); + } + getMapPane().setCursor(getCursor()); + } + + /** + * Get the mouse cursor for this tool + */ + @Override + public Cursor getCursor() { + if (computingZoomBox) + return zoomInCursor; + else if (panning) + return panCursor; + else + return defaultCursor; + } + + /** + * We use a custom drag box + */ + @Override + public boolean drawDragBox() { + return false; + } + + @Override + public void setMapPane(JMapPane pane) { + super.setMapPane(pane); + VariableDragBox dragBox = new VariableDragBox(); + getMapPane().addMouseListener(dragBox); + getMapPane().addMouseMotionListener(dragBox); + getMapPane().addMouseWheelListener(new MouseWheelListener() { + private double clickToZoom = 0.1; // 1 wheel click is 10% zoom + + public void mouseWheelMoved(MouseWheelEvent ev) { + int clicks = ev.getWheelRotation(); + // -ve means wheel moved up, +ve means down + int sign = (clicks < 0 ? -1 : 1); + + ReferencedEnvelope env = getMapPane().getDisplayArea(); + double width = env.getWidth(); + double delta = width * clickToZoom * sign; + + env.expandBy(delta); + getMapPane().setDisplayArea(env); + getMapPane().repaint(); + } + }); + } + + /** + * Custom drag box (hacked from JMapPane) so that we can change the behavior + * depending on whether we pan or zoom. + */ + private class VariableDragBox extends MouseInputAdapter { + + private Point startPos; + private Rectangle rect; + private boolean dragged; + + VariableDragBox() { + rect = new Rectangle(); + dragged = false; + } + + @Override + public void mousePressed(MouseEvent e) { + startPos = new Point(e.getPoint()); + } + + @Override + public void mouseDragged(MouseEvent e) { + if (computingZoomBox) { + Graphics2D g2D = (Graphics2D) getMapPane().getGraphics(); + g2D.setColor(Color.WHITE); + g2D.setXORMode(Color.RED); + if (dragged) { + g2D.drawRect(rect.x, rect.y, rect.width, rect.height); + } + + rect.setFrameFromDiagonal(startPos, e.getPoint()); + g2D.drawRect(rect.x, rect.y, rect.width, rect.height); + + dragged = true; + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (dragged) { + Graphics2D g2D = (Graphics2D) getMapPane().getGraphics(); + g2D.setColor(Color.WHITE); + g2D.setXORMode(Color.RED); + g2D.drawRect(rect.x, rect.y, rect.width, rect.height); + dragged = false; + } + } + } + +} 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 8e1a8f79c..b77a71c52 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 @@ -34,4 +34,12 @@ public class GpsBabelPositionProvider implements PositionProvider { return position; } + public void setInputFormat(String inputFormat) { + this.inputFormat = inputFormat; + } + + public void setInputFile(String inputFile) { + this.inputFile = inputFile; + } + }