use of org.geotools.feature.simple.SimpleFeatureBuilder in project sldeditor by robward-scisys.
the class InLineFeatureModel method updateCRS.
/**
* Update CRS.
*
* @param selectedValue the selected value
*/
public void updateCRS(ValueComboBoxData selectedValue) {
if (selectedValue != null) {
String crsCode = selectedValue.getKey();
CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);
SimpleFeatureType newFeatureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);
ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
SimpleFeatureIterator it = featureSource.getFeatures().features();
try {
while (it.hasNext()) {
SimpleFeature sf = it.next();
List<Object> attributeValueList = sf.getAttributes();
sfb.addAll(attributeValueList);
featureList.add(sfb.buildFeature(null));
}
} finally {
it.close();
}
SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType, featureList);
featureCollection = collection;
cachedFeature = null;
lastRow = -1;
DataStore dataStore = DataUtilities.dataStore(collection);
userLayer.setInlineFeatureDatastore(dataStore);
userLayer.setInlineFeatureType(newFeatureType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.inlineFeatureUpdated();
}
}
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project OpenTripPlanner by opentripplanner.
the class LIsochrone method makeContourFeatures.
/**
* Create a geotools feature collection from a list of isochrones in the OTPA internal format.
* Once in a FeatureCollection, they can for example be exported as GeoJSON.
*/
public static SimpleFeatureCollection makeContourFeatures(List<IsochroneData> isochrones) {
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, contourSchema);
SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema);
for (IsochroneData isochrone : isochrones) {
fbuilder.add(isochrone.geometry);
fbuilder.add(isochrone.cutoffSec);
featureCollection.add(fbuilder.buildFeature(null));
}
return featureCollection;
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makePointFeatures.
private SimpleFeatureCollection makePointFeatures() throws Exception {
Map<Vertex, Double> points = makePoints();
/* Stage the point features in memory */
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, pointSchema);
SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(pointSchema);
GeometryFactory gf = new GeometryFactory();
for (Map.Entry<Vertex, Double> entry : points.entrySet()) {
Vertex vertex = entry.getKey();
Double travelTime = entry.getValue();
fbuilder.add(gf.createPoint(vertex.getCoordinate()));
fbuilder.add(travelTime);
featureCollection.add(fbuilder.buildFeature(null));
}
return featureCollection;
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project OpenTripPlanner by opentripplanner.
the class SimpleIsochrone method makeContourFeatures.
private SimpleFeatureCollection makeContourFeatures() throws Exception {
Map<Integer, Geometry> contours = makeContours();
/* Stage the features in memory, in order from bottom to top, biggest to smallest */
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, contourSchema);
SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(contourSchema);
List<Integer> thresholds = new ArrayList<Integer>(contours.keySet());
Collections.sort(thresholds);
// Collections.reverse(thresholds);
for (Integer threshold : thresholds) {
Geometry contour = contours.get(threshold);
fbuilder.add(contour);
fbuilder.add(threshold);
featureCollection.add(fbuilder.buildFeature(null));
}
return featureCollection;
}
use of org.geotools.feature.simple.SimpleFeatureBuilder in project traffic-engine by opentraffic.
the class OSMUtils method toShapefile.
public static void toShapefile(List<SpatialDataItem> segs, String filename) throws SchemaException, IOException {
final SimpleFeatureType TYPE = DataUtilities.createType("Location", "the_geom:LineString:srid=4326," + "name:String");
System.out.println("TYPE:" + TYPE);
List<SimpleFeature> features = new ArrayList<SimpleFeature>();
/*
* GeometryFactory will be used to create the geometry attribute of each feature,
* using a Point object for the location.
*/
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
for (SpatialDataItem seg : segs) {
featureBuilder.add(seg.getGeometry());
featureBuilder.add(seg.id);
SimpleFeature feature = featureBuilder.buildFeature(null);
features.add(feature);
}
File newFile = new File(filename);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", newFile.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
/*
* TYPE is used as a template to describe the file contents
*/
newDataStore.createSchema(TYPE);
ContentFeatureSource cfs = newDataStore.getFeatureSource();
if (cfs instanceof SimpleFeatureStore) {
SimpleFeatureStore featureStore = (SimpleFeatureStore) cfs;
SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);
try {
featureStore.addFeatures(collection);
} catch (Exception problem) {
problem.printStackTrace();
} finally {
}
}
}
Aggregations