X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.gis%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fgeotools%2FQuickstart.java;fp=runtime%2Forg.argeo.slc.support.gis%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fgeotools%2FQuickstart.java;h=48ff7d003e54970061b4b709bb4d26a5687cefcd;hb=e875b40fba70bb76fed1e2f3ff77c9adca1be1a4;hp=25c624490f9827f3320573edc16aaf5877368ea1;hpb=5ca81acf7afe421597fd3f99ba956d02c36fa43b;p=gpl%2Fargeo-slc.git 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 index 25c624490..48ff7d003 100644 --- 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 @@ -9,6 +9,7 @@ */ package org.argeo.slc.geotools; +import java.awt.Color; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.io.File; @@ -18,19 +19,29 @@ import javax.swing.SwingUtilities; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.geotools.data.FeatureSource; -import org.geotools.data.FileDataStore; +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.geotools.swing.event.MapMouseAdapter; 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 @@ -62,18 +73,19 @@ public class Quickstart { File dir = new File( "/home/mbaudier/gis/projects/100122-EasternBalkans2010/data"); - FeatureSource featureSource = FileDataStoreFinder - .getDataStore(new File(dir, "countries-EuroMed-NEarth.shp")) - .getFeatureSource(); + // FeatureSource featureSource = + // FileDataStoreFinder + // .getDataStore(new File(dir, "countries-EuroMed-NEarth.shp")) + // .getFeatureSource(); // Create a map context and add our shapefile to it - MapContext map = new DefaultMapContext(); - map.setTitle("Quickstart"); + MapContext mapContext = new DefaultMapContext(); + mapContext.setTitle("Quickstart"); // Now display the map // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - final JMapFrame frame = new JMapFrame(map); + final JMapFrame frame = new JMapFrame(mapContext); frame.enableStatusBar(true); frame.enableToolBar(true); frame.enableLayerTable(true); @@ -122,15 +134,61 @@ public class Quickstart { } }); - map.addLayer(FileDataStoreFinder.getDataStore( - new File(dir, "cities-EuroMed-NEarth.shp")).getFeatureSource(), - null); - map.addLayer(FileDataStoreFinder.getDataStore( + // 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); - map.addLayer(FileDataStoreFinder.getDataStore( - new File(dir, "highways-EastBalkan-OSM.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