org.opengis.feature.type.AttributeDescriptor Java Examples

The following examples show how to use org.opengis.feature.type.AttributeDescriptor. 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: FeatureDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object> getFieldHandler(
    final NumericDimensionField<? extends CommonIndexValue> dimension) {
  if (dimension instanceof FeatureAttributeDimensionField) {
    final VisibilityConfiguration visConfig = new VisibilityConfiguration(reprojectedFeatureType);
    final AttributeDescriptor desc =
        reprojectedFeatureType.getDescriptor(dimension.getFieldName());
    if (desc != null) {
      return new FeatureAttributeCommonIndexFieldHandler(
          desc,
          visConfig.getManager().createVisibilityHandler(
              desc.getLocalName(),
              fieldVisiblityHandler,
              visConfig.getAttributeName()));
    }
  }
  return super.getFieldHandler(dimension);
}
 
Example #2
Source File: FeatureDataUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static SimpleFeature buildFeature(
    final SimpleFeatureType featureType,
    final Pair<String, Object>[] entries) {

  final List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }
  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(featureType, defaults, UUID.randomUUID().toString());
  for (final Pair<String, Object> entry : entries) {
    newFeature.setAttribute(entry.getKey(), entry.getValue());
  }
  return newFeature;
}
 
Example #3
Source File: SchemaConverter.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static AttributeDescriptor attrDescFromStructField(
    final AttributeTypeBuilder attrBuilder,
    final StructField field) {
  if (field.name().equals("geom")) {
    return attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geom");
  }
  if (field.dataType() == DataTypes.StringType) {
    return attrBuilder.binding(String.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.DoubleType) {
    return attrBuilder.binding(Double.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.FloatType) {
    return attrBuilder.binding(Float.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.LongType) {
    return attrBuilder.binding(Long.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.IntegerType) {
    return attrBuilder.binding(Integer.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.BooleanType) {
    return attrBuilder.binding(Boolean.class).buildDescriptor(field.name());
  } else if (field.dataType() == DataTypes.TimestampType) {
    return attrBuilder.binding(Date.class).buildDescriptor(field.name());
  }

  return null;
}
 
Example #4
Source File: CentroidManagerGeoWave.java    From geowave with Apache License 2.0 6 votes vote down vote up
public NonSimpleFeatureConverter(
    final String[] extraDimensionNames,
    final Class<? extends Geometry> shapeClass) {
  featureType =
      AnalyticFeature.createFeatureAdapter(
          centroidDataTypeId,
          extraDimensionNames,
          BasicFeatureTypes.DEFAULT_NAMESPACE,
          ClusteringUtils.CLUSTERING_CRS,
          ClusterFeatureAttribute.values(),
          shapeClass).getFeatureType();
  this.shapeClass = shapeClass;
  final List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();
  defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }
}
 
Example #5
Source File: GeoToolsConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public SimpleFeature toSimpleFeature(InternalFeature feature, SimpleFeatureType featureType) {
	SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
	List<Object> attr = new ArrayList<Object>();

	for (AttributeDescriptor ads : featureType.getAttributeDescriptors()) {
		if (!ads.equals(featureType.getGeometryDescriptor())) {
			Attribute a = feature.getAttributes().get(ads.getName().getLocalPart());
			if (null != a) {
				attr.add(a.getValue());
			} else {
				attr.add(null);
			}
		} else {
			attr.add(feature.getGeometry());
		}
	}

	return builder.buildFeature(feature.getId(), attr.toArray());

}
 
Example #6
Source File: QueryIndexHelper.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static TemporalRange getStatsRange(
    final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap,
    final AttributeDescriptor attr) {
  final TemporalRange timeRange = new TemporalRange();
  if (attr != null) {
    final TimeRangeDataStatistics stat =
        ((TimeRangeDataStatistics) statsMap.get(
            VectorStatisticsQueryBuilder.newBuilder().factory().timeRange().fieldName(
                attr.getLocalName()).build().getId()));
    if (stat != null) {
      timeRange.setStartTime(new Date(stat.getMin()));
      timeRange.setEndTime(new Date(stat.getMax()));
    }
  }
  return timeRange;
}
 
Example #7
Source File: FeatureAttributeDimensionField.java    From geowave with Apache License 2.0 6 votes vote down vote up
public FeatureAttributeDimensionField(
    final AttributeDescriptor attributeDescriptor,
    final Range<Double> range) {
  super(
      range == null ? null
          : new BasicDimensionDefinition(range.getMinimum(), range.getMaximum()));
  writer =
      new FeatureAttributeWriterWrapper(
          (FieldWriter) FieldUtils.getDefaultWriterForClass(
              attributeDescriptor.getType().getBinding()));
  reader =
      new FeatureAttributeReaderWrapper(
          (FieldReader) FieldUtils.getDefaultReaderForClass(
              attributeDescriptor.getType().getBinding()));
  attributeName = attributeDescriptor.getLocalName();
}
 
Example #8
Source File: JsonDefinitionColumnVisibilityManagementTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws SchemaException, CQLException {
  type =
      DataUtilities.createType(
          "geostuff",
          "geometry:Geometry:srid=4326,vis:java.lang.String,pop:java.lang.Long,pid:String");
  descriptors = type.getAttributeDescriptors();
  defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  newFeature = SimpleFeatureBuilder.build(type, defaults, UUID.randomUUID().toString());
  newFeature.setAttribute("pop", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("vis", "{\"pid\":\"TS\", \"geo.*\":\"S\"}");
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 128.232)));
}
 
Example #9
Source File: CreateInternalDataSource.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds the geometry field.
 *
 * @param b the b
 * @param fieldName the field name
 * @return the attribute descriptor
 */
private AttributeDescriptor addGeometryField(
        ExtendedSimpleFeatureTypeBuilder b, String fieldName) {
    geometryField.setGeometryFieldName(fieldName);
    Class<?> fieldType;
    switch (dsInfo.getGeometryType()) {
        case POLYGON:
            fieldType = MultiPolygon.class;
            break;
        case LINE:
            fieldType = LineString.class;
            break;
        case POINT:
        default:
            fieldType = Point.class;
            break;
    }
    b.setDefaultGeometry(fieldName);
    return b.createAttributeDescriptor(fieldName, fieldType);
}
 
Example #10
Source File: FeatureFixedBinNumericStaticticsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
private SimpleFeature create(final Double val) {
  final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());

  newFeature.setAttribute("pop", val);
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("when", new Date());
  newFeature.setAttribute("whennot", new Date());
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
  return newFeature;
}
 
Example #11
Source File: VectorIngestRunner.java    From geowave with Apache License 2.0 6 votes vote down vote up
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 #12
Source File: FeatureHyperLogLogStaticticsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
private SimpleFeature create(final String pid, final Set<String> set) {
  final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
  final Object[] defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }

  final SimpleFeature newFeature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());

  newFeature.setAttribute("pid", pid);

  set.add(pid);

  return newFeature;
}
 
Example #13
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the unique attribute name.
 *
 * @return the unique attribute name
 */
private String getUniqueAttributeName() {
    String newColumnName = "";
    List<String> columnNameList = new ArrayList<>();

    List<AttributeDescriptor> descriptorList =
            featureCollection.getSchema().getAttributeDescriptors();

    for (AttributeDescriptor attribute : descriptorList) {
        columnNameList.add(attribute.getLocalName());
    }

    int colIndex = descriptorList.size() + 1;
    boolean found = false;
    while (!found) {
        newColumnName = String.format("attr%02d", colIndex);

        if (columnNameList.contains(newColumnName)) {
            colIndex++;
        } else {
            found = true;
        }
    }
    return newColumnName;
}
 
Example #14
Source File: FeatureWritable.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(final DataInput input) throws IOException {
  try {
    final String ns = input.readUTF();
    featureType =
        FeatureDataUtils.decodeType(
            "-".equals(ns) ? "" : ns,
            input.readUTF(),
            input.readUTF(),
            input.readUTF());
  } catch (final SchemaException e) {
    throw new IOException("Failed to parse the encoded feature type", e);
  }
  final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
  // read the fid
  final String fid = input.readUTF();
  // read the other attributes, build the feature
  for (final AttributeDescriptor ad : featureType.getAttributeDescriptors()) {
    final Object att = readAttribute(ad, input);
    builder.add(att);
  }

  // build the feature
  feature = builder.buildFeature(fid);
}
 
Example #15
Source File: VectorIngestRunner.java    From geowave with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: FeatureDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return Field Reader for the given Field ID
 */
@Override
public FieldReader<Object> getReader(final String fieldName) {
  // Go to the map to get a reader for given fieldId

  FieldReader<Object> reader = mapOfFieldNameToReaders.get(fieldName);

  // Check the map to see if a reader has already been found.
  if (reader == null) {
    // Reader not in Map, go to the reprojected feature type and get the
    // default reader
    final AttributeDescriptor descriptor = reprojectedFeatureType.getDescriptor(fieldName);
    final Class<?> bindingClass = descriptor.getType().getBinding();
    reader = (FieldReader<Object>) FieldUtils.getDefaultReaderForClass(bindingClass);

    // Add it to map for the next time
    mapOfFieldNameToReaders.put(fieldName, reader);
  }

  return reader;
}
 
Example #17
Source File: CorrelativeFieldSelector.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public void updateDataField() {
    if (pointDataSourceProperty.getValue() != null) {
        final List<AttributeDescriptor> attributeDescriptors = ((VectorDataNode) pointDataSourceProperty.getValue()).getFeatureType().getAttributeDescriptors();
        final List<AttributeDescriptor> result = new ArrayList<AttributeDescriptor>();
        result.add(new NullAttributeDescriptor());
        for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
            if (Number.class.isAssignableFrom(attributeDescriptor.getType().getBinding())) {
                result.add(attributeDescriptor);
            }
        }
        dataFieldProperty.getDescriptor().setValueSet(new ValueSet(result.toArray()));
    } else {
        dataFieldProperty.getDescriptor().setValueSet(null);
        try {
            dataFieldProperty.setValue(null);
        } catch (ValidationException ignore) {
        }
    }
}
 
Example #18
Source File: FeatureDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
private FieldVisibilityHandler<SimpleFeature, Object> getLocalVisibilityHandler(
    final String fieldName) {
  final VisibilityConfiguration visConfig = new VisibilityConfiguration(reprojectedFeatureType);

  // See if there is a visibility config stored in the reprojected feature
  // type
  if (reprojectedFeatureType.getDescriptor(visConfig.getAttributeName()) == null) {
    // No, so return the default field visibility handler
    return fieldVisiblityHandler;
  }

  // Yes, then get the descriptor for the given field ID
  final AttributeDescriptor descriptor = reprojectedFeatureType.getDescriptor(fieldName);

  return visConfig.getManager().createVisibilityHandler(
      descriptor.getLocalName(),
      fieldVisiblityHandler,
      visConfig.getAttributeName());
}
 
Example #19
Source File: ExportGeometryAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
static SimpleFeatureType changeGeometryType(SimpleFeatureType original, Class<?> geometryType) {
    SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
    sftb.setCRS(original.getCoordinateReferenceSystem());
    sftb.setDefaultGeometry(original.getGeometryDescriptor().getLocalName());
    boolean defaultGeometryAdded = false;
    for (AttributeDescriptor descriptor : original.getAttributeDescriptors()) {
        if (original.getGeometryDescriptor().getLocalName().equals(descriptor.getLocalName())) {
            sftb.add(descriptor.getLocalName(), geometryType);
            defaultGeometryAdded = true;
        }else {
            sftb.add(descriptor);
        }
    }
    if(!defaultGeometryAdded) {
        sftb.add(original.getGeometryDescriptor().getLocalName(), geometryType);
    }
    sftb.setName("FT_" + geometryType.getSimpleName());
    return sftb.buildFeatureType();
}
 
Example #20
Source File: TxtParser.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public void write(SimpleFeatureCollection obj, OutputStream output) throws IOException {
	SimpleFeatureIterator it = obj.features();

	PrintStream printStream = new PrintStream(output);

	while (it.hasNext()) {
		SimpleFeature ft = it.next();
		printStream.print(ft.getID() + " [");
		boolean first = true;
		for (AttributeDescriptor ad : ft.getType().getAttributeDescriptors()) {
			if (!first) {
				printStream.print(", ");
			}
			printStream.print(ad.getLocalName() + ": " + ft.getAttribute(ad.getName()));
			first = false;
		}
		printStream.println("]");
	}

}
 
Example #21
Source File: FeatureDataAdapter.java    From geowave with Apache License 2.0 6 votes vote down vote up
private void initializePositionMaps() {
  if (positionMapsInitialized) {
    return;
  }
  try {
    for (int i = 0; i < reprojectedFeatureType.getAttributeCount(); i++) {
      final AttributeDescriptor ad = reprojectedFeatureType.getDescriptor(i);
      final String currFieldName = ad.getLocalName();
      fieldToPositionMap.forcePut(currFieldName, i);
    }
    positionToFieldMap = fieldToPositionMap.inverse();
    positionMapsInitialized = true;
  } catch (final Exception e) {
    LOGGER.error("Unable to initialize position map, continuing anyways", e);
  }
}
 
Example #22
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static LinkedHashMap<String, String> feature2AlphanumericToHashmap( SimpleFeature feature ) {
    LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
    List<AttributeDescriptor> attributeDescriptors = feature.getFeatureType().getAttributeDescriptors();
    int index = 0;
    for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
        if (!(attributeDescriptor instanceof GeometryDescriptor)) {
            String fieldName = attributeDescriptor.getLocalName();
            Object attribute = feature.getAttribute(index);
            if (attribute == null) {
                attribute = "";
            }
            String value = attribute.toString();
            attributes.put(fieldName, value);
        }
        index++;
    }
    return attributes;
}
 
Example #23
Source File: VisibilityConfiguration.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc} Configure this VisibilityConfiguration object based on the passed in
 * SimpleFeatureType. This includes setting the 'attributeName' to the attribute that has a key of
 * 'visiblity'.
 *
 * @param persistType - object used to configure this VisibilityConfiguration object
 */
@Override
public void configureFromType(final SimpleFeatureType persistType) {
  // Search the list of attributes for one that has user data
  // with a key of 'visibility' and that the value of
  // it is Boolean.TRUE. If found, set this object's attributeName to
  // the found attribute.

  for (final AttributeDescriptor attrDesc : persistType.getAttributeDescriptors()) {
    if (attrDesc.getUserData().containsKey("visibility")
        && Boolean.TRUE.equals(attrDesc.getUserData().get("visibility"))) {
      attributeName = attrDesc.getLocalName();
    }
  }
  configureManager(persistType);
}
 
Example #24
Source File: BboxFunction.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public Aggregation<?, ?, SimpleFeature> getAggregation(
    final SimpleFeatureType featureType,
    final String[] functionArgs) {
  if (functionArgs == null || functionArgs.length != 1) {
    throw new RuntimeException("BBOX takes exactly 1 parameter");
  }
  final FieldNameParam columnName =
      functionArgs[0].equals("*") ? null : new FieldNameParam(functionArgs[0]);
  if (columnName != null) {
    AttributeDescriptor descriptor = featureType.getDescriptor(columnName.getFieldName());
    if (descriptor == null) {
      throw new RuntimeException(
          "No attribute called '" + columnName.getFieldName() + "' was found in the given type.");
    }
    if (!Geometry.class.isAssignableFrom(descriptor.getType().getBinding())) {
      throw new RuntimeException(
          "BBOX aggregation only works on geometry fields, given field was of type "
              + descriptor.getType().getBinding().getName()
              + ".");
    }
  }
  return new VectorBoundingBoxAggregation(columnName);
}
 
Example #25
Source File: SchemaConverter.java    From geowave with Apache License 2.0 6 votes vote down vote up
public static SimpleFeatureType schemaToFeatureType(
    final StructType schema,
    final String typeName) {
  final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
  typeBuilder.setName(typeName);
  typeBuilder.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
  try {
    typeBuilder.setCRS(CRS.decode("EPSG:4326", true));
  } catch (final FactoryException e) {
    LOGGER.error(e.getMessage(), e);
  }

  final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();

  for (final StructField field : schema.fields()) {
    final AttributeDescriptor attrDesc = attrDescFromStructField(attrBuilder, field);

    typeBuilder.add(attrDesc);
  }

  return typeBuilder.buildFeatureType();
}
 
Example #26
Source File: TimeDescriptors.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public void updateType(final SimpleFeatureType persistType) {
  for (final AttributeDescriptor attrDesc : persistType.getAttributeDescriptors()) {
    final Class<?> bindingClass = attrDesc.getType().getBinding();
    if (TimeUtils.isTemporal(bindingClass)) {
      attrDesc.getUserData().put("time", Boolean.FALSE);
    }
  }
  if (startRangeName != null) {
    persistType.getDescriptor(startRangeName).getUserData().put("start", Boolean.TRUE);
  }
  if (endRangeName != null) {
    persistType.getDescriptor(endRangeName).getUserData().put("end", Boolean.TRUE);
  }
  if (timeName != null) {
    persistType.getDescriptor(timeName).getUserData().put("time", Boolean.TRUE);
  }
}
 
Example #27
Source File: GeoWaveAvroFeatureUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: DateFieldRetypingSource.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void debugType(final String typeLabel, final SimpleFeatureType type) {
  if (LOGGER.isDebugEnabled()) {
    final StringBuilder logBuilder = new StringBuilder();
    logBuilder.append("Type: " + typeLabel);
    for (final AttributeDescriptor propDef : type.getAttributeDescriptors()) {
      logBuilder.append(
          "\nField: "
              + propDef.getLocalName()
              + ", Type: "
              + propDef.getType().getBinding().getSimpleName());
    }
    LOGGER.debug(logBuilder.toString());
  }
}
 
Example #29
Source File: AbstractFieldRetypingSource.java    From geowave with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clones the given schema, changing the geometry attribute to match the given dimensionality.
 *
 * @param schema schema to clone
 * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
 */
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
    SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(schema.getName());
    builder.setCRS(schema.getCoordinateReferenceSystem());
    for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
        if (isMixedGeometry(desc)) {
            GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
            GeometryType geomType = geomDescriptor.getType();

            Class<?> geometryClass = getGeometryForDimensionality(dimensionality);

            GeometryType gt =
                    new GeometryTypeImpl(
                            geomType.getName(),
                            geometryClass,
                            geomType.getCoordinateReferenceSystem(),
                            geomType.isIdentified(),
                            geomType.isAbstract(),
                            geomType.getRestrictions(),
                            geomType.getSuper(),
                            geomType.getDescription());

            builder.add(
                    new GeometryDescriptorImpl(
                            gt,
                            geomDescriptor.getName(),
                            geomDescriptor.getMinOccurs(),
                            geomDescriptor.getMaxOccurs(),
                            geomDescriptor.isNillable(),
                            geomDescriptor.getDefaultValue()));
        } else {
            builder.add(desc);
        }
    }
    schema = builder.buildFeatureType();
    return schema;
}