attrDesc = schema
.getAttributeDescriptors();
- if (attrDesc == null || attrDesc.size() == 0) {
+ if ((attrDesc == null) || (attrDesc.size() == 0)) {
return null;
}
diff --git a/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Import88DLocationsUtil.java b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Import88DLocationsUtil.java
index 573a0aadd5..cf6831fad5 100644
--- a/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Import88DLocationsUtil.java
+++ b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Import88DLocationsUtil.java
@@ -14,7 +14,6 @@ import java.util.Set;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
-import com.raytheon.edex.common.shapefiles.Shapefile;
import com.raytheon.edex.plugin.radar.dao.RadarStationDao;
import com.raytheon.uf.common.dataplugin.radar.RadarStation;
import com.raytheon.uf.common.localization.IPathManager;
diff --git a/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/common/shapefiles/Shapefile.java b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Shapefile.java
similarity index 95%
rename from edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/common/shapefiles/Shapefile.java
rename to edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Shapefile.java
index 24878f72f1..f7a14fe356 100644
--- a/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/common/shapefiles/Shapefile.java
+++ b/edexOsgi/com.raytheon.edex.plugin.radar/src/com/raytheon/edex/plugin/radar/util/Shapefile.java
@@ -1,4 +1,4 @@
-package com.raytheon.edex.common.shapefiles;
+package com.raytheon.edex.plugin.radar.util;
import java.io.File;
import java.io.IOException;
@@ -15,13 +15,13 @@ import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFactorySpi;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.DefaultTransaction;
-import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
-import org.geotools.feature.FeatureCollection;
-import org.geotools.feature.FeatureCollections;
+import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureSource;
+import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
@@ -37,7 +37,7 @@ import com.vividsolutions.jts.geom.Geometry;
* Represents a shape file. Basically a convenience function to simplify the
* tasks of reading/writing shapefiles (using GeoTools). Most of the shapefile
* reading/writing/editing code has been copied or adapted from the GeoTools
- * tutorials which come with the GeoToolssoftware.
+ * tutorials which come with the GeoTools software.
*
* Typical usage (reads a shapefile, get an attribute, adds a new attribute
* column, then writes it):
@@ -53,7 +53,8 @@ import com.vividsolutions.jts.geom.Geometry;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
- * 10Oct2011 10520 JWork Initial check-in.
+ * 10Oct2011 10520 JWork Initial check-in.
+ * 11Mar2014 #2718 randerso Changes for GeoTools 10.5
*
*
*/
@@ -81,7 +82,7 @@ public class Shapefile {
* The FeatureSource for this shapefile, required as a template for writing
* shapefiles
*/
- private FeatureSource theFeatureSource;
+ private SimpleFeatureSource theFeatureSource;
/** Optional column used to store object ids (by default will use FID). */
private String theIDColumn = null;
@@ -170,9 +171,11 @@ public class Shapefile {
}
// Check the input values are ok
List badIDs = new ArrayList();
- for (String i : attributeValues.keySet())
- if (!this.theFeaturesMap.containsKey(i))
+ for (String i : attributeValues.keySet()) {
+ if (!this.theFeaturesMap.containsKey(i)) {
badIDs.add(i);
+ }
+ }
if (badIDs.size() > 0) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(
@@ -245,8 +248,7 @@ public class Shapefile {
String typeName = typeNames[0];
this.theFeatureSource = dataStore.getFeatureSource(typeName);
- FeatureCollection collection = theFeatureSource
- .getFeatures();
+ SimpleFeatureCollection collection = theFeatureSource.getFeatures();
FeatureIterator iterator = collection.features();
try {
@@ -255,11 +257,12 @@ public class Shapefile {
// Set the feature's ID
String id = null;
try {
- if (this.theIDColumn != null)
+ if (this.theIDColumn != null) {
id = (String) feature
.getAttribute(this.theIDColumn);
- else
+ } else {
id = feature.getID();
+ }
} catch (ClassCastException e) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler
@@ -335,8 +338,7 @@ public class Shapefile {
// Check the output file can be written to
File outFile = new File(anOutputFileName);
// Create a feature collection to write the features out to
- FeatureCollection outFeatures = FeatureCollections
- .newCollection();
+ DefaultFeatureCollection outFeatures = new DefaultFeatureCollection();
for (SimpleFeature simpleFeature : this.theFeaturesMap.values()) {
outFeatures.add(simpleFeature);
}
@@ -459,10 +461,11 @@ public class Shapefile {
* Make sure there are some features in this Shapefile, return false if not.
*/
private boolean checkFeatures() {
- if (this.theFeaturesMap == null || this.theFeaturesMap.size() == 0)
+ if ((this.theFeaturesMap == null) || (this.theFeaturesMap.size() == 0)) {
return false;
- else
+ } else {
return true;
+ }
}
/**
diff --git a/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/output/Shapefile.java b/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/output/Shapefile.java
index b8a0bebb2c..83a3fd986b 100644
--- a/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/output/Shapefile.java
+++ b/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/output/Shapefile.java
@@ -26,10 +26,10 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.geotools.data.FeatureStore;
import org.geotools.data.FeatureWriter;
import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.data.store.ContentFeatureSource;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -44,9 +44,10 @@ import com.vividsolutions.jts.geom.Point;
*
*
* SOFTWARE HISTORY
- * Date PR# Engineer Description
- * ----------- ---------- ------------ --------------------------
- * Apr 11, 2007 njensen Initial Creation
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 11, 2007 njensen Initial Creation
+ * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
*
*
*/
@@ -137,15 +138,15 @@ public class Shapefile extends ScriptTask {
// Load up the datastore
ShapefileDataStore shpDS = new ShapefileDataStore(theShape.toURI()
- .toURL(), null, true);
+ .toURL());
+ shpDS.setMemoryMapped(true);
// Tell the datastore to create the dbf schema if it does not
// exist
shpDS.createSchema(featureType);
// Get the transaction object
- FeatureStore fs = (FeatureStore) shpDS
- .getFeatureSource();
+ ContentFeatureSource fs = shpDS.getFeatureSource();
Transaction trx = fs.getTransaction();
// Open a feature writer with the transaction
@@ -161,8 +162,8 @@ public class Shapefile extends ScriptTask {
// iterate through all
for (Map.Entry> entry : shapefileAttributes
.entrySet()) {
- feature.setAttribute(entry.getKey(), entry.getValue().get(
- counter));
+ feature.setAttribute(entry.getKey(),
+ entry.getValue().get(counter));
}
feature.setDefaultGeometry(collection.getGeometryN(counter));
diff --git a/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/query/ShapefileQuery.java b/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/query/ShapefileQuery.java
index 52eacfe776..5107a906ec 100644
--- a/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/query/ShapefileQuery.java
+++ b/edexOsgi/com.raytheon.edex.uengine/src/com/raytheon/edex/uengine/tasks/query/ShapefileQuery.java
@@ -29,9 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
-import org.geotools.data.DefaultQuery;
-import org.geotools.data.shapefile.indexed.IndexType;
-import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
+import org.geotools.data.Query;
+import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureIterator;
@@ -53,9 +52,10 @@ import com.raytheon.uf.common.geospatial.MapUtil;
*
*
* SOFTWARE HISTORY
- * Date PR# Engineer Description
- * ----------- ---------- ------------ --------------------------
- * Apr 11, 2007 njensen Initial Creation
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 11, 2007 njensen Initial Creation
+ * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
*
*
*/
@@ -93,9 +93,8 @@ public class ShapefileQuery extends ScriptTask {
logger.warn("Querying shapeFile: " + theShape.getAbsolutePath());
Map> resultMap = new HashMap>();
try {
- IndexedShapefileDataStore shpDS;
- shpDS = new IndexedShapefileDataStore(theShape.toURI().toURL(),
- null, false, false, IndexType.QIX);
+ ShapefileDataStore shpDS;
+ shpDS = new ShapefileDataStore(theShape.toURI().toURL());
// Load up the schema attributes into memory
List at = new ArrayList();
@@ -119,7 +118,7 @@ public class ShapefileQuery extends ScriptTask {
// Get the types
String[] types = shpDS.getTypeNames();
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
// Query geom
query.setTypeName(types[0]);
diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java
index 4b8187b33b..4b663a11d0 100644
--- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java
+++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java
@@ -47,6 +47,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* ------------ ---------- ----------- --------------------------
* Dec 5, 2012 bsteffen Initial creation.
* Jun 21, 2013 2132 mpduf createSubEnvelopeFromLatLon now uses East/West direction.
+ * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
*
*
*
@@ -209,10 +210,10 @@ public class EnvelopeUtils {
AbstractProvider.CENTRAL_MERIDIAN.getName().getCode())
.doubleValue();
}
- while (latLon.x < centralMeridian - 180.0) {
+ while (latLon.x < (centralMeridian - 180.0)) {
latLon.x += 360.0;
}
- while (latLon.x > centralMeridian + 180.0) {
+ while (latLon.x > (centralMeridian + 180.0)) {
latLon.x -= 360.0;
}
return latLon;
@@ -284,7 +285,7 @@ public class EnvelopeUtils {
CoordinateReferenceSystem crs, Coordinate latLon1,
Coordinate latLon2) {
try {
- ReferencedEnvelope e = new ReferencedEnvelope(crs);
+ ReferencedEnvelope e = ReferencedEnvelope.create(crs);
latLon1 = normalizeLongitude(e, latLon1);
latLon2 = normalizeLongitude(e, latLon2);
@@ -308,7 +309,7 @@ public class EnvelopeUtils {
}
return e;
} catch (FactoryException e) {
- return new ReferencedEnvelope(crs);
+ return ReferencedEnvelope.create(crs);
}
}
@@ -339,7 +340,8 @@ public class EnvelopeUtils {
*/
public static ReferencedEnvelope createLatLonEnvelope(Coordinate latLon1,
Coordinate latLon2) {
- ReferencedEnvelope e = new ReferencedEnvelope(MapUtil.LATLON_PROJECTION);
+ ReferencedEnvelope e = ReferencedEnvelope
+ .create(MapUtil.LATLON_PROJECTION);
e.expandToInclude(latLon1);
e.expandToInclude(latLon2);
return e;
diff --git a/edexOsgi/com.raytheon.uf.common.json/src/com/raytheon/uf/common/json/geo/GeoJsonMapUtil.java b/edexOsgi/com.raytheon.uf.common.json/src/com/raytheon/uf/common/json/geo/GeoJsonMapUtil.java
index 6b06ac4b09..42510531d1 100644
--- a/edexOsgi/com.raytheon.uf.common.json/src/com/raytheon/uf/common/json/geo/GeoJsonMapUtil.java
+++ b/edexOsgi/com.raytheon.uf.common.json/src/com/raytheon/uf/common/json/geo/GeoJsonMapUtil.java
@@ -71,836 +71,848 @@ import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
+ * GeoJson Map Utilities
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Aug 9, 2011 bclement Initial creation
+ * Mar 11, 2014 #2718 randerso Changes for GeoTools 10.5
+ *
+ *
*
* @author bclement
* @version 1.0
*/
public class GeoJsonMapUtil {
- public enum FeatureOpt {
- ENCODE_CRS, ENCODE_BOUNDS
- };
+ public enum FeatureOpt {
+ ENCODE_CRS, ENCODE_BOUNDS
+ };
- public static final String TYPE_KEY = "type";
+ public static final String TYPE_KEY = "type";
- public static final String GEOM_KEY = "geometry";
+ public static final String GEOM_KEY = "geometry";
- public static final String PROP_KEY = "properties";
+ public static final String PROP_KEY = "properties";
- public static final String COORD_KEY = "coordinates";
+ public static final String COORD_KEY = "coordinates";
- public static final String POINT_TYPE = "Point";
+ public static final String POINT_TYPE = "Point";
- public static final String LINE_STR_TYPE = "LineString";
-
- public static final String POLY_TYPE = "Polygon";
-
- public static final String MULT_POINT_TYPE = "Multi" + POINT_TYPE;
-
- public static final String MULT_LINE_STR_TYPE = "Multi" + LINE_STR_TYPE;
-
- public static final String MULT_POLY_TYPE = "Multi" + POLY_TYPE;
-
- public static final String GEOM_COLL_TYPE = "GeometryCollection";
-
- public static final String FEATURE_TYPE = "Feature";
-
- public static final String ID_KEY = "id";
-
- public static final String FEATURE_COLL_TYPE = "FeatureCollection";
-
- public static final String CRS_KEY = "crs";
-
- public static final String NAME_KEY = "name";
-
- public static final String LINK_KEY = "link";
-
- public static final String HREF_KEY = "href";
-
- public static final String BBOX_KEY = "bbox";
-
- public static final String FEATURES_KEY = "features";
-
- public static final String GEOMS_KEY = "geometries";
-
- private GeometryFactory _geomFact;
-
- private Object _mutex = new Object();
-
- protected GeometryFactory getGeomFact() {
- if (_geomFact == null) {
- synchronized (_mutex) {
- // check again
- if (_geomFact == null) {
- _geomFact = new GeometryFactory();
- }
- }
- }
- return _geomFact;
- }
-
- public Map extract(Geometry geom) throws JsonException {
- if (geom instanceof Point) {
- return extractPoint((Point) geom);
- } else if (geom instanceof LineString) {
- return extractLineString((LineString) geom);
- } else if (geom instanceof Polygon) {
- return extractPolygon((Polygon) geom);
- } else if (geom instanceof MultiPoint) {
- return extractMultiPoint((MultiPoint) geom);
- } else if (geom instanceof MultiLineString) {
- return extractMultiLineString((MultiLineString) geom);
- } else if (geom instanceof MultiPolygon) {
- return extractMultiPolygon((MultiPolygon) geom);
- } else if (geom instanceof GeometryCollection) {
- return extractGeometryCollection((GeometryCollection) geom);
- } else {
- throw new JsonException("Unkown geometry type: " + geom.getClass());
- }
- }
-
- public Geometry populateGeometry(Map jsonObj)
- throws JsonException {
- String type = (String) jsonObj.get(TYPE_KEY);
- if (type == null) {
- throw new JsonException("Unable to find type in json map");
- }
- if (POINT_TYPE.equals(type)) {
- return populatePoint(jsonObj);
- } else if (LINE_STR_TYPE.equals(type)) {
- return populateLineString(jsonObj);
- } else if (POLY_TYPE.equals(type)) {
- return populatePolygon(jsonObj);
- } else if (MULT_POINT_TYPE.equals(type)) {
- return populateMultiPoint(jsonObj);
- } else if (MULT_LINE_STR_TYPE.equals(type)) {
- return populateMultiLineString(jsonObj);
- } else if (MULT_POLY_TYPE.equals(type)) {
- return populateMultiPolygon(jsonObj);
- } else if (GEOM_COLL_TYPE.equals(type)) {
- return populateGeomCollection(jsonObj);
- } else {
- throw new JsonException("Unkown GeoJson geometry type: " + type);
- }
- }
-
- public Map extract(SimpleFeature feature)
- throws JsonException {
- return extract(feature, EnumSet.noneOf(FeatureOpt.class));
- }
-
- public Map extract(SimpleFeature feature,
- EnumSet opts) throws JsonException {
- Object geom = feature.getDefaultGeometry();
- Map rval = new LinkedHashMap(6);
- rval.put(TYPE_KEY, FEATURE_TYPE);
- SimpleFeatureType type = feature.getFeatureType();
- if (type == null) {
- throw new JsonException("Feature type cannot be null");
- }
- String id = feature.getID();
- if (id != null) {
- rval.put(ID_KEY, id);
- }
- if (opts.contains(FeatureOpt.ENCODE_CRS)) {
- CoordinateReferenceSystem crs = type.getCoordinateReferenceSystem();
- if (crs != null) {
- rval.put(CRS_KEY, extract(crs));
- }
- }
- if (opts.contains(FeatureOpt.ENCODE_BOUNDS)) {
- BoundingBox bounds = feature.getBounds();
- if (bounds != null) {
- rval.put(BBOX_KEY, getBounds(bounds));
- }
- }
- int geomIndex = -1;
- if (geom != null) {
- rval.put(GEOM_KEY, extract((Geometry) geom));
- geomIndex = type.indexOf(feature.getDefaultGeometryProperty()
- .getName());
- }
- int count = type.getAttributeCount();
- Map props = new LinkedHashMap(count);
- for (int i = 0; i < count; ++i) {
- if (i == geomIndex) {
- continue;
- }
- Object value = feature.getAttribute(i);
- if (value == null) {
- continue;
- }
- AttributeDescriptor desc = type.getDescriptor(i);
- String name = desc.getLocalName();
- if (value instanceof Geometry) {
- props.put(name, extract((Geometry) value));
- } else if (value instanceof Envelope) {
- props.put(name, getEnv((Envelope) value));
- } else if (value instanceof BoundingBox) {
- props.put(name, getBounds((BoundingBox) value));
- } else {
- props.put(name, value);
- }
- }
- rval.put(PROP_KEY, props);
- return rval;
- }
-
- public Map extract(
- FeatureCollection coll)
- throws JsonException {
- return extract(coll, EnumSet.noneOf(FeatureOpt.class));
- }
-
- public Map extract(
- FeatureCollection coll,
- EnumSet opts) throws JsonException {
- Map rval = new LinkedHashMap(4);
- rval.put(TYPE_KEY, FEATURE_COLL_TYPE);
- ReferencedEnvelope bounds = coll.getBounds();
- if (opts.contains(FeatureOpt.ENCODE_CRS) && bounds != null
- && !bounds.isNull()) {
- CoordinateReferenceSystem crs = bounds
- .getCoordinateReferenceSystem();
- if (crs != null) {
- rval.put(CRS_KEY, extract(crs));
- }
- }
- if (opts.contains(FeatureOpt.ENCODE_BOUNDS) && bounds != null
- && !bounds.isNull()) {
- rval.put(BBOX_KEY, getBounds(bounds));
- }
- FeatureIterator iter = coll.features();
- Object[] features = new Object[coll.size()];
- for (int i = 0; iter.hasNext(); ++i) {
- SimpleFeature feature = iter.next();
- features[i] = extract(feature, opts);
- }
- rval.put(FEATURES_KEY, features);
- return rval;
- }
-
- protected double[] getBounds(BoundingBox bbox) {
- double minX = bbox.getMinX();
- double minY = bbox.getMinY();
- double maxX = bbox.getMaxX();
- double maxY = bbox.getMaxY();
- return new double[] { minX, minY, maxX, maxY };
- }
-
- protected double[] getEnv(Envelope bbox) {
- double minX = bbox.getMinX();
- double minY = bbox.getMinY();
- double maxX = bbox.getMaxX();
- double maxY = bbox.getMaxY();
- return new double[] { minX, minY, maxX, maxY };
- }
-
- public Map extract(CoordinateReferenceSystem crs)
- throws JsonException {
- Map rval = new LinkedHashMap(2);
- // TODO supported linked crs
- rval.put(TYPE_KEY, NAME_KEY);
- Map props = new LinkedHashMap(1);
- try {
- props.put(NAME_KEY, CRS.lookupIdentifier(crs, true));
- } catch (FactoryException e) {
- throw new JsonException("Problem looking up CRS ID", e);
- }
- rval.put(PROP_KEY, props);
- return rval;
- }
-
- @SuppressWarnings("unchecked")
- public FeatureCollection populateFeatureCollection(
- Map jsonObj, SimpleFeatureType type)
- throws JsonException {
- Object obj = jsonObj.get(FEATURES_KEY);
- if (obj == null) {
- if (type == null) {
- type = new SimpleFeatureTypeBuilder().buildFeatureType();
- }
- return new EmptyFeatureCollection(type);
- }
- if (!(obj instanceof List>)) {
- throw new JsonException("Expected List for features, got "
- + obj.getClass());
- }
- List> features = (List>) obj;
- List rval = new ArrayList(features.size());
- for (Object f : features) {
- if (!(f instanceof Map)) {
- throw new JsonException("Expected Map for feature got "
- + f.getClass());
- }
- Map fmap = (Map) f;
- if (type == null) {
- rval.add(populateFeature(fmap));
- } else {
- rval.add(populateFeature(fmap, type));
- }
- }
- SimpleFeature sample = rval.get(0);
- MemoryFeatureCollection coll = new MemoryFeatureCollection(
- sample.getFeatureType());
- coll.addAll(rval);
- return coll;
- }
-
- protected FeatureCollection getCollection(
- List features, SimpleFeatureType type) {
- if (type != null) {
- MemoryFeatureCollection coll = new MemoryFeatureCollection(type);
- coll.addAll(features);
- return coll;
- }
- Map> sorted = new HashMap>();
-
- Iterator i = features.iterator();
- while (i.hasNext()) {
- SimpleFeature next = i.next();
- List list = sorted.get(next.getFeatureType());
- if (list == null) {
- list = new ArrayList();
- }
- list.add(next);
- }
- if (sorted.size() == 1) {
- SimpleFeatureType t = features.get(0).getFeatureType();
- MemoryFeatureCollection coll = new MemoryFeatureCollection(t);
- coll.addAll(features);
- return coll;
- } else {
- Set keySet = sorted.keySet();
- List> colls = new ArrayList>(
- keySet.size());
- for (SimpleFeatureType key : keySet) {
- MemoryFeatureCollection coll = new MemoryFeatureCollection(key);
- coll.addAll(sorted.get(key));
- colls.add(coll);
- }
- return new MixedFeatureCollection(colls);
- }
- }
-
- public FeatureCollection populateFeatureCollection(
- Map jsonObj) throws JsonException {
- return populateFeatureCollection(jsonObj, null);
- }
-
- public SimpleFeature populateFeature(Map jsonObj)
- throws JsonException {
- return populateFeature(jsonObj, "the_geom", "feature");
- }
-
- public SimpleFeature populateFeature(Map jsonObj,
- SimpleFeatureType type) throws JsonException {
- String id = (String) jsonObj.get(ID_KEY);
- Geometry geom = getFeatureGeom(jsonObj);
- SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
- if (geom != null) {
- GeometryDescriptor geomDesc = type.getGeometryDescriptor();
- Name geomName = geomDesc.getName();
- builder.set(geomName, geom);
- }
- Map props = getProps(jsonObj.get(PROP_KEY));
- for (AttributeDescriptor desc : type.getAttributeDescriptors()) {
- String name = desc.getLocalName();
- Object value = props.get(name);
- if (value != null) {
- builder.set(name, value);
- }
- }
- return builder.buildFeature(id);
- }
-
- @SuppressWarnings("unchecked")
- protected Geometry getFeatureGeom(Map jsonObj)
- throws JsonException {
- Object obj = jsonObj.get(GEOM_KEY);
- Geometry geom = null;
- if (obj != null) {
- if (obj instanceof Map) {
- geom = populateGeometry((Map) obj);
- } else {
- throw new JsonException("Unexpected type for geometry: "
- + obj.getClass());
- }
- }
- return geom;
- }
-
- @SuppressWarnings("unchecked")
- public SimpleFeature populateFeature(Map jsonObj,
- String geomName, String featureName) throws JsonException {
- String id = (String) jsonObj.get(ID_KEY);
- SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
- typeBuilder.setName(featureName);
- Geometry geom = getFeatureGeom(jsonObj);
- if (geom != null) {
- typeBuilder.setDefaultGeometry(geomName);
- typeBuilder.add(geomName, geom.getClass());
- }
- Object crsObj = jsonObj.get(CRS_KEY);
- CoordinateReferenceSystem crs = null;
- if (crsObj != null) {
- if (crsObj instanceof Map) {
- crs = populateCrs((Map) crsObj);
- typeBuilder.setCRS(crs);
- } else {
- throw new JsonException(
- "Expected Map for CRS got"
- + crsObj.getClass());
- }
- }
- List