Creating WKT objects from FeatureCollection

3 messages Options
Embed this post
Permalink
Heise, Robert

Creating WKT objects from FeatureCollection

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hello,

 

I am a newbie to geotools, so appreciate any support.  Does anybody have any code examples that can programmatically create WKT strings from iterating a FeatureCollection?

 

Thanks

Rob



This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Creating WKT objects from FeatureCollection

Reply Threaded More More options
Print post
Permalink
Hi Robert and welcome to GeoTools.

> I am a newbie to geotools, so appreciate any support.  Does anybody have any
> code examples that can programmatically create WKT strings from iterating a
> FeatureCollection?

Here's one way to do it...

    public void getWKT(FeatureCollection<SimpleFeatureType,
SimpleFeature> collection)
            throws IOException {
        FeatureVisitor visitor = new FeatureVisitor() {

            WKTWriter writer = new WKTWriter();

            public void visit(Feature feature) {
                Geometry geom = (Geometry)
feature.getDefaultGeometryProperty().getValue();
                String wkt = writer.writeFormatted(geom);
                System.out.println(wkt);
            }
        };

        collection.accepts(visitor, null);
    }


Michael

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Creating WKT objects from FeatureCollection

Reply Threaded More More options
Print post
Permalink
Oops... also meant to include the imports with that code snippet:

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTWriter;
import java.io.IOException;
import org.geotools.feature.FeatureCollection;
import org.opengis.feature.Feature;
import org.opengis.feature.FeatureVisitor;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users