Hello all,

I have a shapefile with MULTIPOINT shapetypes that I need to convert to
a shapefile with POINT shapetypes. I have create some code that to do
this, but I get a NullPointerException in the Geotools code. Please take
a look at the code below:

 

I change the original schema file with the following code:

 

AttributeType[] attributeTypes = schema.getAttributeTypes();

attributeTypes[schema.find("the_geom")] =
AttributeTypeFactory.newAttributeType("the_geom", Point.class);;

FeatureType newSchema =
FeatureTypeBuilder.newFeatureType(attributeTypes, schema

            .getTypeName(), schema.getNamespace(), schema.isAbstract(),
schema.getAncestors(),

                  schema.getDefaultGeometry());

 

I change the features with the following code:

 

Geometry geom =
feature.getDefaultGeometry().getInteriorPoint().getGeometryN(0);

feature.setDefaultGeometry(geom);

 

 

 

Then I write all the features to a new shapefile:

 

ShapefileDataStore outStore = new
ShapefileDataStore(outputSHP.toURI().toURL());

outStore.createSchema(newSchema);

 

FeatureWriter outFeatureWriter =
outStore.getFeatureWriter(outStore.getTypeNames()[0],

                        Transaction.AUTO_COMMIT);

 

for (Feature feature : features) {

      // Get the next, empty feature from the writer

      Feature writeFeature = outFeatureWriter.next();

att = feature.getAttributes(att);

 

for (int n = 0; n < att.length; n++) {

writeFeature.setAttribute(n, att[n]);

}

outFeatureWriter.write();

}

 

// line below is essential, incomplete files are written without it!

outFeatureWriter.close();

 

When I run the above code I get a NullPointerException at
org.geotools.data.shapefile.ShapefileDataStore$Writer.write(ShapefileDat
aStore.java:1595).

 

I don't see how I can solve this. Does anyone see what I'm doing wrong
here or how I can do the conversion?

 

Thanks in advance,

 

Jeroen

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to