Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java @ 3113:c04408ec4c9c
Do not automatically load q-facets outside of w_differences.
flys-artifacts/trunk@4712 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 19 Jun 2012 19:30:22 +0000 |
parents | 33aa37e6d98f |
children | f062b5a90e26 |
rev | line source |
---|---|
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.utils; |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
3 import java.io.IOException; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
4 import java.io.File; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
5 import java.io.Serializable; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
6 import java.net.MalformedURLException; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
7 import java.util.ArrayList; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
8 import java.util.HashMap; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
9 import java.util.List; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
10 import java.util.Map; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
11 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
12 import org.apache.log4j.Logger; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
13 |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import com.vividsolutions.jts.geom.Coordinate; |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
15 import com.vividsolutions.jts.geom.Envelope; |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import com.vividsolutions.jts.geom.Geometry; |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
18 import org.opengis.feature.simple.SimpleFeature; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
19 import org.opengis.feature.simple.SimpleFeatureType; |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
20 import org.opengis.referencing.FactoryException; |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
21 import org.opengis.referencing.NoSuchAuthorityCodeException; |
1107
005c2964f9af
Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1106
diff
changeset
|
22 import org.opengis.referencing.crs.CoordinateReferenceSystem; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
23 import org.opengis.referencing.operation.MathTransform; |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
24 import org.opengis.referencing.operation.TransformException; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
25 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
26 import org.geotools.data.DataStoreFactorySpi; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
27 import org.geotools.data.DefaultTransaction; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
28 import org.geotools.data.FeatureWriter; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
29 import org.geotools.data.Transaction; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
30 import org.geotools.data.shapefile.ShapefileDataStore; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
31 import org.geotools.data.shapefile.ShapefileDataStoreFactory; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
32 import org.geotools.data.simple.SimpleFeatureIterator; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
33 import org.geotools.feature.FeatureIterator; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
34 import org.geotools.feature.FeatureCollection; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
35 import org.geotools.feature.simple.SimpleFeatureTypeBuilder; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
36 import org.geotools.geojson.feature.FeatureJSON; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
37 import org.geotools.geometry.jts.JTS; |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
38 import org.geotools.referencing.CRS; |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
40 import de.intevation.flys.model.RiverAxis; |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
41 |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 public class GeometryUtils { |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
45 private static final Logger logger = Logger.getLogger(GeometryUtils.class); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
46 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
47 public static final String DEFAULT_EPSG = "EPSG:31467"; |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
48 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
49 |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 private GeometryUtils() { |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
54 public static Envelope getRiverBoundary(String rivername) { |
2078
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
55 List<RiverAxis> axes = RiverAxis.getRiverAxis(rivername); |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
56 if (axes != null && axes.size() > 0) { |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
57 Envelope max = null; |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
58 |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
59 for (RiverAxis axis: axes) { |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
60 // TODO Take the correct EPSG into account. Maybe, we need to |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
61 // reproject the geometry. |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
62 Envelope env = axis.getGeom().getEnvelopeInternal(); |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
63 |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
64 if (max == null) { |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
65 max = env; |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
66 } |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
67 else { |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
68 max.expandToInclude(env); |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
69 } |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
70 } |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
71 |
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
72 return max; |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
73 } |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
74 |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
75 return null; |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
76 } |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
77 |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
78 |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
79 public static String getRiverBounds(String rivername) { |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
80 Envelope env = getRiverBoundary(rivername); |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
81 |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
82 if (env == null) { |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
83 return jtsBoundsToOLBounds(env); |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
84 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
85 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
86 return null; |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
87 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
88 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
89 |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 /** |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
91 * Returns the boundary of Envelope <i>env</i> in OpenLayers |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 * representation. |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 * |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
94 * @param env The envelope of a geometry. |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 * |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
96 * @return the OpenLayers boundary of <i>env</i>. |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 */ |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
98 public static String jtsBoundsToOLBounds(Envelope env) { |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
99 return "" + |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
100 env.getMinX() + " " + |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
101 env.getMinY() + " " + |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
102 env.getMaxX() + " " + |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
103 env.getMaxY(); |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 } |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
105 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
106 |
1641
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
107 public static String createOLBounds(Geometry a, Geometry b) { |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
108 Coordinate[] ca = a.getCoordinates(); |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
109 Coordinate[] cb = b.getCoordinates(); |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
110 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
111 double lowerX = Double.MAX_VALUE; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
112 double lowerY = Double.MAX_VALUE; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
113 double upperX = -Double.MAX_VALUE; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
114 double upperY = -Double.MAX_VALUE; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
115 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
116 for (Coordinate c: ca) { |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
117 lowerX = lowerX < c.x ? lowerX : c.x; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
118 lowerY = lowerY < c.y ? lowerY : c.y; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
119 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
120 upperX = upperX > c.x ? upperX : c.x; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
121 upperY = upperY > c.y ? upperY : c.y; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
122 } |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
123 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
124 for (Coordinate c: cb) { |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
125 lowerX = lowerX < c.x ? lowerX : c.x; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
126 lowerY = lowerY < c.y ? lowerY : c.y; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
127 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
128 upperX = upperX > c.x ? upperX : c.x; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
129 upperY = upperY > c.y ? upperY : c.y; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
130 } |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
131 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
132 return "" + lowerX + " " + lowerY + " " + upperX + " " + upperY; |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
133 } |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
134 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
135 |
1107
005c2964f9af
Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1106
diff
changeset
|
136 public static SimpleFeatureType buildFeatureType( |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
137 String name, String srs, Class geometryType) |
1107
005c2964f9af
Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1106
diff
changeset
|
138 { |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
139 return buildFeatureType(name, srs, geometryType, null); |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
140 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
141 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
142 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
143 /** |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
144 * Creates a new SimpleFeatureType using a SimpleFeatureTypeBuilder. |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
145 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
146 * @param name The name of the FeatureType. |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
147 * @param srs The SRS (e.g. "EPSG:31466"). |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
148 * @param geometryType The geometry type's class (e.g. Polygon.class). |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
149 * @param attrs Optional. An object with attribute-name/attribute-class |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
150 * pairs where index 0 specifies the name as string and index 1 the type |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
151 * as class. |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
152 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
153 * @return a new SimpleFeatureType. |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
154 */ |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
155 public static SimpleFeatureType buildFeatureType( |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
156 String name, String srs, Class geometryType, Object[][] attrs) |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
157 { |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
158 try { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
159 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
160 CoordinateReferenceSystem crs = CRS.decode(srs); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
161 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
162 builder.setName("flys"); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
163 builder.setNamespaceURI("http://www.intevation.de/"); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
164 builder.setCRS(crs); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
165 builder.setSRS(srs); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
166 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
167 builder.add("geometry", geometryType, crs); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
168 |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
169 if (attrs != null) { |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
170 for (Object[] attr: attrs) { |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
171 builder.add((String) attr[0], (Class) attr[1]); |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
172 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
173 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
174 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
175 return builder.buildFeatureType(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
176 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
177 catch (NoSuchAuthorityCodeException nsae) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
178 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
179 catch (FactoryException fe) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
180 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
181 |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
182 return null; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
183 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
184 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
185 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
186 public static List<SimpleFeature> parseGeoJSON( |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
187 String geojson, SimpleFeatureType ft |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
188 ) { |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
189 List<SimpleFeature> collection = new ArrayList<SimpleFeature>(); |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
190 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
191 try { |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
192 FeatureJSON fjson = new FeatureJSON(); |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
193 fjson.setFeatureType(ft); |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
194 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
195 FeatureIterator<SimpleFeature> iterator = |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
196 fjson.streamFeatureCollection(geojson); |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
197 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
198 while (iterator.hasNext()) { |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
199 collection.add(iterator.next()); |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
200 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
201 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
202 catch (IOException ioe) { |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
203 // TODO handle exception |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
204 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
205 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
206 return collection; |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
207 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
208 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
209 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
210 public static boolean writeShapefile( |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
211 File shape, |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
212 SimpleFeatureType featureType, |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
213 FeatureCollection collection |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
214 ) { |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
215 return writeShapefile( |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
216 shape, featureType, collection, featureType.getCoordinateReferenceSystem()); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
217 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
218 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
219 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
220 public static boolean writeShapefile( |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
221 File shape, |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
222 SimpleFeatureType featureType, |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
223 FeatureCollection collection, |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
224 CoordinateReferenceSystem crs |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
225 ) { |
1164
0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1144
diff
changeset
|
226 if (collection.isEmpty()) { |
0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1144
diff
changeset
|
227 logger.warn("Shapefile is not written - no features given!"); |
0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1144
diff
changeset
|
228 return false; |
0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1144
diff
changeset
|
229 } |
0398c2b8dbaf
Do only create WSPLGEN and barrier facets if the WSPLGEN job has been added to the Scheduler and if there are digitized geometries existing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1144
diff
changeset
|
230 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
231 Transaction transaction = null; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
232 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
233 try { |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
234 MathTransform transform = CRS.findMathTransform( |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
235 CRS.decode(DEFAULT_EPSG), crs); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
236 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
237 Map<String, Serializable> params = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
238 new HashMap<String, Serializable>(); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
239 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
240 params.put("url", shape.toURI().toURL()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
241 params.put("create spatial index", Boolean.TRUE); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
242 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
243 DataStoreFactorySpi dataStoreFactory = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
244 new ShapefileDataStoreFactory(); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
245 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
246 ShapefileDataStore newDataStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
247 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
248 newDataStore.createSchema(featureType); |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
249 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
250 transaction = new DefaultTransaction("create"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
251 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
252 String typeName = newDataStore.getTypeNames()[0]; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
253 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
254 FeatureWriter<SimpleFeatureType, SimpleFeature> writer = |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
255 newDataStore.getFeatureWriter(typeName, transaction); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
256 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
257 SimpleFeatureIterator iterator = (SimpleFeatureIterator) collection.features(); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
258 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
259 while (iterator.hasNext()){ |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
260 SimpleFeature feature = iterator.next(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
261 SimpleFeature copy = writer.next(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
262 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
263 copy.setAttributes(feature.getAttributes()); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
264 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
265 Geometry orig = (Geometry) feature.getDefaultGeometry(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
266 Geometry reprojected = JTS.transform(orig, transform); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
267 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
268 copy.setDefaultGeometry(reprojected); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
269 writer.write(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
270 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
271 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
272 transaction.commit(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
273 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
274 return true; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
275 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
276 catch (MalformedURLException mue) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
277 logger.error("Unable to prepare shapefile: " + mue.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
278 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
279 catch (IOException ioe) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
280 logger.error("Unable to write shapefile: " + ioe.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
281 } |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
282 catch (NoSuchAuthorityCodeException nsae) { |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
283 logger.error("Cannot get CoordinateReferenceSystem for '" |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
284 + DEFAULT_EPSG + "'"); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
285 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
286 catch (FactoryException fe) { |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
287 logger.error("Cannot get CoordinateReferenceSystem for '" |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
288 + DEFAULT_EPSG + "'"); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
289 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
290 catch (TransformException te) { |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
291 logger.error("Was not able to transform geometry!", te); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
292 } |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
293 finally { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
294 if (transaction != null) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
295 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
296 transaction.close(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
297 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
298 catch (IOException ioe) { /* do nothing */ } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
299 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
300 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
301 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
302 return false; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
303 } |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
304 } |
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
305 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |