This is what I do...

FeatureItertor iter = allFeatures.features();
try {
    while (iter.hasNext()) {
        SimpleFeature feature = (SimpleFeature)iter.next();
        Geometry geom = (Geometry) feature.getAttribute("shape");  //
where shape is geom attribute name in this example
        for (Coordinate coord : geom.getCoordinates()) {
            doSomethingWonderful(coord);
        }
    }
} finally {
    iter.close();
}

You might also like to look at the JTS CoordinateFilter interface
which can make things simpler sometimes.  There's a basic example in
the users guide:
http://docs.codehaus.org/display/GEOTDOC/04+Using+CoordinateFilter+to+implement+operations

Also if you know what your geometry sub-class is (e.g. Polygnon) you
might do something like this...

    Polygon poly = (Polygon) feature.getAttribute("attrName");
    LineString outerShell = poly.getExteriorRing();
    for (Coordinate coord : outerShell.getCordinates()) {
        ...
    }

Have a look at JTS docs for more info:
http://tsusiatsoftware.net/jts/javadoc/index.html

Michael

2009/1/15 Greg Ederer <g...@ergonosis.com>:
> Hi,
>
> I have the following code:
>
> FeatureCollection allFeatures = featureSource.getFeatures();
>     Iterator iterator = allFeatures.iterator();
>     try
>     {
>       for (Iterator i = allFeatures.iterator(); i.hasNext();)
>       {
>         Feature feature = (Feature) i.next();
>         System.out.println(feature.getType());
>       }
>     }
>     finally
>     {
>       allFeatures.close(iterator);
>     }
>
> I would now like to iterate over the vertices of each feature, and get
> the coordinates.  I'm having a little trouble figuring this out.  What
> is the best way to do this?
>
> Thanks!
>
> Greg
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Geotools-gt2-users mailing list
> Geotools-gt2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to