SimpleFeatureType featureType = b.buildFeatureType();
try {
MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
pm.beginTask("Import gps to lines...", logsList.size());
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
int index = 0;
for( GpsLog log : logsList ) {
List<GpsPoint> points = log.points;
List<Coordinate> coordList = new ArrayList<Coordinate>();
String startDate = log.startTime;
String endDate = log.endTime;
for( GpsPoint gpsPoint : points ) {
Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
coordList.add(c);
}
Coordinate[] coordArray = (Coordinate[]) coordList.toArray(new Coordinate[coordList.size()]);
if (coordArray.length < 2) {
continue;
}
LineString lineString = gF.createLineString(coordArray);
LineString reprojectLineString = (LineString) JTS.transform(lineString, transform);
MultiLineString multiLineString = gF.createMultiLineString(new LineString[]{reprojectLineString});
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
Object[] values = new Object[]{multiLineString, startDate, endDate, log.text};
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);
newCollection.add(feature);
pm.worked(1);
}
pm.done();
ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", outputLinesShapeFile.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore dStore = (ShapefileDataStore) factory.createNewDataStore(params);
dStore.createSchema(featureType);
dStore.forceSchemaCRS(mapCrs);
JGrassToolsPlugin.getDefault().writeToShapefile(dStore, newCollection);
JGrassToolsPlugin.getDefault().addServiceToCatalogAndMap(outputLinesShapeFile.getAbsolutePath(), true, true,
new NullProgressMonitor());
} catch (Exception e1) {
JGrassToolsPlugin.log(e1.getLocalizedMessage(), e1);
e1.printStackTrace();
}
/*
* create the points shapefile
*/
File outputPointsShapeFile = new File(outputFolderFile, "gpspoints.shp");
b = new SimpleFeatureTypeBuilder();
b.setName("geopaparazzinotes");
b.setCRS(mapCrs);
b.add("the_geom", Point.class);
b.add("ALTIMETRY", String.class);
b.add("DATE", String.class);
featureType = b.buildFeatureType();
try {
MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
pm.beginTask("Import gps to points...", logsList.size());
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
int index = 0;
for( GpsLog log : logsList ) {
List<GpsPoint> gpsPointList = log.points;
for( GpsPoint gpsPoint : gpsPointList ) {
Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
Point point = gF.createPoint(c);
Point reprojectPoint = (Point) JTS.transform(point, transform);
Object[] values = new Object[]{reprojectPoint, String.valueOf(gpsPoint.altim), gpsPoint.utctime};
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);
newCollection.add(feature);
}
pm.worked(1);
}
pm.done();