GeometryDescriptor gd = nativeFeatureType.getGeometryDescriptor(); if (gd == null) return catalog.getStyleByName(StyleInfo.DEFAULT_POINT);
private Map<String, Object> buildDummyFeatureTypeInfo(ComplexAttribute f) { Map<String, Object> dummy = new HashMap<String, Object>(); dummy.put("name", f.getType().getName().getLocalPart()); dummy.put("namespace", getNamespace(f.getType().getName())); dummy.put("prefix", getPrefix(f.getType().getName())); dummy.put("title", "Layer: " + f.getType().getName().getLocalPart()); dummy.put("abstract", "[No Abstract Provided]"); dummy.put("description", "[No Description Provided]"); dummy.put("keywords", new ArrayList<String>()); dummy.put("metadataLinks", new ArrayList<String>()); dummy.put("SRS", "[SRS]"); if (f instanceof Feature) { final GeometryDescriptor gd = ((Feature) f).getType().getGeometryDescriptor(); if (gd != null) { dummy.put("nativeCRS", gd.getCoordinateReferenceSystem()); } } return dummy; }
return null; GeometryDescriptor gd = featureType.getFeatureType().getGeometryDescriptor(); if (gd == null) { return null;
@Test public void testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
if (crs == null && featureType.getGeometryDescriptor() != null) { crs = featureType.getGeometryDescriptor().getCoordinateReferenceSystem();
public GeometryDescriptor getGeometryDescriptor() { return ((FeatureType) getSubject()).getGeometryDescriptor(); } }
@Test public void testDefaultGeometry() throws IOException { FeatureTypeInfo featureType = getCatalog().getResourceByName("cdf", "Nulls", FeatureTypeInfo.class); GeometryDescriptor schemaDefaultGeometry = featureType.getFeatureType().getGeometryDescriptor(); FeatureIterator i = featureType.getFeatureSource(null, null).getFeatures().features(); GeometryDescriptor featureDefaultGeometry = i.next().getDefaultGeometryProperty().getDescriptor(); assertNotNull(schemaDefaultGeometry); assertNotNull(featureDefaultGeometry); assertEquals("pointProperty", schemaDefaultGeometry.getLocalName()); assertEquals(schemaDefaultGeometry, featureDefaultGeometry); } }
protected boolean isDefaultGeometry(PropertyName ae) { return reader.getFeatureType() .getGeometryDescriptor() .getLocalName() .equals(ae.getPropertyName()); }
public boolean equals(Object o) { if (this == o) { return true; } if (!super.equals(o)) { return false; } if (getClass() != o.getClass()) { return false; } FeatureType other = (FeatureType) o; if (!Utilities.equals(getGeometryDescriptor(), other.getGeometryDescriptor())) { return false; } return true; }
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; }
public Object get(Object object, String xpath, Class target) { if (object instanceof Feature) return ((Feature) object).getDefaultGeometryProperty(); if (object instanceof FeatureType) { FeatureType ft = (FeatureType) object; GeometryDescriptor gd = ft.getGeometryDescriptor(); if (gd == null) { // look for any geometry descriptor for (PropertyDescriptor pd : ft.getDescriptors()) { if (Geometry.class.isAssignableFrom(pd.getType().getBinding())) { return pd; } } } return gd; } return null; }
@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); }
/** * 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(); } }
private void setDefaultGeometryAttribute(Feature feature) { String defaultGeomXPath = mapping.getDefaultGeometryXPath(); if (defaultGeomXPath != null && !defaultGeomXPath.isEmpty()) { GeometryDescriptor defaultGeomDescr = feature.getType().getGeometryDescriptor(); if (defaultGeomDescr != null) { PropertyName geomProperty = filterFac.property(defaultGeomXPath, namespaces); Object geomValue = geomProperty.evaluate(feature); if (geomValue instanceof Collection) { throw new RuntimeException( "Error setting default geometry value: multiple values were found"); } String geomName = Types.toPrefixedName(defaultGeomDescr.getName(), namespaces); StepList fakeDefaultGeomXPath = XPath.steps(targetFeature, geomName, namespaces); xpathAttributeBuilder.set( feature, fakeDefaultGeomXPath, geomValue, null, null, false, null); } } }
/** * {@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); }
private FeatureType reprojectType(FeatureType type) { Collection<PropertyDescriptor> schema = new ArrayList<PropertyDescriptor>(); for (PropertyDescriptor descr : type.getDescriptors()) { if (descr instanceof GeometryDescriptor) { schema.add(reprojectGeometry((GeometryDescriptor) descr)); } else { schema.add(descr); } } FeatureType ft; if (type instanceof NonFeatureTypeProxy) { ft = new NonFeatureTypeProxy( ((NonFeatureTypeProxy) type).getSubject(), mapping, schema); } else { ft = ftf.createFeatureType( type.getName(), schema, reprojectGeometry(type.getGeometryDescriptor()), type.isAbstract(), type.getRestrictions(), type.getSuper(), type.getDescription()); } ft.getUserData().putAll(type.getUserData()); return ft; }
/** * Create the modified feature type. * * @param sourceFeatureType the source feature type * @return the modified feature type * @throws ProcessException errror */ private SimpleFeatureType createTargetFeatureType(FeatureType sourceFeatureType) throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); AttributeDescriptor geomAttbType = sourceFeatureType.getGeometryDescriptor(); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { if (attbType.equals(geomAttbType)) { typeBuilder.add(geomAttbType.getLocalName(), Point.class); } else { typeBuilder.add((AttributeDescriptor) attbType); } } typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) { LOGGER.warning("Error creating type: " + e); throw new ProcessException("Error creating type: " + e, e); } }
/** * Create the modified feature type. * * @param sourceFeatureType the source feature type * @return the modified feature type * @throws ProcessException errror */ private SimpleFeatureType createTargetFeatureType(FeatureType sourceFeatureType) throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { typeBuilder.add((AttributeDescriptor) attbType); } typeBuilder.minOccurs(1).maxOccurs(1).nillable(false).add("lrs_measure", Double.class); typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) { LOGGER.warning("Error creating type: " + e); throw new ProcessException("Error creating type: " + e, e); } }
/** * Tests that no default geometry is available for a feature type with no direct child geometry * property. */ @Test public void testDefaultGeometryNone() throws IOException { FeatureTypeMapping mappingNoDefaultGeom = stationsDataAccess.getMappingByNameOrElement(STATION_NO_DEFAULT_GEOM_MAPPING); assertNotNull(mappingNoDefaultGeom); // no default geometry configured assertNull(mappingNoDefaultGeom.getDefaultGeometryXPath()); FeatureType ftNoDefaultGeom = stationsDataAccess.getSchema(STATION_NO_DEFAULT_GEOM_MAPPING); // therefore, no default geometry descriptor available assertNull(ftNoDefaultGeom.getGeometryDescriptor()); }
public void testDefaultGeometryMappingConfiguration() throws IOException { FeatureType ftWithDefaultGeom = stationsDataAccess.getSchema(STATION_FEATURE); assertNotNull(ftWithDefaultGeom.getGeometryDescriptor()); assertEquals( ComplexFeatureConstants.DEFAULT_GEOMETRY_LOCAL_NAME, ftWithDefaultGeom.getGeometryDescriptor().getLocalName());