|
|
|
Oliver Gottwald
|
Hi, I'm new to giotools and worked my way through a number of the example sets. I have the FeatureCollection coordinates defined but now I'm lost on how to define the FeatureSource(i think) and display the coordinates via swing. Any help on this would be greatly appreciated. Oliver The following is my main: public static void main(String[] args) throws Exception { final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point,name:String"); FeatureCollection collection = FeatureCollections.newCollection(); double lon[] = {123.31, 0}; double lat[] = {48.4, 52}; String nam[] = { "Point1", "Point2", "Point3" }; GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null); for(int i=0;i<=1;i++){ double longitude = lon[i]; double latitude = lat[i]; String name = nam[i]; Point point = factory.createPoint( new Coordinate(longitude,latitude)); SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new Object[]{point, name}, null ); collection.add( feature ); } FeatureIterator iterator = collection.features(); try { while (iterator.hasNext()) { SimpleFeature feature = (SimpleFeature)iterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate[] coords = geometry.getCoordinates(); for( int i = 0; i < coords.length; i++ ) { System.out.println(coords[i]); } } } finally { if( iterator != null ){ // YOU MUST CLOSE THE ITERATOR! iterator.close(); } } //Display FeatureCollection ?? } ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
Jody Garnett-2
|
Some javascript/style in this post has been disabled (why?)
There is a DataUtilities method to make you a feature source from a feature collection; details in the user guide.Jody On 21/10/2009, at 5:35 AM, Oliver Gottwald wrote:
------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
Oliver Gottwald
|
In reply to this post
by Oliver Gottwald
jody,
Thank you for the quick response. I added the line: FeatureSource featureSource = DataUtilities.source(collection); under: //Display FeatureCollection ?? Should I use something like the below to actually display the featureSource or is there a different/better approach? MapContext map = new DefaultMapContext(); map.setTitle("Feature selection tool example"); Style style = createDefaultStyle(); map.addLayer(featureSource, style); mapFrame = new JMapFrame(map); mapFrame.setSize(600, 600); mapFrame.setVisible(true); I think my version of gt-main may be off for the MapDisplayLab (pulled code from above). I get compiliation errors. Currently I'm using gt-main-2.5.4.jar for the example. Do you know what the proper mavin dependency is? ======================================================================= There is a DataUtilities method to make you a feature source from a feature collection; details in the user guide. Jody On 21/10/2009, at 5:35 AM, Oliver Gottwald wrote:
------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
In reply to this post
by Oliver Gottwald
Hi Oliver,
In GeoTools 2.6.0, if you just want to display your in-memory feature collection you can do something like this... FeatureCollection<SimpleFeatureType, SimpleFeature> collection = ... MapContext map = new DefaultMapContext(); map.setTitle("My feature collection"); map.addLayer(collection, null); JMapFrame.showMap(map); These are the imports: import org.geotools.feature.FeatureCollection; import org.geotools.map.DefaultMapContext; import org.geotools.map.MapContext; import org.geotools.swing.JMapFrame; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; If you want to display your points with something other than the very basic default style you might want to look at the StyleLab example: http://geotools.org/examples/stylelab.html Hope that helps. Michael ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
Oliver Gottwald
|
In reply to this post
by Oliver Gottwald
Michael, Thank you for the code snipped. Last night I figured this out by also integrating a snipped from the QuickStart example which matches with your code snipped. I passed out before posting on the forum. I look forward to being an active member on this forum. Below is my working code and POM. package org.geotools.demo.example; import org.geotools.data.DataUtilities; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureCollections; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.geometry.jts.JTSFactoryFinder; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; import org.geotools.feature.FeatureIterator; import com.vividsolutions.jts.geom.Geometry; import org.geotools.data.FeatureSource; import org.geotools.map.DefaultMapContext; import org.geotools.map.MapContext; import org.geotools.swing.JMapFrame; public class DisplayForcedShape { public static void main(String[] args) throws Exception { final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point,name:String"); // see createFeatureType(); FeatureCollection collection = FeatureCollections.newCollection(); double lon[] = {123.31, 0}; double lat[] = {48.4, 52}; String name[] = { "Point1", "Point2", "Point3" }; GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null); for(int i=0;i<=1;i++){ Point point = factory.createPoint( new Coordinate(lon[i],lat[i])); SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new Object[]{point, name[i]}, null ); collection.add( feature ); } FeatureIterator iterator = collection.features(); try { while (iterator.hasNext()) { SimpleFeature feature = (SimpleFeature)iterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate[] coords = geometry.getCoordinates(); for( int i = 0; i < coords.length; i++ ) { System.out.println(coords[i]); } } } finally { if( iterator != null ){ // YOU MUST CLOSE THE ITERATOR! iterator.close(); } } FeatureSource featureSource = DataUtilities.source(collection); MapContext map = new DefaultMapContext(); map.setTitle("Quickstart"); map.addLayer(featureSource, null); // Now display the map JMapFrame.showMap(map); } } <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.geotools.demo.example</groupId> <artifactId>gttest1</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>gttest1</name> <url>http://maven.apache.org</url> <properties> <geotools.version>2.6-M3</geotools.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-main</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-shapefile</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-epsg-hsql</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-swing</artifactId> <version>${geotools.version}</version> </dependency> </dependencies> <repositories> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net repository</name> <url>http://download.java.net/maven/2</url> </repository> <repository> <id>osgeo</id> <name>Open Source Geospatial Foundation Repository</name> <url>http://download.osgeo.org/webdav/geotools/</url> </repository> <repository> <id>osgeo-snapshots</id> <name>Snapshot Repository</name> <snapshots> <enabled>true</enabled> </snapshots> <url>http://repo.opengeo.org/</url> </repository> </repositories> </project> Michael Bedward wrote: Hi Oliver, ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
Hi Oliver,
That looks good. In your pom.xml, you can now change your geotools.version property from 2.6-M3 to 2.6.0 which has been released (I'll update the example pages). cheers Michael ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Geotools-gt2-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |