[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[udig-devel] DXF Plugin/FeatureCollection Geometry
|
Hi, it looks like the code in one of the open source products I've been using
is creating a FeatureCollection where the individual Feature objects do have
the default Geometry set, but the FeatureCollection itself does not. Here's
the code - it's part of a package to convert between JTS FeatureCollection
and Geotools FeatureCollection. It's freely available at
http://soldin.de/about/2004-jump_plugins/ - I'm using the gt2jump.readwrite .
---------------------------------------
public static org.geotools.feature.FeatureCollection
convert(com.vividsolutions.jump.feature.FeatureCollection jump_features)
throws Exception{
// GT2 feature collection
org.geotools.feature.FeatureCollection gt2_features =
org.geotools.feature.FeatureCollections.newCollection();
for (Iterator iter = jump_features.iterator();
iter.hasNext();) {
Feature jump_feature = (Feature) iter.next();
// get jump_schema for feature
FeatureSchema jump_fschema =
jump_feature.getSchema();
// create a feature schema for GT2
org.geotools.feature.FeatureTypeFactory
gt2_ftype_factory =
org.geotools.feature.FeatureTypeFactory.newInstance(Integer.toString(jump_fea
ture.getID()));
// create an array of GT2 Attribs
Object[] gt2_attribs = new
Object[jump_fschema.getAttributeCount()];
for (int i = 0; i<jump_fschema.getAttributeCount();
i++){
// building schema
AttributeType a_type =
jump_fschema.getAttributeType(i);
org.geotools.feature.AttributeType gt2_a_type
=
org.geotools.feature.AttributeTypeFactory.newAttributeType(
jump_fschema.getAttributeName(i),
a_type.toJavaClass());
gt2_ftype_factory.addType(gt2_a_type);
// adding attrib
gt2_attribs[i] =
jump_feature.getAttribute(i);
}
//System.out.println(gt2_ftype_factory.toString());
org.geotools.feature.FeatureType gt2_ftype =
gt2_ftype_factory.getFeatureType();
// create GT2 feature
String fid = Integer.toString(jump_feature.getID());
org.geotools.feature.Feature gt2_feature =
gt2_ftype.create(gt2_attribs,fid);
// add it to collection
gt2_features.add(gt2_feature);
}
return gt2_features;
}
---------------------------------------
Also, the setDefaultGeometry function doesn't work - I went through the
geotools source (org.geotools.feature.DefaultFeatureCollection.java) and
found the relevant code.
public void setDefaultGeometry(Geometry geometry) throws
IllegalAttributeException {
throw new IllegalAttributeException("Not Supported");
}