sascha@465: package de.intevation.gnv.utils;
sascha@465:
sascha@779: import com.vividsolutions.jts.geom.Geometry;
sascha@779: import com.vividsolutions.jts.geom.MultiLineString;
sascha@779: import com.vividsolutions.jts.geom.MultiPolygon;
sascha@779:
sascha@779: import com.vividsolutions.jts.io.ParseException;
sascha@779: import com.vividsolutions.jts.io.WKTReader;
sascha@779:
sascha@779: import de.intevation.gnv.geobackend.base.Result;
sascha@779: import de.intevation.gnv.geobackend.base.ResultDescriptor;
sascha@779:
sascha@465: import java.io.File;
sascha@465: import java.io.IOException;
sascha@498: import java.io.Serializable;
sascha@779:
sascha@465: import java.net.MalformedURLException;
sascha@779:
ingo@760: import java.text.NumberFormat;
sascha@779:
tim@649: import java.util.Collection;
sascha@498: import java.util.Date;
sascha@498: import java.util.HashMap;
sascha@498: import java.util.List;
sascha@498: import java.util.Map;
sascha@465:
sascha@498: import org.apache.log4j.Logger;
sascha@779:
sascha@498: import org.geotools.data.DataStoreFactorySpi;
sascha@465: import org.geotools.data.DataUtilities;
sascha@465: import org.geotools.data.DefaultTransaction;
sascha@498: import org.geotools.data.FeatureStore;
sascha@498: import org.geotools.data.Transaction;
sascha@779:
sascha@465: import org.geotools.data.shapefile.ShapefileDataStore;
sascha@465: import org.geotools.data.shapefile.ShapefileDataStoreFactory;
sascha@779:
sascha@498: import org.geotools.feature.FeatureCollection;
sascha@498: import org.geotools.feature.FeatureCollections;
sascha@498: import org.geotools.feature.SchemaException;
sascha@779:
sascha@498: import org.geotools.feature.simple.SimpleFeatureBuilder;
sascha@779:
sascha@498: import org.geotools.referencing.crs.DefaultGeographicCRS;
sascha@779:
sascha@498: import org.opengis.feature.simple.SimpleFeature;
sascha@498: import org.opengis.feature.simple.SimpleFeatureType;
sascha@465:
sascha@465: /**
sascha@780: * @author Sascha L. Teichmann
sascha@465: */
sascha@465: public final class ShapeFileWriter
sascha@465: {
sascha@465: private static Logger log = Logger.getLogger(
sascha@465: ShapeFileWriter.class);
sascha@465:
ingo@760: private static NumberFormat format = NumberFormat.getInstance();
ingo@760:
ingo@760: public static final int DOUBLE_PRECISION = 3;
ingo@760:
ingo@761: static {
ingo@761: format.setMaximumFractionDigits(DOUBLE_PRECISION);
ingo@761: }
ingo@761:
sascha@465: private ShapeFileWriter() {
sascha@465: }
sascha@465:
sascha@465: public static boolean writeMultiLineStringsToFile(
sascha@465: File shapeFile,
sascha@498: Integer parameterId,
sascha@498: Integer layer,
sascha@498: Date date,
sascha@465: List> multiLineStrings
sascha@465: ) {
sascha@498: return writeMultiLineStringsToFile(
sascha@498: shapeFile,
sascha@498: parameterId,
sascha@498: layer,
sascha@498: date,
sascha@778: multiLineStrings,
sascha@498: "isolines");
sascha@465: }
sascha@465:
sascha@465: public static boolean writeMultiLineStringsToFile(
sascha@465: File shapeFile,
sascha@498: Integer parameterId,
sascha@498: Integer layer,
sascha@498: Date date,
sascha@465: List> multiLineStrings,
sascha@498: String name
sascha@465: ) {
sascha@498: Map params = new HashMap();
sascha@465:
sascha@465: try {
sascha@498: params.put("url", shapeFile.toURI().toURL());
sascha@465: }
sascha@465: catch (MalformedURLException mue) {
sascha@465: log.error(mue.getLocalizedMessage(), mue);
sascha@465: return false;
sascha@465: }
sascha@465:
sascha@498: params.put("create spatial index", Boolean.TRUE);
sascha@465:
sascha@465:
sascha@498: if (name == null) {
sascha@498: name = shapeFile.getName();
sascha@498: }
sascha@465:
sascha@498: SimpleFeatureType TYPE;
sascha@778:
sascha@778: try {
sascha@498: TYPE = DataUtilities.createType(
sascha@498: name,
sascha@498: "geom:MultiLineString:srid=4326," +
sascha@778: "PARAMETER:Integer," +
sascha@498: "LAYER:Integer," +
sascha@498: "DATE:Date," +
ingo@760: "VALUE:Double," +
ingo@760: "DESC:String");
sascha@465: }
sascha@465: catch (SchemaException se) {
sascha@465: log.error(se.getLocalizedMessage(), se);
sascha@498: return false;
sascha@465: }
sascha@498:
sascha@498: SimpleFeatureBuilder featureBuilder =
sascha@498: new SimpleFeatureBuilder(TYPE);
sascha@498:
sascha@778: FeatureCollection collection =
sascha@498: FeatureCollections.newCollection();
sascha@498:
sascha@498: for (Pair