Hello List,
i´ve got a problem by creating a shapefile.
public static void AusgabeShape(double [][][] zellraster, File raster, int
i) throws IOException, SchemaException
{
//Shape erzeugen
//Grundgerüst erstellen
final SimpleFeatureType TYPE =
DataUtilities.createType("Raster","location:Polygon:srid:31467,"+"ID:Integer,"+"KSCHNITT:Double,"+"KABSOLUT:Double");
//Geometrie aus dem vorhandenen Rastershape mit den berechneten
Sachdaten
verbinden
//Raster
FileDataStore store = FileDataStoreFinder.getDataStore(raster);
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureCollection featureCollection =
featureSource.getFeatures();
//neue Polygone-Sammlung erzeugen
SimpleFeatureCollection newcollection =
FeatureCollections.newCollection();
//neue Features erzeugen, die dem TYPE entsprechen
SimpleFeatureBuilder featureBuilder = new
SimpleFeatureBuilder(TYPE);
//Verbinden von Geometrie und Infos
FeatureIterator iterator = featureCollection.features();
try {
while (iterator.hasNext()) {
SimpleFeature feature = (SimpleFeature)
iterator.next();
int spalte =
systemfunktionen.Spalte(feature.getID());
int zeile =
systemfunktionen.Zeile(feature.getID());
Geometry the_geom = (Geometry)
feature.getDefaultGeometry();
featureBuilder.add(the_geom);
featureBuilder.add(feature.getID());
featureBuilder.add(zellraster[zeile][spalte][konstante.platz_anzahl_kaefer_schnitt]);
featureBuilder.add(zellraster[zeile][spalte][konstante.platz_anzahl_kaefer_absolut]);
SimpleFeature newfeature =
featureBuilder.buildFeature(null);
newcollection.add(newfeature);
}
} finally {
featureCollection.close(iterator);
}
ShapefileDataStoreFactory dataStoreFactory = new
ShapefileDataStoreFactory();
Map<String,Serializable> params = new HashMap<String,
Serializable>();
File newFile = new
File(konstante.shapespeicherpfad+i+"muh.shp");
params.put("url",newFile.toURI().toURL());
params.put("create spatial index",Boolean.TRUE);
ShapefileDataStore newDataStore = (ShapefileDataStore)
dataStoreFactory.createNewDataStore(params);
newDataStore.createSchema(TYPE);
newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
Transaction transaction = new DefaultTransaction("create");
String typeName = newDataStore.getTypeNames()[0];
SimpleFeatureSource newfeatureSource =
newDataStore.getFeatureSource(typeName);
if (featureSource instanceof SimpleFeatureStore)
{
SimpleFeatureStore newfeatureStore =
(SimpleFeatureStore)
newfeatureSource;
newfeatureStore.setTransaction(transaction);
try
{
newfeatureStore.addFeatures(newcollection);
transaction.commit();
}
catch (Exception problem)
{
problem.printStackTrace();
transaction.rollback();
}
finally
{
transaction.close();
}
System.exit(0);
}
else
{
System.out.println(typeName+" does not support
read/write access");
System.exit(1);
}
}
but i get the following error:
14.06.2011 11:19:31 org.geotools.data.shapefile.ShapefileDataStore
createSchema
WARNUNG: PRJ file not generated for null CoordinateReferenceSystem
java.io.IOException: Current fid index is null, next must be called before
write()
at
org.geotools.data.shapefile.indexed.IndexedFidWriter.write(IndexedFidWriter.java:250)
at
org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.write(IndexedShapefileFeatureWriter.java:100)
at
org.geotools.data.shapefile.ShapefileFeatureWriter.close(ShapefileFeatureWriter.java:225)
at
org.geotools.data.shapefile.indexed.IndexedShapefileFeatureWriter.close(IndexedShapefileFeatureWriter.java:108)
at
org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:276)
at
org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:146)
at
org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:182)
at main.geometriefunktionen.AusgabeShape(geometriefunktionen.java:326)
at main.funktionen.Generationenberechnung(funktionen.java:52)
at main.start.main(start.java:74)
i don´t know why?
please help me!
thanks a lot
balli
--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Problems-by-creating-a-shapefile-tp6473348p6473348.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users