Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java @ 1649:74142aa5d938
Improved WSPLGEN start to suppress inconsistent Artifact states.
flys-artifacts/trunk@2836 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 27 Sep 2011 11:33:45 +0000 |
parents | eb3ab28d1c21 |
children | 092e1e5020bc |
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; |
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
|
15 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
|
16 |
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
|
17 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
|
18 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
|
19 import org.opengis.referencing.FactoryException; |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
20 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
|
21 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
|
22 |
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 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
35 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
|
36 |
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
|
37 |
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 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
|
39 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
40 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
|
41 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
42 |
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
|
43 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
|
44 } |
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 |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
47 public static String getRiverBounds(String rivername) { |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
48 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
|
49 if (axis != null) { |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
50 // 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
|
51 // reproject the geometry. |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
52 Geometry geom = axis.getGeom().getBoundary(); |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
53 return jtsBoundsToOLBounds(geom); |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
54 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
55 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
56 return null; |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
57 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
58 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
59 |
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
|
60 /** |
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
|
61 * Returns the boundary of Geometry <i>geom</i> in OpenLayers |
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
|
62 * 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
|
63 * |
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
|
64 * @param geom The 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
|
65 * |
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
|
66 * @return the OpenLayers boundary of <i>geom</i>. |
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
|
67 */ |
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
|
68 public static String jtsBoundsToOLBounds(Geometry geom) { |
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
|
69 Coordinate[] c = geom != null ? geom.getCoordinates() : null; |
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
|
70 |
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 if (c == null || c.length < 2) { |
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
|
72 return null; |
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 } |
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 |
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
|
75 return "" + c[0].x + " " + c[1].y + " " + c[1].x + " " + c[0].y; |
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 } |
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
|
77 |
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
|
78 |
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
|
79 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
|
80 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
|
81 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
|
82 |
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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 |
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 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
|
89 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
|
90 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
|
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 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
|
93 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
|
94 } |
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 |
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 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
|
97 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
|
98 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
|
99 |
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 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
|
101 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
|
102 } |
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 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
|
105 } |
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 |
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 |
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
|
108 public static SimpleFeatureType buildFeatureType( |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
109 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
|
110 { |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
111 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
|
112 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
113 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
114 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
115 /** |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
116 * 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
|
117 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
118 * @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
|
119 * @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
|
120 * @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
|
121 * @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
|
122 * 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
|
123 * as class. |
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 * @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
|
126 */ |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
127 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
|
128 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
|
129 { |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
130 try { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
131 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
132 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
|
133 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
134 builder.setName("flys"); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
135 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
|
136 builder.setCRS(crs); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
137 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
|
138 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
139 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
|
140 |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
141 if (attrs != null) { |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
142 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
|
143 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
|
144 } |
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 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
147 return builder.buildFeatureType(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
148 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
149 catch (NoSuchAuthorityCodeException nsae) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
150 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
151 catch (FactoryException fe) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
152 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
153 |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
154 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
|
155 } |
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
|
156 |
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
|
157 |
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
|
158 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
|
159 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
|
160 ) { |
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 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
|
162 |
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
|
163 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
|
164 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
|
165 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
|
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 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
|
168 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
|
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 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
|
171 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
|
172 } |
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 } |
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 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
|
175 // 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
|
176 } |
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 |
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 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
|
179 } |
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 |
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 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
|
183 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
|
184 SimpleFeatureType featureType, |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
185 FeatureCollection collection |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
186 ) { |
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
|
187 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
|
188 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
|
189 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
|
190 } |
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
|
191 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
192 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
|
193 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
194 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
195 Map<String, Serializable> params = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
196 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
|
197 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
198 params.put("url", shape.toURI().toURL()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
199 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
|
200 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
201 DataStoreFactorySpi dataStoreFactory = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
202 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
|
203 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
204 ShapefileDataStore newDataStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
205 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
206 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
|
207 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
208 transaction = new DefaultTransaction("create"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
209 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
210 String typeName = newDataStore.getTypeNames()[0]; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
211 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
212 FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
213 (FeatureStore<SimpleFeatureType, SimpleFeature>) |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
214 newDataStore.getFeatureSource(typeName); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
215 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
216 featureStore.setTransaction(transaction); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
217 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
218 featureStore.addFeatures(collection); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
219 transaction.commit(); |
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 return true; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
222 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
223 catch (MalformedURLException mue) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
224 logger.error("Unable to prepare shapefile: " + mue.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
225 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
226 catch (IOException ioe) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
227 logger.error("Unable to write shapefile: " + ioe.getMessage()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
228 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
229 finally { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
230 if (transaction != null) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
231 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
232 logger.debug("XXX CLOSE TRANSACTION!"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
233 transaction.close(); |
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) { /* do nothing */ } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
236 } |
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 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
239 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
|
240 } |
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
|
241 } |
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
|
242 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |