private static Feature addFeature(Geometry g) { Feature f = new Feature(); f.setName(Integer.toString(++id)); /* String type = g.getClass().getName(); int ind = type.lastIndexOf('.'); if (ind > 0) type = type.substring(ind + 1); */ f.setDescription(g.toString()); f.setGeometry(g); return f; }
/** * Create a feature with a number of data elements in the extended data. This method will not use * a schema. * * @param geoclass the class of the geometry objects to create * @param schema the schema * @param valuemap the valuemap, not <code>null</code> * @return the new instance */ protected Feature createFeature( Class<? extends Geometry> geoclass, Schema schema, Map<String, Object> valuemap) { if (schema == null) { throw new IllegalArgumentException("schema should never be null"); } if (valuemap == null) { throw new IllegalArgumentException("valuemap should never be null"); } Feature f = createBasicFeature(geoclass); f.setSchema(schema.getId()); for (String key : schema.getKeys()) { SimpleField field = schema.get(key); Object value = valuemap.get(key); f.putData(field, value != null ? value : ObjectUtils.NULL); } return f; }
/** * @param geoclass * @return */ protected Feature createBasicFeature(Class<? extends Geometry> geoclass) { Feature f = new Feature(); count.incrementAndGet(); f.setName("feature" + count); f.setDescription("feature description " + count); if (geoclass.isAssignableFrom(Point.class)) { Point p = new Point(new Geodetic2DPoint(random)); f.setGeometry(p); } else if (geoclass.isAssignableFrom(Line.class)) { List<Point> pts = new ArrayList<Point>(); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); f.setGeometry(new Line(pts)); } else if (geoclass.isAssignableFrom(LinearRing.class)) { List<Point> pts = new ArrayList<Point>(); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); f.setGeometry(new LinearRing(pts)); } else if (geoclass.isAssignableFrom(Polygon.class)) { List<Point> pts = new ArrayList<Point>(); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); pts.add(new Point(new Geodetic2DPoint(random))); f.setGeometry(new Polygon(new LinearRing(pts))); } return f; }
/** * Create a feature with a number of data elements in the extended data. This method will not use * a schema. * * @param geoclass the class of the geometry objects to create * @param names the names of the attributes * @param values the values, the length must match the length of names * @return the new instance */ protected Feature createFeature( Class<? extends Geometry> geoclass, String names[], Object values[]) { if (names == null) { throw new IllegalArgumentException("names should never be null"); } if (values == null) { throw new IllegalArgumentException("values should never be null"); } if (names.length != values.length) { throw new IllegalArgumentException("the count of names and values must match"); } Feature f = createBasicFeature(geoclass); for (int i = 0; i < names.length; i++) { SimpleField field = new SimpleField(names[i]); f.putData(field, values[i]); } return f; }