annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 655:6eccb68a8b99

Added WMS-Publishing to Product Layer gnv-artifacts/trunk@747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 08 Mar 2010 14:04:28 +0000
parents 4fc97074eb90
children 22dc921cd8b1
rev   line source
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.utils;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.File;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.io.IOException;
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
5 import java.io.Serializable;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.net.MalformedURLException;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
7 import java.util.Collection;
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
8 import java.util.Date;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
9 import java.util.HashMap;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
10 import java.util.List;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
11 import java.util.Map;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
13 import org.apache.log4j.Logger;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
14 import org.geotools.data.DataStoreFactorySpi;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import org.geotools.data.DataUtilities;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.geotools.data.DefaultTransaction;
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
17 import org.geotools.data.FeatureStore;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
18 import org.geotools.data.Transaction;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.geotools.data.shapefile.ShapefileDataStore;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.geotools.data.shapefile.ShapefileDataStoreFactory;
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
21 import org.geotools.feature.FeatureCollection;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
22 import org.geotools.feature.FeatureCollections;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
23 import org.geotools.feature.SchemaException;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
24 import org.geotools.feature.simple.SimpleFeatureBuilder;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
25 import org.geotools.referencing.crs.DefaultGeographicCRS;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
26 import org.opengis.feature.simple.SimpleFeature;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
27 import org.opengis.feature.simple.SimpleFeatureType;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
29 import com.vividsolutions.jts.geom.Geometry;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
30 import com.vividsolutions.jts.geom.MultiLineString;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
31 import com.vividsolutions.jts.geom.MultiPolygon;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
32 import com.vividsolutions.jts.io.ParseException;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
33 import com.vividsolutions.jts.io.WKTReader;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
34
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
35 import de.intevation.gnv.geobackend.base.Result;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
36
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 /**
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 */
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public final class ShapeFileWriter
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 private static Logger log = Logger.getLogger(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 ShapeFileWriter.class);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 private ShapeFileWriter() {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 public static boolean writeMultiLineStringsToFile(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 File shapeFile,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
50 Integer parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
51 Integer layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
52 Date date,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 List<Pair<Object, MultiLineString>> multiLineStrings
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 ) {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
55 return writeMultiLineStringsToFile(
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
56 shapeFile,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
57 parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
58 layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
59 date,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
60 multiLineStrings,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
61 "isolines");
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 public static boolean writeMultiLineStringsToFile(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 File shapeFile,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
66 Integer parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
67 Integer layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
68 Date date,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 List<Pair<Object, MultiLineString>> multiLineStrings,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
70 String name
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 ) {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
72 Map<String, Serializable> params = new HashMap<String, Serializable>();
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 try {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
75 params.put("url", shapeFile.toURI().toURL());
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 catch (MalformedURLException mue) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 log.error(mue.getLocalizedMessage(), mue);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 return false;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
82 params.put("create spatial index", Boolean.TRUE);
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
85 if (name == null) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
86 name = shapeFile.getName();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
87 }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
89 SimpleFeatureType TYPE;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
90
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
91 try {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
92 TYPE = DataUtilities.createType(
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
93 name,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
94 "geom:MultiLineString:srid=4326," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
95 "PARAMETER:Integer," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
96 "LAYER:Integer," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
97 "DATE:Date," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
98 "VALUE:Double");
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 catch (SchemaException se) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 log.error(se.getLocalizedMessage(), se);
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
102 return false;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
104
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
105 SimpleFeatureBuilder featureBuilder =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
106 new SimpleFeatureBuilder(TYPE);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
107
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
108 FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
109 FeatureCollections.newCollection();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
110
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
111 for (Pair<Object, MultiLineString> pair: multiLineStrings) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
112 featureBuilder.add(pair.getB());
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
113 featureBuilder.add(parameterId);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
114 featureBuilder.add(layer);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
115 featureBuilder.add(date);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
116 featureBuilder.add(pair.getA());
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
117 SimpleFeature feature = featureBuilder.buildFeature(null);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
118 collection.add(feature);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
119 }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
120
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
121 DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
122
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
123 Transaction transaction = null;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
124
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
125 boolean success = false;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
126 try {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
127 ShapefileDataStore newDataStore =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
128 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
129
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
130 newDataStore.createSchema(TYPE);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
131 newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
132
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
133 transaction = new DefaultTransaction("create");
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
134
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
135 String typeName = newDataStore.getTypeNames()[0];
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
136
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
137 FeatureStore<SimpleFeatureType, SimpleFeature> featureStore =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
138 (FeatureStore<SimpleFeatureType, SimpleFeature>)
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
139 newDataStore.getFeatureSource(typeName);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
140
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
141 featureStore.setTransaction(transaction);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
142
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
143 featureStore.addFeatures(collection);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
144 transaction.commit();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
145 success = true;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
146 }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 catch (IOException ioe) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 log.error(ioe.getLocalizedMessage(), ioe);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 finally {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
151 if (transaction != null) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
152 if (!success) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
153 try { transaction.rollback(); }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
154 catch (IOException ioe) {}
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
155 }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
156 try { transaction.close(); }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 catch (IOException ioe) {}
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 return success;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 public static boolean writeMultiPolygonsToFile(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 File shapeFile,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
166 Integer parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
167 Integer layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
168 Date date,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 Map<Integer, MultiPolygon> multiPolygons
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 ) {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
171 return writeMultiPolygonsToFile(
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
172 shapeFile,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
173 parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
174 layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
175 date,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
176 multiPolygons,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
177 "polygons");
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
180
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
181 public static String writeDataToFile(File shapeFile,
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
182 String name,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
183 Collection<Result> data){
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
184 String geomType = null;
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
185
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
186 WKTReader wktReader = new WKTReader();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
187
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
188 Map<String, Serializable> params = new HashMap<String, Serializable>();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
189
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
190 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
191 params.put("url", shapeFile.toURI().toURL());
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
192 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
193 catch (MalformedURLException mue) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
194 log.error(mue.getLocalizedMessage(), mue);
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
195 return null;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
196 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
197
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
198 params.put("create spatial index", Boolean.TRUE);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
199
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
200
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
201 if (name == null) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
202 name = shapeFile.getName();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
203 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
204
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
205 SimpleFeatureType type = null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
206 SimpleFeatureBuilder featureBuilder = null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
207 FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
208 FeatureCollections.newCollection();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
209
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
210 for (Result result: data) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
211 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
212 Geometry g = wktReader.read(result.getString(0));
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
213 if (type == null){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
214 try {
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
215 geomType = g.getGeometryType().toUpperCase();
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
216 type = DataUtilities.createType(
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
217 name,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
218 "geom:"+g.getGeometryType()+":srid=4326");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
219 // TODO add other AttributeTypes
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
220 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
221 catch (SchemaException se) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
222 log.error(se.getLocalizedMessage(), se);
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
223 return null;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
224 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
225 featureBuilder = new SimpleFeatureBuilder(type);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
226 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
227 featureBuilder.add(g);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
228 SimpleFeature feature = featureBuilder.buildFeature(null);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
229 collection.add(feature);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
230 } catch (ParseException e) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
231 log.error(e,e);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
232 } catch (java.lang.IllegalArgumentException e){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
233 log.error("cannot create geometry for "+result.getString(0));
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
234 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
235 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
236
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
237 DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
238
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
239 Transaction transaction = null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
240
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
241 boolean success = false;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
242 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
243 ShapefileDataStore newDataStore =
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
244 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
245
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
246 newDataStore.createSchema(type);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
247 newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
248
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
249 transaction = new DefaultTransaction("create");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
250
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
251 String typeName = newDataStore.getTypeNames()[0];
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
252
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
253 FeatureStore<SimpleFeatureType, SimpleFeature> featureStore =
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
254 (FeatureStore<SimpleFeatureType, SimpleFeature>)
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
255 newDataStore.getFeatureSource(typeName);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
256
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
257 featureStore.setTransaction(transaction);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
258
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
259 featureStore.addFeatures(collection);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
260 transaction.commit();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
261 success = true;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
262 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
263 catch (IOException ioe) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
264 log.error(ioe.getLocalizedMessage(), ioe);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
265 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
266 finally {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
267 if (transaction != null) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
268 if (!success) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
269 try { transaction.rollback(); }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
270 catch (IOException ioe) {}
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
271 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
272 try { transaction.close(); }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
273 catch (IOException ioe) {}
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
274 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
275 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
276
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
277 return geomType;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
278
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
279 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 498
diff changeset
280
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
281 public static boolean writeMultiPolygonsToFile(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
282 File shapeFile,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
283 Integer parameterId,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
284 Integer layer,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
285 Date date,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286 Map<Integer, MultiPolygon> multiPolygons,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
287 String name
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
288 ) {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
289 Map<String, Serializable> params = new HashMap<String, Serializable>();
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 try {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
292 params.put("url", shapeFile.toURI().toURL());
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294 catch (MalformedURLException mue) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 log.error(mue.getLocalizedMessage(), mue);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
296 return false;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
299 params.put("create spatial index", Boolean.TRUE);
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
302 if (name == null) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
303 name = shapeFile.getName();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
304 }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
305
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
306 SimpleFeatureType TYPE;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
307
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
308 try {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
309 TYPE = DataUtilities.createType(
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
310 name,
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
311 "geom:MultiPolygon:srid=4326," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
312 "PARAMETER:Integer," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
313 "LAYER:Integer," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
314 "DATE:Date," +
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
315 "CLASS:Integer");
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
316 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
317 catch (SchemaException se) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
318 log.error(se.getLocalizedMessage(), se);
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
319 return false;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
320 }
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
321
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
322 SimpleFeatureBuilder featureBuilder =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
323 new SimpleFeatureBuilder(TYPE);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
324
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
325 FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
326 FeatureCollections.newCollection();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
327
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
328 for (Map.Entry<Integer, MultiPolygon> entry:
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
329 multiPolygons.entrySet()
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
330 ) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
331 featureBuilder.add(entry.getValue());
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
332 featureBuilder.add(parameterId);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
333 featureBuilder.add(layer);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
334 featureBuilder.add(date);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
335 featureBuilder.add(entry.getKey());
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
336 SimpleFeature feature = featureBuilder.buildFeature(null);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
337 collection.add(feature);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
338 }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
339
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
340 DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
341
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
342 Transaction transaction = null;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
343
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
344 boolean success = false;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
345 try {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
346 ShapefileDataStore newDataStore =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
347 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
348
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
349 newDataStore.createSchema(TYPE);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
350 newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
351
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
352 transaction = new DefaultTransaction("create");
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
353
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
354 String typeName = newDataStore.getTypeNames()[0];
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
355
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
356 FeatureStore<SimpleFeatureType, SimpleFeature> featureStore =
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
357 (FeatureStore<SimpleFeatureType, SimpleFeature>)
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
358 newDataStore.getFeatureSource(typeName);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
359
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
360 featureStore.setTransaction(transaction);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
361
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
362 featureStore.addFeatures(collection);
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
363 transaction.commit();
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
364 success = true;
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
365 }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
366 catch (IOException ioe) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
367 log.error(ioe.getLocalizedMessage(), ioe);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
368 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
369 finally {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
370 if (transaction != null) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
371 if (!success) {
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
372 try { transaction.rollback(); }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
373 catch (IOException ioe) {}
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
374 }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
375 try { transaction.close(); }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
376 catch (IOException ioe) {}
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
377 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
378 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
379
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
380 return success;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
381 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
382
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
383 private static final Double asDouble(Object a) {
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
384 if (a instanceof Double) {
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
385 return (Double)a;
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
386 }
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
387 if (a instanceof Number) {
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
388 return Double.valueOf(((Number)a).doubleValue());
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
389 }
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
390 return 0d;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
391 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
392 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
393 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org