Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
1106:e9f66d63bdd0 | 1107:005c2964f9af |
---|---|
12 import com.vividsolutions.jts.geom.Coordinate; | 12 import com.vividsolutions.jts.geom.Coordinate; |
13 import com.vividsolutions.jts.geom.Geometry; | 13 import com.vividsolutions.jts.geom.Geometry; |
14 | 14 |
15 import org.opengis.feature.simple.SimpleFeature; | 15 import org.opengis.feature.simple.SimpleFeature; |
16 import org.opengis.feature.simple.SimpleFeatureType; | 16 import org.opengis.feature.simple.SimpleFeatureType; |
17 import org.opengis.referencing.crs.CoordinateReferenceSystem; | |
17 | 18 |
18 import org.geotools.data.DataStoreFactorySpi; | 19 import org.geotools.data.DataStoreFactorySpi; |
19 import org.geotools.data.DataUtilities; | |
20 import org.geotools.data.FeatureStore; | 20 import org.geotools.data.FeatureStore; |
21 import org.geotools.data.DefaultTransaction; | 21 import org.geotools.data.DefaultTransaction; |
22 import org.geotools.data.Transaction; | 22 import org.geotools.data.Transaction; |
23 import org.geotools.data.shapefile.ShapefileDataStore; | 23 import org.geotools.data.shapefile.ShapefileDataStore; |
24 import org.geotools.data.shapefile.ShapefileDataStoreFactory; | 24 import org.geotools.data.shapefile.ShapefileDataStoreFactory; |
25 import org.geotools.feature.FeatureIterator; | 25 import org.geotools.feature.FeatureIterator; |
26 import org.geotools.feature.FeatureCollection; | 26 import org.geotools.feature.FeatureCollection; |
27 import org.geotools.feature.SchemaException; | 27 import org.geotools.feature.SchemaException; |
28 import org.geotools.feature.simple.SimpleFeatureTypeBuilder; | 28 import org.geotools.feature.simple.SimpleFeatureTypeBuilder; |
29 import org.geotools.geojson.feature.FeatureJSON; | 29 import org.geotools.geojson.feature.FeatureJSON; |
30 import org.geotools.referencing.crs.DefaultGeographicCRS; | |
31 | 30 |
32 | 31 |
33 public class GeometryUtils { | 32 public class GeometryUtils { |
34 | 33 |
35 private GeometryUtils() { | 34 private GeometryUtils() { |
53 | 52 |
54 return "" + c[0].x + " " + c[1].y + " " + c[1].x + " " + c[0].y; | 53 return "" + c[0].x + " " + c[1].y + " " + c[1].x + " " + c[0].y; |
55 } | 54 } |
56 | 55 |
57 | 56 |
58 /** | 57 public static SimpleFeatureType buildFeatureType( |
59 * Returns a SimpleFeatureType used while parsing the GeoJSON string that | 58 String name, |
60 * represents the barriers entered by the user. | 59 String srs, |
61 * | 60 Class geometryType, |
62 * @param srs The SRS that is used by the GeoJSON string. | 61 CoordinateReferenceSystem crs) |
63 * | 62 throws SchemaException |
64 * @return a SimpleFeatureType. | 63 { |
65 */ | |
66 public static SimpleFeatureType buildBarriersFeatureType(String srs) { | |
67 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); | 64 SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); |
68 | 65 |
69 builder.setName("flys"); | 66 builder.setName("flys"); |
70 builder.setNamespaceURI("http://www.intevation.de/"); | 67 builder.setNamespaceURI("http://www.intevation.de/"); |
68 builder.setCRS(crs); | |
71 builder.setSRS(srs); | 69 builder.setSRS(srs); |
72 builder.setDefaultGeometry("geometry"); | |
73 | 70 |
74 builder.add("geometry", org.opengis.geometry.Geometry.class); | 71 builder.add("geometry", geometryType, crs); |
75 | 72 |
76 return builder.buildFeatureType(); | 73 return builder.buildFeatureType(); |
77 } | |
78 | |
79 | |
80 public static SimpleFeatureType buildFeatureType( | |
81 String name, String srid, String geometryType) | |
82 throws SchemaException | |
83 { | |
84 String schema = "geom:" + geometryType + ":srid=" + srid; | |
85 | |
86 return DataUtilities.createType(name, schema); | |
87 } | 74 } |
88 | 75 |
89 | 76 |
90 public static List<SimpleFeature> parseGeoJSON( | 77 public static List<SimpleFeature> parseGeoJSON( |
91 String geojson, SimpleFeatureType ft | 78 String geojson, SimpleFeatureType ft |
123 | 110 |
124 DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory(); | 111 DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory(); |
125 | 112 |
126 ShapefileDataStore newDataStore = | 113 ShapefileDataStore newDataStore = |
127 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); | 114 (ShapefileDataStore)dataStoreFactory.createNewDataStore(params); |
128 | |
129 newDataStore.createSchema(featureType); | 115 newDataStore.createSchema(featureType); |
130 newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84); | |
131 | 116 |
132 Transaction transaction = new DefaultTransaction("create"); | 117 Transaction transaction = new DefaultTransaction("create"); |
133 | 118 |
134 String typeName = newDataStore.getTypeNames()[0]; | 119 String typeName = newDataStore.getTypeNames()[0]; |
135 | 120 |