annotate flys-artifacts/src/main/java/de/intevation/flys/utils/GeometryUtils.java @ 1107:005c2964f9af

Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles. flys-artifacts/trunk@2610 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Aug 2011 14:13:06 +0000
parents e9f66d63bdd0
children 5b1198c27d43
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
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
12 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
13 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
14
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
15 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
16 import org.opengis.feature.simple.SimpleFeatureType;
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
17 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
18
e9f66d63bdd0 Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1052
diff changeset
19 import org.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
20 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
21 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
22 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
23 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
24 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
25 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
26 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
27 import org.geotools.feature.SchemaException;
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.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
29 import org.geotools.geojson.feature.FeatureJSON;
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
30
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
31
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
32 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
33
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 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
35 }
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
36
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 /**
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 * 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
40 * 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
41 *
eeebf8514c7f The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 * @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
43 *
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 * @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
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 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
47 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
48
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
49 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
50 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
51 }
eeebf8514c7f The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
eeebf8514c7f The boundary (extent) for the river axis is determined based on its geometry - this extent is written into the wms facet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 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
54 }
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
55
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
56
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
57 public static SimpleFeatureType buildFeatureType(
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
58 String name,
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
59 String srs,
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
60 Class geometryType,
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
61 CoordinateReferenceSystem crs)
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
62 throws SchemaException
005c2964f9af Use the correct SRID while reading GeoJSON barriers and writing line/polygon shapefiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1106
diff changeset
63 {
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
64 SimpleFeatureTypeBuilder builder = new 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
65
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
66 builder.setName("flys");
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
67 builder.setNamespaceURI("http://www.intevation.de/");
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
68 builder.setCRS(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
69 builder.setSRS(srs);
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
70
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
71 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
72
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
73 return builder.buildFeatureType();
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
74 }
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
75
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
76
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 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
78 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
79 ) {
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
80 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
81
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
82 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
83 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
84 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
85
e9f66d63bdd0 Write user defined barriers into a shapefile that is placed in the Artifact's directory.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1052
diff changeset
86 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
87 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
88
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
89 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
90 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
91 }
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
92 }
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
93 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
94 // 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
95 }
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
96
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
97 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
98 }
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
99
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
100
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
101 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
102 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
103 SimpleFeatureType featureType,
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
104 FeatureCollection 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
105 throws MalformedURLException, 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
106 {
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
107 Map<String, Serializable> params = new HashMap<String, 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
108 params.put("url", shape.toURI().toURL());
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
109 params.put("create spatial index", Boolean.TRUE);
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
110
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
111 DataStoreFactorySpi dataStoreFactory = new 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
112
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
113 ShapefileDataStore newDataStore =
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
114 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
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
115 newDataStore.createSchema(featureType);
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
116
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 Transaction transaction = new DefaultTransaction("create");
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
118
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
119 String typeName = newDataStore.getTypeNames()[0];
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
120
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
121 FeatureStore<SimpleFeatureType, SimpleFeature> 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
122 (FeatureStore<SimpleFeatureType, 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
123 newDataStore.getFeatureSource(typeName);
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
124
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
125 featureStore.setTransaction(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
126
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
127 featureStore.addFeatures(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
128 transaction.commit();
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
129
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
130 return true;
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
131 }
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
132 }
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
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org