From: Mathieu Baudier Date: Tue, 22 Feb 2011 23:10:42 +0000 (+0000) Subject: Improve GIS X-Git-Tag: argeo-slc-2.1.7~1018 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d3958405fbe58c656a9163aee14fc2a74a93bcba;p=gpl%2Fargeo-slc.git Improve GIS git-svn-id: https://svn.argeo.org/slc/trunk@4169 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.classpath b/eclipse/plugins/org.argeo.slc.ui.gis/.classpath new file mode 100644 index 000000000..92f19d2ff --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.project b/eclipse/plugins/org.argeo.slc.ui.gis/.project new file mode 100644 index 000000000..f0dfed9bd --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/.project @@ -0,0 +1,28 @@ + + + org.argeo.slc.client.gis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs b/eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..14c8f81cd --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Wed Oct 13 08:00:18 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.compliance=1.5 +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/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF new file mode 100644 index 000000000..31e527427 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gis +Bundle-SymbolicName: org.argeo.slc.client.gis; singleton:=true +Bundle-Version: 0.13.1.SNAPSHOT +Bundle-Activator: org.argeo.slc.client.gis.ClientGisActivator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.argeo.dep.osgi.jai.imageio;bundle-version="1.1.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Import-Package: com.vividsolutions.jts.geom;version="1.10.0", + org.apache.commons.logging;version="1.1.1", + org.argeo.eclipse.spring, + org.argeo.slc.geotools, + org.argeo.slc.geotools.data, + org.argeo.slc.geotools.swing, + org.argeo.slc.gis.model, + org.argeo.slc.jts, + org.geotools.data, + org.geotools.gce.image, + org.geotools.geometry, + org.geotools.map, + org.geotools.renderer, + org.geotools.renderer.lite, + org.geotools.styling, + org.geotools.swing, + org.geotools.swing.event, + org.geotools.swing.tool, + org.opengis.feature.simple, + org.opengis.geometry, + org.opengis.referencing.crs, + org.springframework.osgi.util;version="1.2.1" diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml new file mode 100644 index 000000000..69235e815 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml new file mode 100644 index 000000000..f395c7b21 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/build.properties b/eclipse/plugins/org.argeo.slc.ui.gis/build.properties new file mode 100644 index 000000000..89500559a --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/build.properties @@ -0,0 +1,6 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif b/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif new file mode 100644 index 000000000..34fb3c9d8 Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif differ diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml b/eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml new file mode 100644 index 000000000..b482a4d73 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java new file mode 100644 index 000000000..7c2d23563 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java @@ -0,0 +1,61 @@ +package org.argeo.slc.client.gis; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class ClientGisActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.argeo.slc.client.gis"; //$NON-NLS-1$ + + // The shared instance + private static ClientGisActivator plugin; + + /** + * The constructor + */ + public ClientGisActivator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static ClientGisActivator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java new file mode 100644 index 000000000..c9de6640e --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java @@ -0,0 +1,19 @@ +package org.argeo.slc.client.gis; + +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class GisPerspectiveFactory implements IPerspectiveFactory { + + public void createInitialLayout(IPageLayout layout) { + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(false); + layout.setFixed(false); + + IFolderLayout topLeft = layout.createFolder("topLeft", + IPageLayout.LEFT, 0.5f, editorArea); + topLeft.addView("org.argeo.slc.client.gis.mapView"); + } + +} diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java new file mode 100644 index 000000000..369798706 --- /dev/null +++ b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java @@ -0,0 +1,241 @@ +package org.argeo.slc.client.gis.views; + +import java.awt.Color; +import java.awt.Frame; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; + +import javax.swing.SwingUtilities; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.geotools.Backend; +import org.argeo.slc.geotools.DataDescriptor; +import org.argeo.slc.geotools.data.FeatureSourceDataDescriptor; +import org.argeo.slc.geotools.data.PostgisDataDescriptor; +import org.argeo.slc.geotools.data.WorldImageDataDescriptor; +import org.argeo.slc.geotools.swing.VersatileZoomTool; +import org.argeo.slc.gis.model.FieldPosition; +import org.argeo.slc.jts.PositionProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; +import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.Envelope2D; +import org.geotools.map.MapContext; +import org.geotools.renderer.lite.StreamingRenderer; +import org.geotools.styling.RasterSymbolizer; +import org.geotools.styling.Style; +import org.geotools.styling.StyleBuilder; +import org.geotools.swing.JMapPane; +import org.geotools.swing.event.MapPaneAdapter; +import org.geotools.swing.event.MapPaneEvent; + +import com.vividsolutions.jts.geom.Coordinate; + +public class GeoToolsMapView extends ViewPart { + public static final String ID = "org.argeo.slc.client.gis.views.GeoToolsMapView"; + private final static Log log = LogFactory.getLog(GeoToolsMapView.class); + + private Composite embedded; + + private PositionProvider positionProvider; + + private Backend backend; + + private MapContext mapContext; + private JMapPane mapPane; + + /** in s */ + private Integer positionRefreshPeriod = 1; + private FieldPosition currentPosition = null; + private Boolean positionProviderDisconnected = false; + private VersatileZoomTool versatileZoomTool; + + public void createPartControl(Composite parent) { + embedded = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND); + Frame frame = SWT_AWT.new_Frame(embedded); + + mapPane = new JMapPane(new StreamingRenderer(), mapContext); + versatileZoomTool = new VersatileZoomTool(); + mapPane.setCursorTool(versatileZoomTool); + + mapPane.addMapPaneListener(new CustomMapPaneListener()); + + frame.add(mapPane); + + centerOnPosition(); + + for (DataDescriptor dd : backend.getAvailableData(null)) { + if (dd instanceof WorldImageDataDescriptor) { + StyleBuilder styleBuilder = new StyleBuilder(); + RasterSymbolizer rs = styleBuilder.createRasterSymbolizer(); + rs.setGeometryPropertyName("geom"); + Style rasterStyle = styleBuilder.createStyle(rs); + try { + mapContext.addLayer(backend.loadGridCoverage(dd), + rasterStyle); + } catch (Exception e) { + log.warn(e); + } + + } else if (dd instanceof FeatureSourceDataDescriptor) { + try { + mapContext.addLayer(backend.loadFeatureSource(dd), null); + } catch (Exception e) { + log.warn(e); + } + } else if (dd instanceof PostgisDataDescriptor) { + // DataStore dataStore = backend.loadDataStore(dd); + for (DataDescriptor dd2 : backend.getAvailableData(dd)) + mapContext.addLayer(backend.loadFeatureSource(dd2), null); + } + } + // GisFieldViewer gisFieldViewer = new GisFieldViewer(frame); + // gisFieldViewer.setPostGisDataStore(postGisDataStore); + // gisFieldViewer.setPositionProvider(positionProvider); + // gisFieldViewer.setJaiImageIoClassLoader(jaiImageIoClassLoader); + // gisFieldViewer.afterPropertiesSet(); + + new Thread(new PositionUpdater()).start(); + + } + + protected void receiveNewPosition(FieldPosition position) { + if (position != null && versatileZoomTool != null) { + positionProviderDisconnected = false; + currentPosition = position; + Point2D point2d = new DirectPosition2D(currentPosition + .getLocation().getCoordinate().x, currentPosition + .getLocation().getCoordinate().y); + versatileZoomTool.setFieldPosition(point2d); + drawPositionLocation(); + } else { + positionProviderDisconnected = true; + } + } + + protected void drawPositionLocation() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (currentPosition == null) + return; + + AffineTransform tr = getMapPane().getWorldToScreenTransform(); + DirectPosition2D geoCoords = new DirectPosition2D( + currentPosition.getLocation().getCoordinate().x, + currentPosition.getLocation().getCoordinate().y); + if (tr == null) + return; + tr.transform(geoCoords, geoCoords); + geoCoords.setCoordinateReferenceSystem(getMapPane() + .getMapContext().getCoordinateReferenceSystem()); + + final int halfRefSize = 3; + Rectangle rect = new Rectangle((int) Math.round(geoCoords + .getX() - halfRefSize), (int) Math.round(geoCoords + .getY() - halfRefSize), halfRefSize * 2 + 1, + halfRefSize * 2 + 1); + Graphics2D g2D = (Graphics2D) getMapPane().getGraphics(); + if (g2D == null) + return; + g2D.setColor(Color.WHITE); + if (positionProviderDisconnected) + g2D.setXORMode(Color.ORANGE); + else + g2D.setXORMode(Color.RED); + g2D.drawRect(rect.x, rect.y, rect.width, rect.height); + g2D.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, + rect.height + 2); + } + }); + } + + protected void centerOnPosition() { + if (currentPosition == null) + return; + Envelope2D env = new Envelope2D(); + final double increment = 1d; + Coordinate positionCoo = currentPosition.getLocation().getCoordinate(); + env.setFrameFromDiagonal(positionCoo.x - increment, positionCoo.y + - increment, positionCoo.x + increment, positionCoo.y + + increment); + getMapPane().setDisplayArea(env); + + } + + public void setFocus() { + if (embedded != null) + embedded.setFocus(); + } + + protected JMapPane getMapPane() { + return mapPane; + } + + public void setPositionProvider(PositionProvider positionProvider) { + this.positionProvider = positionProvider; + } + + public void setBackend(Backend backend) { + this.backend = backend; + } + + public void setMapContext(MapContext mapContext) { + this.mapContext = mapContext; + } + + private class CustomMapPaneListener extends MapPaneAdapter { + + @Override + public void onRenderingStopped(MapPaneEvent ev) { + drawPositionLocation(); + } + + @Override + public void onDisplayAreaChanged(MapPaneEvent ev) { + drawPositionLocation(); + } + + @Override + public void onRenderingProgress(MapPaneEvent ev) { + drawPositionLocation(); + } + + @Override + public void onRenderingStarted(MapPaneEvent ev) { + drawPositionLocation(); + } + + @Override + public void onResized(MapPaneEvent ev) { + drawPositionLocation(); + } + + } + + private class PositionUpdater implements Runnable { + + public void run() { + while (true) { + FieldPosition currentPosition = positionProvider + .currentPosition(); + + receiveNewPosition(currentPosition); + + if (currentPosition != null) { + } + + try { + Thread.sleep(positionRefreshPeriod * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + +} \ No newline at end of file