Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/ShapeFileWriter.java @ 806:2cea76f1112e
Added Javadoc in utils package.
gnv-artifacts/trunk@888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Apr 2010 13:10:39 +0000 |
parents | feeaf5aec552 |
children | f953c9a559d8 |
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 |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
30 import com.vividsolutions.jts.geom.Geometry; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
31 import com.vividsolutions.jts.geom.MultiLineString; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
32 import com.vividsolutions.jts.geom.MultiPolygon; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
33 import com.vividsolutions.jts.io.ParseException; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
34 import com.vividsolutions.jts.io.WKTReader; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
35 |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
36 import de.intevation.gnv.geobackend.base.Result; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
37 import de.intevation.gnv.geobackend.base.ResultDescriptor; |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
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 /** |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
40 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
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
|
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 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
49 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
50 * Precision used to format double values. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
51 */ |
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
|
52 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
|
53 |
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
|
54 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
|
55 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
|
56 } |
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
|
57 |
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
|
58 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
|
59 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
61 |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
62 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
63 * Write multilinestrings to shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
64 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
65 * @param shapeFile Shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
66 * @param parameterId The parameter id. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
67 * @param layer The layer. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
68 * @param date The date. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
69 * @param multiLineStrings The multilinestring. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
70 * @return true, if shapefile writing was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
71 */ |
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 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 ) { |
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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 date, |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
84 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
|
85 "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
|
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 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
88 |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
89 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
90 * Write multilinestrings to shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
91 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
92 * @param shapeFile Shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
93 * @param parameterId The parameter id. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
94 * @param layer The layer. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
95 * @param date The date. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
96 * @param multiLineStrings The multilinestring. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
97 * @param name A name. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
98 * @return true, if shapefile writing was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
99 */ |
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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 ) { |
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
|
108 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
|
109 |
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 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
|
111 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
|
112 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
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
|
118 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
|
119 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
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
|
121 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
|
122 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
|
123 } |
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
|
124 |
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
|
125 SimpleFeatureType TYPE; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
126 |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 "geom:MultiLineString:srid=4326," + |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
131 "PARAMETER:Integer," + |
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
|
132 "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
|
133 "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
|
134 "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
|
135 "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
|
136 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 } |
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
|
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 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
|
143 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
|
144 |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
145 FeatureCollection<SimpleFeatureType, SimpleFeature> 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
|
146 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
|
147 |
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 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 } |
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 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
159 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
|
160 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
161 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
|
162 |
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 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
|
164 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
|
165 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
|
166 (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
|
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 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
|
169 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
|
170 |
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 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
|
172 |
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 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
|
174 |
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 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
|
176 (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
|
177 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
|
178 |
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 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
|
180 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
181 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
|
182 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
|
183 success = true; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
184 } |
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
|
185 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
|
186 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
|
187 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
194 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
|
195 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
|
196 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 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
|
200 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
202 |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
203 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
204 * Write multipolygon to file. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
205 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
206 * @param shapeFile The shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
207 * @param parameterId The parameter id. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
208 * @param layer The layer. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
209 * @param date The date. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
210 * @param multiPolygons Multipolygons. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
211 * @return true, if shapefile writing was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
212 */ |
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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 ) { |
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
|
220 return writeMultiPolygonsToFile( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 date, |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
225 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
|
226 "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
|
227 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
229 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
230 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
231 * Write data to shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
232 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
233 * @param shapeFile The shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
234 * @param name The name. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
235 * @param data The data. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
236 * @param geometryType The geometry type. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
237 * @return true, if shapefile writing was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
238 */ |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
239 public static boolean 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
|
240 String name, |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
241 Collection<Result> data, |
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
242 String geometryType){ |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
243 |
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
|
244 WKTReader wktReader = new WKTReader(); |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
245 |
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
|
246 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
|
247 |
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 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
|
249 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
|
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 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
|
252 log.error(mue.getLocalizedMessage(), mue); |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
253 return false; |
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
|
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 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
|
257 |
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 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
|
260 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
|
261 } |
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 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
|
264 SimpleFeatureBuilder featureBuilder = null; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
265 FeatureCollection<SimpleFeatureType, SimpleFeature> collection = |
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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 if (type == null){ |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
275 try { |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
276 String schema = "geom:"+geometryType+":srid=4326"; |
727
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
277 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
|
278 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
|
279 ":"+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
|
280 } |
22dc921cd8b1
Added generic Export for all Columns which are in an ResultValue.
Tim Englich <tim.englich@intevation.de>
parents:
655
diff
changeset
|
281 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
|
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 (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
|
284 log.error(se.getLocalizedMessage(), se); |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
285 return false; |
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
|
286 } |
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 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
|
288 } |
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 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
|
290 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
|
291 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
|
292 } |
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
|
293 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
|
294 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
|
295 } 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
|
296 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
|
297 } 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
|
298 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
|
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 } |
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
|
301 |
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
|
302 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
|
303 |
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
|
304 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
|
305 |
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
|
306 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
|
307 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
|
308 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
|
309 (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
|
310 |
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
|
311 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
|
312 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
|
313 |
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
|
314 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
|
315 |
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
|
316 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
|
317 |
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
|
318 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
|
319 (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
|
320 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
|
321 |
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
|
322 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
|
323 |
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
|
324 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
|
325 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
|
326 success = true; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
327 } |
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
|
328 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
|
329 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
|
330 } |
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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 } |
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
|
337 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
|
338 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
|
339 } |
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
|
340 } |
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
|
341 |
799
feeaf5aec552
ISSUE213: Wrong Geometrytype used for the generation of an Layer with Multipolygon-Geometries
Tim Englich <tim.englich@intevation.de>
parents:
780
diff
changeset
|
342 return true; |
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
|
343 } |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
344 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
345 |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
346 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
347 * Write multipolygons to file. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
348 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
349 * @param shapeFile The shapefile. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
350 * @param parameterId The parameter id. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
351 * @param layer The layer. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
352 * @param date The date. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
353 * @param multiPolygons Multipolygons. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
354 * @param name A name. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
355 * @return true, if shapefile writing was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
356 */ |
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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 ) { |
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
|
365 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
|
366 |
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 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
|
368 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
|
369 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 |
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
|
375 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
|
376 |
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 |
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
|
378 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
|
379 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
|
380 } |
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
|
381 |
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
|
382 SimpleFeatureType TYPE; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
383 |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 "geom:MultiPolygon:srid=4326," + |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
388 "PARAMETER:Integer," + |
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 "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
|
390 "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
|
391 "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
|
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 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
|
394 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
|
395 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
|
396 } |
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
|
397 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
398 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
|
399 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
|
400 |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
401 FeatureCollection<SimpleFeatureType, SimpleFeature> 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
|
402 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
|
403 |
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 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
|
405 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
|
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 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
415 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
416 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
|
417 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
418 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
|
419 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 (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
|
424 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
425 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
|
426 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
|
427 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
428 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
|
429 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
430 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
|
431 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
432 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
|
433 (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
|
434 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
|
435 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
436 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
|
437 |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
438 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
|
439 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
|
440 success = true; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
441 } |
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
|
442 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
|
443 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
|
444 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
451 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
|
452 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
|
453 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
454 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
455 |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
456 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
|
457 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
458 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
459 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
460 * Returns an object as Double. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
461 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
462 * @param a An object. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
463 * @return Object <i>a</i> as Double. If <i>a</i> is not a double and no |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
464 * number, 0d is returned. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
465 */ |
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
|
466 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
|
467 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
|
468 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
|
469 } |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
465
diff
changeset
|
470 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
|
471 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
|
472 } |
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
|
473 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
|
474 } |
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
|
475 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
476 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
477 * Turns a double value into a string representation taking account of the |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
478 * locale. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
479 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
480 * @param value A double value. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
481 * @return The double value formatted as string. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
799
diff
changeset
|
482 */ |
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
|
483 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
|
484 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
|
485 } |
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
|
486 } |
f7038820df2e
Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
487 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |