if (gd == null) return catalog.getStyleByName(StyleInfo.DEFAULT_POINT); Class gtype = gd.getType().getBinding(); StyleType st; if (LineString.class.isAssignableFrom(gtype)
Class gtype = gd.getType().getBinding(); if (Point.class.isAssignableFrom(gtype) || MultiPoint.class.isAssignableFrom(gtype)) { styleName = StyleInfo.DEFAULT_POINT;
public FeatureTypeImpl( Name name, Collection<PropertyDescriptor> schema, GeometryDescriptor defaultGeometry, boolean isAbstract, List<Filter> restrictions, AttributeType superType, InternationalString description) { super(name, schema, true, isAbstract, restrictions, superType, description); this.defaultGeometry = defaultGeometry; if (defaultGeometry != null && !(defaultGeometry.getType() instanceof GeometryType)) { throw new IllegalArgumentException("defaultGeometry must have a GeometryType"); } }
@Override public Geometry decodeGeometryValue( GeometryDescriptor descriptor, ResultSet rs, int column, GeometryFactory factory, Connection cx, Hints hints) throws IOException, SQLException { return geometry(descriptor.getType().getBinding(), rs.getBytes(column), factory, hints); }
/** * Checks if reduction required and makes sense * * @param hints hints passed in * @param gatt Geometry attribute descriptor * @param param {@link Hints#GEOMETRY_GENERALIZATION} or {@link Hints#GEOMETRY_SIMPLIFICATION} * @return true to indicate reducing the geometry, false otherwise */ protected boolean isGeometryReduceRequired( Hints hints, GeometryDescriptor gatt, Hints.Key param) { if (hints == null) return false; if (hints.containsKey(param) == false) return false; if (gatt.getType().getBinding() == Point.class) return false; return true; }
public CoordinateReferenceSystem getCoordinateReferenceSystem() { if (crs == null) { if (getGeometryDescriptor() != null && getGeometryDescriptor().getType().getCoordinateReferenceSystem() != null) { crs = defaultGeometry.getType().getCoordinateReferenceSystem(); } if (crs == null) { for (PropertyDescriptor property : getDescriptors()) { if (property instanceof GeometryDescriptor) { GeometryDescriptor geometry = (GeometryDescriptor) property; if (geometry.getType().getCoordinateReferenceSystem() != null) { crs = geometry.getType().getCoordinateReferenceSystem(); break; } } } } } return crs; }
/** * Finds the CRS of the specified attribute (or uses the default geometry instead) * * @param geomName * @param schema * @return */ org.opengis.referencing.crs.CoordinateReferenceSystem getAttributeCRS( PropertyName geomName, FeatureType schema) { if (geomName == null || "".equals(geomName.getPropertyName())) { GeometryDescriptor geom = schema.getGeometryDescriptor(); return geom.getType().getCoordinateReferenceSystem(); } else { GeometryDescriptor geom = (GeometryDescriptor) geomName.evaluate(schema); return geom.getType().getCoordinateReferenceSystem(); } }
static Geometries findGeometryType(SimpleFeatureType schema) { GeometryDescriptor gd = findGeometryDescriptor(schema); return gd != null ? Geometries.getForBinding((Class<? extends Geometry>) gd.getType().getBinding()) : null; }
public static BufferedImage icon(SimpleFeatureType ft) { if (ft == null || ft.getGeometryDescriptor() == null) return null; Class binding = ft.getGeometryDescriptor().getType().getBinding(); if (Point.class.isAssignableFrom(binding) || MultiPoint.class.isAssignableFrom(binding)) { return point(DEFAULT_BORDER, DEFAULT_FILL); } if (LineString.class.isAssignableFrom(binding) || MultiLineString.class.isAssignableFrom(binding) || LinearRing.class.isAssignableFrom(binding)) { return line(DEFAULT_BORDER, 1); } if (Polygon.class.isAssignableFrom(binding) || MultiPolygon.class.isAssignableFrom(binding)) { return polygon(DEFAULT_BORDER, DEFAULT_FILL, 1); } return geometry(DEFAULT_BORDER, DEFAULT_FILL); } }
private GeometryDescriptor reprojectGeometry(GeometryDescriptor descr) { if (descr == null) { return null; } GeometryType type = ftf.createGeometryType( descr.getType().getName(), descr.getType().getBinding(), reprojection, descr.getType().isIdentified(), descr.getType().isAbstract(), descr.getType().getRestrictions(), descr.getType().getSuper(), descr.getType().getDescription()); type.getUserData().putAll(descr.getType().getUserData()); GeometryDescriptor gd = ftf.createGeometryDescriptor( type, descr.getName(), descr.getMinOccurs(), descr.getMaxOccurs(), descr.isNillable(), descr.getDefaultValue()); gd.getUserData().putAll(descr.getUserData()); return gd; }
Geometry convertGeometry( Geometry geom, GeometryDescriptor descriptor, GeometryFactory factory) { // if the geometry is null no need to convert it if (geom == null) { return null; } // grab the binding Class targetClazz = descriptor.getType().getBinding(); // in Oracle you can have polygons in a column declared to be multipolygon, and so on... // so we better convert geometries, since our feature model is not so lenient if (targetClazz.equals(MultiPolygon.class) && geom instanceof Polygon) { return factory.createMultiPolygon(new Polygon[] {(Polygon) geom}); } else if (targetClazz.equals(MultiPoint.class) && geom instanceof Point) { return factory.createMultiPoint(new Point[] {(Point) geom}); } else if (targetClazz.equals(MultiLineString.class) && geom instanceof LineString) { return factory.createMultiLineString(new LineString[] {(LineString) geom}); } else if (targetClazz.equals(GeometryCollection.class)) { return factory.createGeometryCollection(new Geometry[] {geom}); } return geom; }
@Test public void testEmptyBounds() throws Exception { // test the bounds of a single point Catalog cat = getCatalog(); FeatureTypeInfo fti = cat.getFeatureTypeByName(toString(MockData.POINTS)); assertEquals( Point.class, fti.getFeatureType().getGeometryDescriptor().getType().getBinding()); assertEquals(1, fti.getFeatureSource(null, null).getCount(Query.ALL)); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getStoreByName(MockData.CGF_PREFIX, DataStoreInfo.class)); FeatureTypeInfo built = cb.buildFeatureType(fti.getQualifiedName()); cb.setupBounds(built); assertTrue(built.getNativeBoundingBox().getWidth() > 0); assertTrue(built.getNativeBoundingBox().getHeight() > 0); }
/** * The query that defines this readers interaction with an ArcSDE instance. * * @param query the {@link SeQuery} wrapper where to fetch rows from. Must NOT be already {@link * ArcSDEQuery#execute() executed}. * @param geometryFactory the JTS GeometryFactory to use when creating Feature geometries * @param session the session the <code>query</code> is being ran over. This attribute reader * will close it only if it does not have a transaction in progress. * @throws IOException */ @SuppressWarnings("unchecked") public ArcSDEAttributeReader( final ArcSDEQuery query, final GeometryFactory geometryFactory, final ISession session) throws IOException { this.query = query; this.session = session; this.fidReader = query.getFidReader(); this.schema = query.getSchema(); this.geometryFactory = geometryFactory; String typeName = schema.getTypeName(); this.fidPrefix = new StringBuffer(typeName).append('.'); this.fidPrefixLen = this.fidPrefix.length(); final GeometryDescriptor geomType = schema.getGeometryDescriptor(); if (geomType != null) { this.schemaGeometryClass = (Class<? extends Geometry>) geomType.getType().getBinding(); } else { this.schemaGeometryClass = null; } query.execute(); }
private void buildType() { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("feature"); typeBuilder.setNamespaceURI("http://geotools.org"); if (geom != null) { typeBuilder.add(geom.getLocalName(), geom.getType().getBinding(), crs); } if (propertyTypes != null) { Set<Entry<String, Class<?>>> entrySet = propertyTypes.entrySet(); for (Entry<String, Class<?>> entry : entrySet) { Class<?> binding = entry.getValue(); if (binding.equals(Object.class)) { binding = String.class; } typeBuilder.add(entry.getKey(), binding); } } if (crs != null) { typeBuilder.setCRS(crs); } featureType = typeBuilder.buildFeatureType(); }
public GeometryAttribute getDefaultGeometryProperty() { if (defaultGeometry != null) { return defaultGeometry; } synchronized (this) { if (defaultGeometry == null) { // look it up from the type if (((FeatureType) getType()).getGeometryDescriptor() == null) { return null; } GeometryType geometryType = (GeometryType) getType().getGeometryDescriptor().getType(); if (geometryType != null) { for (Iterator itr = getValue().iterator(); itr.hasNext(); ) { Property property = (Property) itr.next(); if (property instanceof GeometryAttribute) { if (property.getType().equals(geometryType)) { defaultGeometry = (GeometryAttribute) property; break; } } } } } } return defaultGeometry; }
/** * {@inheritDoc} The {@code layer} argument must be an instance of {@linkplain FeatureLayer}. */ @Override public void setLayer(Layer layer) { if (!(layer instanceof FeatureLayer)) { throw new IllegalArgumentException("layer must be an instance of FeatureLayer"); } super.setLayer(layer); GeometryDescriptor geomDesc = layer.getFeatureSource().getSchema().getGeometryDescriptor(); attrName = geomDesc.getLocalName(); Class<? extends Geometry> geomClass = (Class<? extends Geometry>) geomDesc.getType().getBinding(); geomType = Geometries.getForBinding(geomClass); }
@Override protected SimpleFeatureType buildFeatureType() throws IOException { List<AttributeDescriptor> types = readAttributes(); SimpleFeatureType parent = null; GeometryDescriptor geomDescriptor = (GeometryDescriptor) types.get(0); Class<?> geomBinding = geomDescriptor.getType().getBinding(); if ((geomBinding == Point.class) || (geomBinding == MultiPoint.class)) { parent = BasicFeatureTypes.POINT; } else if ((geomBinding == Polygon.class) || (geomBinding == MultiPolygon.class)) { parent = BasicFeatureTypes.POLYGON; } else if ((geomBinding == LineString.class) || (geomBinding == MultiLineString.class)) { parent = BasicFeatureTypes.LINE; } SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setDefaultGeometry(geomDescriptor.getLocalName()); builder.addAll(types); builder.setName(entry.getName()); builder.setAbstract(false); if (parent != null) { builder.setSuperType(parent); } return builder.buildFeatureType(); }
protected Class checkGeometryType(Class geomClass) throws Exception { // we just prefix the table name with "t" otherwise we go beyond // the Oracle identifier max length limit (oh my my...) String featureTypeName = tname("t" + geomClass.getSimpleName()); // create a featureType and write it to PostGIS CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName(featureTypeName); ftb.add(aname("id"), Integer.class); ftb.add(aname("name"), String.class); ftb.add(aname("geom"), geomClass, crs); SimpleFeatureType newFT = ftb.buildFeatureType(); dataStore.createSchema(newFT); SimpleFeatureType newSchema = dataStore.getSchema(featureTypeName); assertNotNull(newSchema); assertEquals(3, newSchema.getAttributeCount()); return newSchema.getGeometryDescriptor().getType().getBinding(); } }
public void testCRS() { builder.setName("testName"); builder.setNamespaceURI("testNamespaceURI"); builder.setCRS(DefaultGeographicCRS.WGS84); builder.crs(null).add("point", Point.class); builder.add("point2", Point.class, DefaultGeographicCRS.WGS84); builder.setDefaultGeometry("point"); SimpleFeatureType type = builder.buildFeatureType(); assertEquals(DefaultGeographicCRS.WGS84, type.getCoordinateReferenceSystem()); assertNull(type.getGeometryDescriptor().getType().getCoordinateReferenceSystem()); assertEquals( DefaultGeographicCRS.WGS84, ((GeometryType) type.getType("point2")).getCoordinateReferenceSystem()); }
public void testSanity() { builder.setName("testName"); builder.setNamespaceURI("testNamespaceURI"); builder.add("point", Point.class, (CoordinateReferenceSystem) null); builder.add("integer", Integer.class); SimpleFeatureType type = builder.buildFeatureType(); assertNotNull(type); assertEquals(2, type.getAttributeCount()); AttributeType t = type.getType("point"); assertNotNull(t); assertEquals(Point.class, t.getBinding()); t = type.getType("integer"); assertNotNull(t); assertEquals(Integer.class, t.getBinding()); t = type.getGeometryDescriptor().getType(); assertNotNull(t); assertEquals(Point.class, t.getBinding()); }