Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/utils/GeometryUtils.java @ 8587:07c9ac22f611
(issue1755) Generalise BedQuality result handling
The bedquality calculation now produces a result for each time period
which has BedQualityResultValues for each specific result type.
Formally this was split up in density, porosity and diameter classes
with some bedload diameter classes mixed in for extra fun.
The intent of this commit is to allow more shared code and generic
access patterns to the BedQuality results.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 18 Mar 2015 18:42:08 +0100 |
parents | e4606eae8ea5 |
children | e9d912c97fa8 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5434
diff
changeset
|
9 package org.dive4elements.river.utils; |
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
|
10 |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
11 import com.vividsolutions.jts.geom.Coordinate; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
12 import com.vividsolutions.jts.geom.Envelope; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
13 import com.vividsolutions.jts.geom.Geometry; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
14 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5434
diff
changeset
|
15 import org.dive4elements.river.model.RiverAxis; |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
16 |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
17 import java.io.File; |
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 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
26 import org.apache.log4j.Logger; |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
27 import org.geotools.data.DataStoreFactorySpi; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
28 import org.geotools.data.DefaultTransaction; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
29 import org.geotools.data.FeatureWriter; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
30 import org.geotools.data.Transaction; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
31 import org.geotools.data.shapefile.ShapefileDataStore; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
32 import org.geotools.data.shapefile.ShapefileDataStoreFactory; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
33 import org.geotools.data.simple.SimpleFeatureIterator; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
34 import org.geotools.feature.FeatureCollection; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
35 import org.geotools.feature.FeatureIterator; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
36 import org.geotools.feature.simple.SimpleFeatureTypeBuilder; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
37 import org.geotools.geojson.feature.FeatureJSON; |
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
38 import org.geotools.geometry.jts.JTS; |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
39 import org.geotools.geometry.jts.ReferencedEnvelope; |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
40 import org.geotools.referencing.CRS; |
5181
9d36ddf7dbd3
Change IllegalArgumentException to HibernateException.
Raimund Renkert <rrenkert@intevation.de>
parents:
5173
diff
changeset
|
41 import org.hibernate.HibernateException; |
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
|
42 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
|
43 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
|
44 import org.opengis.referencing.FactoryException; |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
45 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
|
46 import org.opengis.referencing.crs.CoordinateReferenceSystem; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
47 import org.opengis.referencing.operation.MathTransform; |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
48 import org.opengis.referencing.operation.TransformException; |
1106
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
49 |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 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
|
51 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
52 private static final Logger log = Logger.getLogger(GeometryUtils.class); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
53 |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
54 public static final String PREFIX_EPSG = "EPSG:"; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
55 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
56 public static final String DEFAULT_EPSG = "EPSG:31467"; |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
57 |
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
|
58 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
|
59 } |
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 |
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
|
61 public static Envelope getRiverBoundary(String rivername) { |
5170
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
62 try { |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
63 List<RiverAxis> axes = RiverAxis.getRiverAxis(rivername); |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
64 if (axes != null && axes.size() > 0) { |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
65 Envelope max = null; |
2078
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
66 |
5170
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
67 for (RiverAxis axis: axes) { |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
68 // TODO Take the correct EPSG into account. Maybe, we need to |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
69 // reproject the geometry. |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
70 Envelope env = axis.getGeom().getEnvelopeInternal(); |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
71 |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
72 if (max == null) { |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
73 max = env; |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
74 } |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
75 else { |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
76 max.expandToInclude(env); |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
77 } |
2078
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
78 } |
5170
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
79 |
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
80 return max; |
2078
cbeeaaad1056
#440 Support river axes that consist of more than a single geometry.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1774
diff
changeset
|
81 } |
5170
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
82 } |
5181
9d36ddf7dbd3
Change IllegalArgumentException to HibernateException.
Raimund Renkert <rrenkert@intevation.de>
parents:
5173
diff
changeset
|
83 catch(HibernateException iae) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
84 log.warn("Exception, no valid river axis found for " + rivername); |
5170
c1b60f8c3390
Made river mapfile generator more tolerant.
Raimund Renkert <rrenkert@intevation.de>
parents:
3306
diff
changeset
|
85 return null; |
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
|
86 } |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
87 log.warn("No valid river axis found for " + rivername); |
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
|
88 |
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
|
89 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
|
90 } |
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
91 |
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
|
92 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
|
93 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
|
94 |
3303
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
95 if (env != null) { |
1774
092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1641
diff
changeset
|
96 return jtsBoundsToOLBounds(env); |
1144
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
97 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
98 |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
99 return null; |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
100 } |
c07e9e9c7482
Set the river extent for WMSLayers in the FloodMapState.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1121
diff
changeset
|
101 |
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
|
102 /** |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
103 * Returns the boundary of Envelope <i>env</i> in OpenLayers representation. |
1052
eeebf8514c7f
The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 * |
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
|
105 * @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
|
106 * |
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
|
107 * @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
|
108 */ |
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
|
109 public static String jtsBoundsToOLBounds(Envelope env) { |
3303
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
110 StringBuilder buf = new StringBuilder(); |
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
111 buf.append(env.getMinX()); buf.append(' '); |
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
112 buf.append(env.getMinY()); buf.append(' '); |
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
113 buf.append(env.getMaxX()); buf.append(' '); |
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
114 buf.append(env.getMaxY()); |
96daa8a4c48f
Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents:
3301
diff
changeset
|
115 return buf.toString(); |
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
|
116 } |
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
|
117 |
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
|
118 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
|
119 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
|
120 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
|
121 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
131 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
|
132 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
|
133 } |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
134 |
eb3ab28d1c21
The extent of the WSPLGEN facets are now determined by the extent of the start and end CrossSectionTrack of the WSPLGEN calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1164
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 |
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
|
139 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
|
140 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
|
141 } |
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
|
142 |
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
|
143 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
|
144 } |
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
|
145 |
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
|
146 public static SimpleFeatureType buildFeatureType( |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
147 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
|
148 { |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
149 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
|
150 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
151 |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
152 /** |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
153 * 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
|
154 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
155 * @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
|
156 * @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
|
157 * @param geometryType The geometry type's class (e.g. Polygon.class). |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
158 * @param attrs Optional. An object with attribute-name/attribute-class pairs |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
159 * where index 0 specifies the name as string and index 1 the |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
160 * ype as class. |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
161 * |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
162 * @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
|
163 */ |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
164 public static SimpleFeatureType buildFeatureType(String name, String srs, |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
165 Class<?> geometryType, Object[][] attrs) { |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
166 try { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
167 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
168 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
|
169 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
170 builder.setName("flys"); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
171 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
|
172 builder.setCRS(crs); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
173 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
|
174 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
175 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
|
176 |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
177 if (attrs != null) { |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
178 for (Object[] attr: attrs) { |
3286
f062b5a90e26
Add showpointlabel style attribute
Christian Lins <christian.lins@intevation.de>
parents:
2762
diff
changeset
|
179 builder.add((String) attr[0], (Class<?>) attr[1]); |
1119
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
180 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
181 } |
faca1825818e
Write additional attributes ELEVATION and KILOMETER into crosssection track shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1108
diff
changeset
|
182 |
1108
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
183 return builder.buildFeatureType(); |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
184 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
185 catch (NoSuchAuthorityCodeException nsae) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
186 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
187 catch (FactoryException fe) { |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
188 } |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
189 |
5b1198c27d43
Export riveraxis and crosssections to shapefiles for WSPLGEN.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1107
diff
changeset
|
190 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
|
191 } |
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 |
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 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
|
194 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
|
195 ) { |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
196 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
|
197 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
202 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
|
203 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
|
204 |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
205 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
|
206 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
|
207 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
208 } |
e9f66d63bdd0
Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1052
diff
changeset
|
209 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
|
210 // 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
|
211 } |
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 |
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
|
213 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
|
214 } |
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
|
215 |
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 |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
217 /** |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
218 * This method returns the {@link CoordinateReferenceSystem} by the |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
219 * {@link String} <i>epsg</i>. |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
220 * |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
221 * @param epsg An EPSG code like <b>EPSG:31466</b> |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
222 * |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
223 * @return the {@link CoordinateReferenceSystem} specified by <i>epsg</i>. |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
224 */ |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
225 public static CoordinateReferenceSystem getCoordinateReferenceSystem( |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
226 String epsg |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
227 ) { |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
228 if (epsg == null) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
229 log.warn("cannot create CoordinateReferenceSystem with null"); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
230 return null; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
231 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
232 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
233 if (!epsg.startsWith(PREFIX_EPSG)) { |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
234 epsg = PREFIX_EPSG + epsg; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
235 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
236 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
237 try { |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
238 return CRS.decode(epsg); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
239 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
240 catch (FactoryException fe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
241 log.error( |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
242 "unable to get CoordinateReferenceSystem for: " + epsg, |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
243 fe); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
244 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
245 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
246 return null; |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
247 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
248 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
249 |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
250 public static Envelope transform(Envelope orig, String targetSrs) { |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
251 return transform(orig, targetSrs, DEFAULT_EPSG); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
252 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
253 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
254 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
255 public static Envelope transform( |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
256 Envelope orig, |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
257 String targetSrs, |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
258 String origSrs |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
259 ) { |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
260 if (targetSrs == null || orig == null || origSrs == null) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
261 log.warn("unable to transform envelope: empty parameters"); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
262 return orig; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
263 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
264 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
265 log.debug("Transform envlope to '" + targetSrs + "'"); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
266 try { |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
267 CoordinateReferenceSystem sourceCRS = |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
268 getCoordinateReferenceSystem(origSrs); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
269 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
270 CoordinateReferenceSystem targetCRS = |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
271 getCoordinateReferenceSystem(targetSrs); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
272 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
273 if (sourceCRS != null && targetCRS != null) { |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
274 ReferencedEnvelope tmpEnv = |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
275 new ReferencedEnvelope(orig, CRS.decode(origSrs)); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
276 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
277 Envelope target = tmpEnv.transform(targetCRS, false); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
278 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
279 if (log.isDebugEnabled()) { |
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
280 log.debug(" orig envelope : " + orig); |
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
281 log.debug(" transformed envelope: " + target); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
282 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
283 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
284 return target; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
285 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
286 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
287 catch (NoSuchAuthorityCodeException nsae) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
288 log.error("Cannot get CoordinateReferenceSystem!", nsae); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
289 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
290 catch (FactoryException fe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
291 log.error("Cannot get CoordinateReferenceSystem!", fe); |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
292 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
293 catch (TransformException te) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
294 log.error("Cannot transform envelope from source " |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
295 + origSrs + " to target srs " + targetSrs); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
296 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
297 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
298 return null; |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
299 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
300 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
301 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
302 public static boolean writeShapefile(File shape, |
3306
1b41dc00b1f7
Create shapefile directory instead of shapefile 'file'
Christian Lins <christian.lins@intevation.de>
parents:
3303
diff
changeset
|
303 SimpleFeatureType featureType, FeatureCollection<?, ?> collection) { |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
304 return writeShapefile(shape, featureType, collection, |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
305 featureType.getCoordinateReferenceSystem()); |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
306 } |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
307 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
308 |
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
309 public static boolean writeShapefile(File shape, |
3306
1b41dc00b1f7
Create shapefile directory instead of shapefile 'file'
Christian Lins <christian.lins@intevation.de>
parents:
3303
diff
changeset
|
310 SimpleFeatureType featureType, FeatureCollection<?, ?> collection, |
3301
c8f670ae96e8
Create extent of a map layer in the correct coordinate reference system.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3286
diff
changeset
|
311 CoordinateReferenceSystem crs) { |
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
|
312 if (collection.isEmpty()) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
313 log.warn("Shapefile is not written - no features given!"); |
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
|
314 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
|
315 } |
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
|
316 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
317 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
|
318 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
319 try { |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
320 MathTransform transform = CRS.findMathTransform( |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
321 CRS.decode(DEFAULT_EPSG), crs); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
322 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
323 Map<String, Serializable> params = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
324 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
|
325 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
326 params.put("url", shape.toURI().toURL()); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
327 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
|
328 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
329 DataStoreFactorySpi dataStoreFactory = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
330 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
|
331 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
332 ShapefileDataStore newDataStore = |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
333 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
334 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
|
335 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
336 transaction = new DefaultTransaction("create"); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
337 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
338 String typeName = newDataStore.getTypeNames()[0]; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
339 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
340 FeatureWriter<SimpleFeatureType, SimpleFeature> writer = |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
341 newDataStore.getFeatureWriter(typeName, transaction); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
342 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
343 SimpleFeatureIterator iterator = (SimpleFeatureIterator) collection.features(); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
344 |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
345 while (iterator.hasNext()){ |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
346 SimpleFeature feature = iterator.next(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
347 SimpleFeature copy = writer.next(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
348 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
349 copy.setAttributes(feature.getAttributes()); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
350 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
351 Geometry orig = (Geometry) feature.getDefaultGeometry(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
352 Geometry reprojected = JTS.transform(orig, transform); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
353 |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
354 copy.setDefaultGeometry(reprojected); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
355 writer.write(); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
356 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
357 |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
358 transaction.commit(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
359 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
360 return true; |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
361 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
362 catch (MalformedURLException mue) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
363 log.error("Unable to prepare shapefile: " + mue.getMessage()); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
364 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
365 catch (IOException ioe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
366 log.error("Unable to write shapefile: " + ioe.getMessage()); |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
367 } |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
368 catch (NoSuchAuthorityCodeException nsae) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
369 log.error("Cannot get CoordinateReferenceSystem for '" |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
370 + DEFAULT_EPSG + "'"); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
371 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
372 catch (FactoryException fe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
373 log.error("Cannot get CoordinateReferenceSystem for '" |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
374 + DEFAULT_EPSG + "'"); |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
375 } |
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
376 catch (TransformException te) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7642
diff
changeset
|
377 log.error("Was not able to transform geometry!", te); |
2762
33aa37e6d98f
Reproject geometries before exporting them as shapefiles to filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2078
diff
changeset
|
378 } |
1121
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
379 finally { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
380 if (transaction != null) { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
381 try { |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
382 transaction.close(); |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
383 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
384 catch (IOException ioe) { /* do nothing */ } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
385 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
386 } |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
387 |
66783d957201
Close open shapefile transactions properly.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1119
diff
changeset
|
388 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
|
389 } |
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
|
390 } |
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
|
391 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |