Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 761:0b1de7e38907
Adjusted mapfile templates for 'Horizontalschnitte' - display DESC column as label in a WMS layer (issue209).
gnv-artifacts/trunk@815 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Mar 2010 11:23:33 +0000 |
parents | f82e57a60124 |
children | 9a828e5a2390 |
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; |
760
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
7 import java.text.NumberFormat; |
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
|
8 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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 |
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
|
14 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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 |
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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 |
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 import de.intevation.gnv.geobackend.base.Result; |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
37 import de.intevation.gnv.geobackend.base.ResultDescriptor; |
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
|
38 |
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
|
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 * @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
|
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 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
|
43 { |
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 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
|
45 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
|
46 |
760
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
47 private static NumberFormat format = NumberFormat.getInstance(); |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
48 |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
49 public static final int DOUBLE_PRECISION = 3; |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
50 |
761
0b1de7e38907
Adjusted mapfile templates for 'Horizontalschnitte' - display DESC column as label in a WMS layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
760
diff
changeset
|
51 static { |
0b1de7e38907
Adjusted mapfile templates for 'Horizontalschnitte' - display DESC column as label in a WMS layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
760
diff
changeset
|
52 format.setMaximumFractionDigits(DOUBLE_PRECISION); |
0b1de7e38907
Adjusted mapfile templates for 'Horizontalschnitte' - display DESC column as label in a WMS layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
760
diff
changeset
|
53 } |
0b1de7e38907
Adjusted mapfile templates for 'Horizontalschnitte' - display DESC column as label in a WMS layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
760
diff
changeset
|
54 |
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
|
55 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
|
56 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 ) { |
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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 "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
|
72 } |
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 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
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 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
|
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 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
|
85 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
|
86 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
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
|
92 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
|
93 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
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
|
95 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
|
96 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
|
97 } |
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
|
98 |
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
|
99 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
|
100 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 "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
|
105 "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
|
106 "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
|
107 "DATE:Date," + |
760
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
108 "VALUE:Double," + |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
109 "DESC:String"); |
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
|
110 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 } |
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
|
115 |
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 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
|
117 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
|
118 |
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 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
|
120 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
|
121 |
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 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 featureBuilder.add(pair.getA()); |
760
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
128 featureBuilder.add(value2description(asDouble(pair.getA()))); |
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
|
129 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
|
130 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
|
131 } |
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 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
|
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 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
|
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 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
|
138 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
|
139 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
|
140 (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
|
141 |
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 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
|
143 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
|
144 |
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 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
|
146 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
147 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
|
148 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
149 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
|
150 (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
|
151 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
|
152 |
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 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
|
154 |
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 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
|
156 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
|
157 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
|
158 } |
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
|
159 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
|
160 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
|
161 } |
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 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 } |
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 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
|
169 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
|
170 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 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
|
174 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 ) { |
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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 "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
|
190 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 |
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
|
192 |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
193 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
|
194 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
|
195 Collection<Result> data){ |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
196 String geomType = null; |
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
197 |
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
|
198 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
|
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 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
|
201 |
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 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
|
203 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
|
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 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
|
206 log.error(mue.getLocalizedMessage(), mue); |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
207 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
|
208 } |
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 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
|
211 |
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 |
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 (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
|
214 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
|
215 } |
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 |
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 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
|
218 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
|
219 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
|
220 FeatureCollections.newCollection(); |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
221 int j = 0; |
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
|
222 for (Result result: data) { |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
223 j++; |
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 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
|
225 Geometry g = wktReader.read(result.getString(0)); |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
226 ResultDescriptor rd = result.getResultDescriptor(); |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
227 int columns = rd.getColumnCount(); |
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
|
228 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
|
229 try { |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
230 geomType = g.getGeometryType().toUpperCase(); |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
231 String schema = "geom:"+g.getGeometryType()+":srid=4326"; |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
232 for (int i = 1; i < columns; i++){ |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
233 schema+=","+rd.getColumnName(i)+ |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
234 ":"+rd.getColumnClassName(i); |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
235 } |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
236 type = DataUtilities.createType(name, schema); |
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
|
237 } |
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 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
|
239 log.error(se.getLocalizedMessage(), se); |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
240 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
|
241 } |
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 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
|
243 } |
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 featureBuilder.add(g); |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
245 for (int i = 1; i < columns; i++){ |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
246 featureBuilder.add(result.getObject(i)); |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
247 } |
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
|
248 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
|
249 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
|
250 } catch (ParseException e) { |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
251 log.error("cannot create geometry "+j+" for "+result.getString(0)); |
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
|
252 } 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
|
253 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
|
254 } |
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 } |
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 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
|
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 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
|
260 |
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 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
|
262 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
|
263 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
|
264 (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
|
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 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
|
267 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
|
268 |
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 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
|
270 |
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 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
|
272 |
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 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
|
274 (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
|
275 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
|
276 |
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
|
277 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
|
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 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
|
280 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
|
281 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
|
282 } |
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
|
283 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
|
284 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
|
285 } |
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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 } |
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
|
292 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
|
293 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
|
294 } |
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
|
295 } |
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
|
296 |
655
6eccb68a8b99
Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents:
649
diff
changeset
|
297 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
|
298 |
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
|
299 } |
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
|
300 |
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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 ) { |
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
|
309 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
|
310 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 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
|
312 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
|
313 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 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
|
315 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
|
316 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
|
317 } |
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 |
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 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
|
320 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 |
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
|
322 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
|
323 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
|
324 } |
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
|
325 |
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
|
326 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
|
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 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
|
329 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
|
330 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
|
331 "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
|
332 "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
|
333 "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
|
334 "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
|
335 "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
|
336 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 } |
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
|
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 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
|
343 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
|
344 |
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 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
|
346 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
|
347 |
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 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
|
349 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
|
350 ) { |
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 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 } |
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 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
|
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 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
|
363 |
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 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
|
365 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
|
366 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
|
367 (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
|
368 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
369 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
|
370 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
|
371 |
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 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
|
373 |
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 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
|
375 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
376 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
|
377 (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
|
378 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
|
379 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
380 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
|
381 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 } |
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
|
386 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
|
387 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
|
388 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
395 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
|
396 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
|
397 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
400 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
|
401 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
407 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
|
408 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
|
409 } |
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
|
410 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
|
411 } |
760
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
412 |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
413 private static final String value2description(Double value) { |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
414 return format.format(value); |
f82e57a60124
Added a further column in the isolines shapefile to store a description used to be displayed as labels in a wms layer (issue209).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
727
diff
changeset
|
415 } |
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
|
416 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |