Java Code Examples for org.opengis.feature.simple.SimpleFeatureType#getAttributeCount()
The following examples show how to use
org.opengis.feature.simple.SimpleFeatureType#getAttributeCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VectorIngestRunner.java From geowave with Apache License 2.0 | 6 votes |
public static void writeScene( final SimpleFeatureType sceneType, final SimpleFeature firstBandOfScene, final Writer<SimpleFeature> sceneWriter) { final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(sceneType); String fid = null; for (int i = 0; i < sceneType.getAttributeCount(); i++) { final AttributeDescriptor descriptor = sceneType.getDescriptor(i); final String name = descriptor.getLocalName(); final Object value = firstBandOfScene.getAttribute(name); if (value != null) { featureBuilder.set(i, value); if (name.equals(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME)) { fid = value.toString(); } } } if (fid != null) { sceneWriter.write(featureBuilder.buildFeature(fid)); } }
Example 2
Source File: VectorIngestRunner.java From geowave with Apache License 2.0 | 6 votes |
public static void writeScene( final SimpleFeatureType sceneType, final SimpleFeature firstBandOfScene, final Writer sceneWriter) { final SimpleFeatureBuilder bldr = new SimpleFeatureBuilder(sceneType); String fid = null; for (int i = 0; i < sceneType.getAttributeCount(); i++) { final AttributeDescriptor attr = sceneType.getDescriptor(i); final String attrName = attr.getLocalName(); final Object attrValue = firstBandOfScene.getAttribute(attrName); if (attrValue != null) { bldr.set(i, attrValue); if (attrName.equals(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME)) { fid = attrValue.toString(); } } } if (fid != null) { sceneWriter.write(bldr.buildFeature(fid)); } }
Example 3
Source File: AbstractFieldRetypingSource.java From geowave with Apache License 2.0 | 5 votes |
@Override public SimpleFeature getRetypedSimpleFeature( final SimpleFeatureBuilder builder, final SimpleFeature original) { final SimpleFeatureType target = builder.getFeatureType(); for (int i = 0; i < target.getAttributeCount(); i++) { final AttributeDescriptor attributeType = target.getDescriptor(i); Object value = null; if (original.getFeatureType().getDescriptor(attributeType.getName()) != null) { final Name name = attributeType.getName(); value = retypeAttributeValue(original.getAttribute(name), name); } builder.add(value); } String featureId = getFeatureId(original); if (featureId == null) { final FeatureId id = getDefaultFeatureId(original.getIdentifier(), original.getFeatureType(), target); featureId = id.getID(); } final SimpleFeature retyped = builder.buildFeature(featureId); retyped.getUserData().putAll(original.getUserData()); return retyped; }
Example 4
Source File: GeoWaveAvroFeatureUtils.java From geowave with Apache License 2.0 | 5 votes |
/** * Add the attributes, types and classifications for the SimpleFeatureType to the provided * FeatureDefinition * * @param fd - existing Feature Definition (or new one if null) * @param sft - SimpleFeatureType of the simpleFeature being serialized * @param defaultClassifications - map of attribute names to classification * @param defaultClassification - default classification if one could not be found in the map * @return the feature definition * @throws IOException */ public static AvroFeatureDefinition buildFeatureDefinition( AvroFeatureDefinition fd, final SimpleFeatureType sft, final Map<String, String> defaultClassifications, final String defaultClassification) throws IOException { if (fd == null) { fd = new AvroFeatureDefinition(); } fd.setFeatureTypeName(sft.getTypeName()); final List<String> attributes = new ArrayList<>(sft.getAttributeCount()); final List<String> types = new ArrayList<>(sft.getAttributeCount()); final List<String> classifications = new ArrayList<>(sft.getAttributeCount()); for (final AttributeDescriptor attr : sft.getAttributeDescriptors()) { final String localName = attr.getLocalName(); attributes.add(localName); types.add(attr.getType().getBinding().getCanonicalName()); classifications.add( getClassification(localName, defaultClassifications, defaultClassification)); } fd.setAttributeNames(attributes); fd.setAttributeTypes(types); fd.setAttributeDefaultClassifications(classifications); return fd; }
Example 5
Source File: GeoWaveAvroFeatureUtils.java From geowave with Apache License 2.0 | 5 votes |
/** * Create an AttributeValue from the SimpleFeature's attributes * * @param sf * @param sft * @return the attribute value */ public static synchronized AvroAttributeValues buildAttributeValue( final SimpleFeature sf, final SimpleFeatureType sft) { final AvroAttributeValues attributeValue = new AvroAttributeValues(); final List<ByteBuffer> values = new ArrayList<>(sft.getAttributeCount()); attributeValue.setSerializationVersion( ByteBuffer.wrap(new byte[] {FieldUtils.SERIALIZATION_VERSION})); attributeValue.setFid(sf.getID()); for (final AttributeDescriptor attr : sft.getAttributeDescriptors()) { final Object o = sf.getAttribute(attr.getLocalName()); byte[] bytes; if (o instanceof Geometry) { bytes = WKB_WRITER.write((Geometry) o); } else { final FieldWriter fw = FieldUtils.getDefaultWriterForClass(attr.getType().getBinding()); bytes = fw.writeField(o); } values.add(ByteBuffer.wrap(bytes)); } attributeValue.setValues(values); return attributeValue; }
Example 6
Source File: FeatureDataAdapter.java From geowave with Apache License 2.0 | 5 votes |
/** * Create List of NativeFieldHandlers based on the SimpleFeature type passed as parameter. * * @param featureType - SFT to be used to determine handlers * @return List of NativeFieldHandlers that correspond to attributes in featureType */ protected List<NativeFieldHandler<SimpleFeature, Object>> getFieldHandlersFromFeatureType( final SimpleFeatureType featureType) { final List<NativeFieldHandler<SimpleFeature, Object>> nativeHandlers = new ArrayList<>(featureType.getAttributeCount()); for (final AttributeDescriptor attrDesc : featureType.getAttributeDescriptors()) { nativeHandlers.add(new FeatureAttributeHandler(attrDesc)); } return nativeHandlers; }
Example 7
Source File: GeoWaveVectorMetadataReader.java From mrgeo with Apache License 2.0 | 4 votes |
private VectorMetadata loadMetadata() throws AccumuloSecurityException, AccumuloException, IOException { VectorMetadata metadata = new VectorMetadata(); if (adapter == null) { DataAdapter<?> localAdapter = dataProvider.getDataAdapter(); adapter = (FeatureDataAdapter) localAdapter; } SimpleFeatureType sft = adapter.getType(); for (int index = 0; index < sft.getAttributeCount(); index++) { AttributeDescriptor desc = sft.getDescriptor(index); metadata.addAttribute(desc.getName().getLocalPart()); } FeatureBoundingBoxStatistics boundsStats = null; String geometryField = sft.getGeometryDescriptor().getLocalName(); log.info("GeoWave geometry field is: " + geometryField); DataStatistics<?> stats = dataProvider.getStatisticsStore().getDataStatistics( new ByteArrayId(dataProvider.getGeoWaveResourceName()), FeatureBoundingBoxStatistics.composeId(geometryField)); boundsStats = (FeatureBoundingBoxStatistics) stats; Bounds bounds = null; if (boundsStats != null) { bounds = new Bounds(boundsStats.getMinX(), boundsStats.getMinY(), boundsStats.getMaxX(), boundsStats.getMaxY()); log.info("Bounds for " + dataProvider.getGeoWaveResourceName() + " from GeoWave: " + bounds.toString()); } else { log.info("BBOX information was not found in GeoWave for field " + geometryField); // See if the GeoWave data provider is configured to force a bounding // box computation by iterating features. if (GeoWaveVectorDataProvider.getConnectionInfo().getForceBboxCompute()) { log.info("Computing BBOX by iterating features"); VectorReader reader = dataProvider.getVectorReader(); CloseableKVIterator<FeatureIdWritable, Geometry> iter = reader.get(); double minX = Double.MAX_VALUE; double minY = Double.MAX_VALUE; double maxX = Double.MIN_VALUE; double maxY = Double.MIN_VALUE; while (iter.hasNext()) { Geometry geom = iter.next(); Bounds b = geom.getBounds(); minX = Math.min(minX, b.w); minY = Math.min(minY, b.s); maxX = Math.max(maxX, b.e); maxY = Math.max(maxY, b.n); } bounds = new Bounds(minX, minY, maxX, maxY); log.info("Bounds for " + dataProvider.getGeoWaveResourceName() + " were computed as: " + bounds.toString()); } else { // Use world bounds, but log a warning bounds = Bounds.WORLD.clone(); log.warn("Using world bounds for " + dataProvider.getGeoWaveResourceName() + ": " + bounds.toString()); } } metadata.setBounds(bounds); return metadata; }
Example 8
Source File: InternalFeatureCollection.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public WrappedFeature(SimpleFeatureType featureType) { super(new Object[featureType.getAttributeCount()], featureType, new FeatureIdImpl(""), false); }