it is a example for iterate file shapefile, it convert the multipolygon to
linestring:


FeatureCollection featureCollection = (FeatureCollection) figuras
                                                        .get(key);
                                        Iterator it = 
featureCollection.iterator();
                                        while (it.hasNext()) {
                                        Feature feaNext = (Feature) it.next();
Object geometry = feaNext.getDefaultGeometryValue();
Geometry geom = (Geometry) geometry;
MultiPolygon multiPolygon = (MultiPolygon) geom;

for (int j = 0; j < multiPolygon.getNumGeometries(); j++) {
        Geometry geomMulti = multiPolygon.getGeometryN(j);
        CoordinateList coordinateList = new CoordinateList();
        Vector<Geometry> vectorGeometry = new Vector<Geometry>();
        for (int i = 0; i < geomMulti.getCoordinates().length; i++) {
                                        if (coordinateList.size() > 0
                                        && 
coordinateList.contains(geomMulti.getCoordinates()[i])) {
                                                        
coordinateList.add(geomMulti.getCoordinates()[i], true);
                                        
vectorGeometry.add(gf.createLineString(coordinateList.toCoordinateArray()));
                                coordinateList = new CoordinateList();
                                                                        } else {
                                                                                
coordinateList.add(geomMulti
                                                                                
                .getCoordinates()[i], true);
                                                                        }
                                                                }

//here, you have all geometry contains the multipolygon. 
}
}

Sorry for my english.





yellowbkpk wrote:
> 
> I'd like to iterate through all of the features of a Shapefile (and
> convert them to OpenStreetMap format, but I can do that part once I read
> them).
> 
> I've succesfully followed the tutorial on the webpage to read the
> shapefile, but the problem is that once I read it in, I can't break apart
> any of the multi* geometry types.
> 
> If I have a MultiPolygon or MultiLineString (for example), how do I fetch
> the pieces of the geometry using the JTS API?
> 
> It looks like I could continuously break it down with getGeometryN() and
> getNumGeometries(), but then I would lose the ability to group the points
> into the lines and polygons.
> 
> Thanks,
> Ian
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-iterate-through-Shapefile--tp19640992p19968449.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to