I have an application which exports an ArcGIS map points. Receipt points in a Spring MVC controller.
My Pointer has a list of attributes that can be variable. The attributes are a list of strings with two values, name and value. Code:
public class PointDTO {
private String type;
private Double x;
private Double y;
private Integer wkid;
private List<String[]> atributtes = new ArrayList<String[]>();
//Getters & Setters
}
He wanted to know if you can use a list type or something similar to this in the SimpleFeatureType:
SimpleFeatureType type = DataUtilities.createType ("Location", "the_geom: Point: srid = 25829"
+ "Type: String"
+ "X: double," + "And: double,"
+ "Atributes: List");
Right now what I do is to have a 'Attribute' string type. And I concatenate all the attributes but has a maximum length of 250 characters.
Another solution would be to declare several SimpleFeatureType but I think you can not use the same ShapefileDataStore.
Also I have problem importing words with accents in online ArcgisExporer.
You should be able to use something like the following to create your FeatureTypes and Features for each of your types. Then it's a simple case of generating a ShapefileDatastore to write each set out.
package spike;
import java.util.ArrayList;
import java.util.List;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.geometry.jts.GeometryBuilder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import com.vividsolutions.jts.geom.Point;
public class ShpFileBuilder {
static final GeometryBuilder GEOMBUILDER = new GeometryBuilder();
public SimpleFeatureType buildType(PointDTO dto) {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName(dto.type);
builder.setNamespaceURI("http://www.geotools.org/");
builder.setSRS("EPSG:25829");
builder.add("the_geom", Point.class);
for (String[] att : dto.atributtes) {
builder.add(att[0], String.class);
}
SimpleFeatureType featureType = builder.buildFeatureType();
return featureType;
}
public SimpleFeature buildFeature(PointDTO dto, SimpleFeatureType schema) {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
Point p = GEOMBUILDER.point(dto.x.doubleValue(), dto.y.doubleValue());
builder.set("the_geom", p);
for (String[] att : dto.atributtes) {
builder.set(att[0], att[1]);
}
return builder.buildFeature(dto.wkid.toString());
}
public class PointDTO {
private String type;
private Double x;
private Double y;
private Integer wkid;
private List<String[]> atributtes = new ArrayList<String[]>();
// Getters & Setters
}
}