Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.5.4
-
Fix Version/s: 2.7.6
-
Component/s: None
-
Labels:None
-
Environment:Using Windows Vista SP1/SP2 & 7RC. Java version 1.6.0_14.
Description
Here is the problem : i'm working on a town generator. So using pre-existing data such as town shapes, river or roads, i must create realistic village maps. I'm working on the roads right now, and for most of the villages I'm working on, there are no data about the roads. So I have to create them myself. What I want to do is create new features and add them to my MapLayer, so that I can display them to see if there are good or not. But when I try to add new features to my layer, I get this error :
"
java.lang.UnsupportedOperationException: Schema creation not supported
at org.geotools.data.AbstractDataStore.getFeatureWriter(AbstractDataStore.java:207)
at org.geotools.data.TransactionStateDiff.applyDiff(TransactionStateDiff.java:197)
at org.geotools.data.TransactionStateDiff.commit(TransactionStateDiff.java:151)
at org.geotools.data.DefaultTransaction.commit(DefaultTransaction.java:182)
at msi.sig.towngenerator.shapelab.ShapeTools.ajouterSurLayer(ShapeTools.java:193)
at msi.sig.towngenerator.generator.Generator.genereRoutes(Generator.java:386)
at msi.sig.towngenerator.generator.Generator.readCommune(Generator.java:189)
"
I don't really understanf what it means, since I think I've already checked if the layer was editable or not. Here is the code I run:
"
public static void ajouterSurLayer(Geometry geometry, MapLayer layer)
{
FeatureStore store;
SimpleFeatureType featureType = (SimpleFeatureType) layer.getFeatureSource().getSchema();
Object[] values = new Object[featureType.getAttributeCount()];
AttributeDescriptor geomAttribut = featureType.getGeometryDescriptor();
List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors();
for (int i = 0, max = attributes.size(); i < max; i++) {
AttributeDescriptor oneAttribut = attributes.get
;
if (oneAttribut.equals(geomAttribut))
{ values[i] = geometry; }else
{ values[i] = oneAttribut.getDefaultValue(); }}
SimpleFeature myFeature = SimpleFeatureBuilder.build(featureType, values, null);
FeatureCollection lstFeatures = FeatureCollections.newCollection();
lstFeatures.add(myFeature);
if (layer.getFeatureSource() instanceof FeatureStore) {
store = (FeatureStore) layer.getFeatureSource();
DefaultTransaction transaction = new DefaultTransaction();
store.setTransaction(transaction);
try
{ store.addFeatures(lstFeatures); transaction.commit(); } catch (Exception ex) {
ex.printStackTrace();
try
catch (IOException e)
{ e.printStackTrace(); }}finally
{ transaction.close(); } }
}
"
Here is the method in TransactionStateDiff:
FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
try{
writer = store.createFeatureWriter(typeName, transaction);
} catch (UnsupportedOperationException e) {
writer = store.getFeatureWriter(typeName);
}
So it looks like getFeatureWriter is only used as a fallback when working with old implementations that have not been upgraded to use createFeatureWriter. I will throw the original exception then .... as of -r33595 on trunk.