Hallo,
I'm parsing a textfile line by line. Line values are simply split. One of
these values consist of polygon coordinates, which I allready used for
creating a jts Polygon object. I want to write the polygons along with the
other attributes to shape and dbf. I just can't manage it using the
following code. what am i doing wrong?
any comments will be helpful. thanks. 
steffen.

                GeometryFactory gf = new GeometryFactory();
                MemoryDataStore data = new MemoryDataStore();
                FeatureType type = null;

                try {
                        BufferedReader reader = new BufferedReader(new 
FileReader(infile));
                        String strLine;
                        String[] fieldnames = reader.readLine().split("~");
                        while ((strLine = reader.readLine()) != null) {
                                String[] items = strLine.split("~");
                                for (int i = 0; i < items.length; i++) {
                                        if (fieldnames[i].contains("FOOT")) {
                                                String[] footprint = 
items[i].split(" ");

                                                int idx = 0;
                                                Coordinate[] coords = new 
Coordinate[footprint.length / 2];
                                                for (int j = 0; j < 
footprint.length / 2; j++) {
                                                        Coordinate coord = new 
Coordinate(Double
                                                                        
.parseDouble(footprint[idx + 1]), Double
                                                                        
.parseDouble(footprint[idx]));
                                                        idx = idx + 2;
                                                        coords[j] = coord;
                                                }

                                                LinearRing ring = 
gf.createLinearRing(coords);
                                                Polygon polygon = 
gf.createPolygon(ring, null);
                                                AttributeType attr = 
AttributeTypeFactory
                                                                
.newAttributeType("the_geom", Polygon.class);
                                                // I dont really understand this
                                                FeatureTypeBuilder ftBuilder = 
FeatureTypeBuilder
                                                                
.newInstance("ez");
                                                
                                                ftBuilder.addType(attr);
                                                type = 
ftBuilder.getFeatureType();
                                                Feature feature = 
type.create(new Object[] { polygon });

                                                data.addFeature(feature);
                                        }

                                }

                                ShapefileDataStore newShapefileDataStore = new 
ShapefileDataStore(
                                                out.toURL());
                                newShapefileDataStore.createSchema(type);

                // grab the data source from the new shapefile data store
                FeatureSource newFeatureSource =
data.getFeatureSource("ez");
                FeatureCollection fsFilteredShape =
newFeatureSource.getFeatures(); 

                // downcast FeatureSource to specific implementation of
FeatureStore
                FeatureStore newFeatureStore =
(FeatureStore)newFeatureSource;

                // accquire a transaction to create the shapefile from
FeatureStore
                Transaction t = newFeatureStore.getTransaction();

                // add features got from the query (FeatureReader)
                //newFeatureStore.addFeatures(filteredReader);
                newFeatureStore.addFeatures(fsFilteredShape);

                // filteredReader is now exhausted and closed, commit the
changes
                t.commit();
                t.close();

                        }

                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

-- 
View this message in context: 
http://www.nabble.com/Creating-polygon-shapefile-tp16150328p16150328.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to