Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java @ 3807:d73c43798a99 pre2.6-2011-11-04
merged flys-backend/pre2.6-2011-11-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:51 +0200 |
parents | 092e1e5020bc |
children | cbeeaaad1056 |
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; |
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
|
23 |
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
|
24 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
|
25 import org.geotools.data.FeatureStore; |
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.DefaultTransaction; |
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.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
|
28 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
|
29 import org.geotools.data.shapefile.ShapefileDataStoreFactory; |
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.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
|
31 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
|
32 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
|
33 import org.geotools.geojson.feature.FeatureJSON; |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
34 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
|
35 |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
36 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
|
37 |
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
|
38 |
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 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
|
40 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
41 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
|
42 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
43 |
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
|
44 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
|
45 } |
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
|
46 |
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
|
47 |
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
|
48 public static Envelope getRiverBoundary(String rivername) { |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
49 RiverAxis axis = RiverAxis.getRiverAxis(rivername); |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
50 if (axis != null) { |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
51 // TODO Take the correct EPSG into account. Maybe, we need to |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
52 // reproject the geometry. |
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
|
53 return axis.getGeom().getEnvelopeInternal(); |
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 } |
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
|
55 |
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
|
56 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
|
57 } |
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
|
58 |
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
|
59 |
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
|
60 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
|
61 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
|
62 |
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
|
63 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
|
64 return jtsBoundsToOLBounds(env); |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
65 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
66 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
67 return null; |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
68 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
69 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
70 |
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
|
71 /** |
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
|
72 * 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
|
73 * 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
|
74 * |
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
|
75 * @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
|
76 * |
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
|
77 * @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
|
78 */ |
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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 } |
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
|
86 |
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
|
87 |
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
|
88 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
|
89 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
|
90 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
|
91 |
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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 |
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
|
97 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
|
98 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
|
99 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
|
100 |
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
|
101 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
|
102 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
|
103 } |
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
|
104 |
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
|
105 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
|
106 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
|
107 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
|
108 |
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 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
|
110 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
|
111 } |
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 |
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 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
|
114 } |
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 |
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
|
117 public static SimpleFeatureType buildFeatureType( |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
118 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
|
119 { |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
120 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
|
121 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
122 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
123 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
124 /** |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
125 * 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
|
126 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
127 * @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
|
128 * @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
|
129 * @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
|
130 * @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
|
131 * 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
|
132 * as class. |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
133 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
134 * @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
|
135 */ |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
136 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
|
137 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
|
138 { |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
139 try { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
140 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
141 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
|
142 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
143 builder.setName("flys"); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
144 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
|
145 builder.setCRS(crs); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
146 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
|
147 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
148 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
|
149 |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
150 if (attrs != null) { |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
151 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
|
152 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
|
153 } |
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 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
156 return builder.buildFeatureType(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
157 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
158 catch (NoSuchAuthorityCodeException nsae) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
159 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
160 catch (FactoryException fe) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
161 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
162 |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
163 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
|
164 } |
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
|
165 |
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 |
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
|
167 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
|
168 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
|
169 ) { |
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
|
170 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
|
171 |
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
|
172 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
|
173 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
|
174 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
|
175 |
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
|
176 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
|
177 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
|
178 |
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
|
179 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
|
180 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
|
181 } |
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
|
182 } |
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 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
|
184 // 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
|
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 |
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 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
|
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 |
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 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
|
192 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
|
193 SimpleFeatureType featureType, |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
194 FeatureCollection collection |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
195 ) { |
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
|
196 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
|
197 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
|
198 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
|
199 } |
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
|
200 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
201 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
|
202 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
203 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
204 Map<String, Serializable> params = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
205 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
|
206 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
207 params.put("url", shape.toURI().toURL()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
208 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
|
209 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
210 DataStoreFactorySpi dataStoreFactory = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
211 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
|
212 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
213 ShapefileDataStore newDataStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
214 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
215 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
|
216 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
217 transaction = new DefaultTransaction("create"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
218 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
219 String typeName = newDataStore.getTypeNames()[0]; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
220 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
221 FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
222 (FeatureStore<SimpleFeatureType, SimpleFeature>) |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
223 newDataStore.getFeatureSource(typeName); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
224 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
225 featureStore.setTransaction(transaction); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
226 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
227 featureStore.addFeatures(collection); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
228 transaction.commit(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
229 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
230 return true; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
231 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
232 catch (MalformedURLException mue) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
233 logger.error("Unable to prepare shapefile: " + mue.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
234 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
235 catch (IOException ioe) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
236 logger.error("Unable to write shapefile: " + ioe.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
237 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
238 finally { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
239 if (transaction != null) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
240 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
241 logger.debug("XXX CLOSE TRANSACTION!"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
242 transaction.close(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
243 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
244 catch (IOException ioe) { /* do nothing */ } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
245 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
246 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
247 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
248 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
|
249 } |
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
|
250 } |
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
|
251 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |