Java Code Examples for org.opengis.feature.type.AttributeDescriptor

The following examples show how to use org.opengis.feature.type.AttributeDescriptor. These examples are extracted from open source projects. 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 Project: geowave   Source File: VectorIngestRunner.java    License: 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 2
/**
 * 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 3
Source Project: sldeditor   Source File: InLineFeatureModel.java    License: 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 4
Source Project: geowave   Source File: SchemaConverter.java    License: 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 5
@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 Project: geowave   Source File: CentroidManagerGeoWave.java    License: 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 7
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 8
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 9
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 10
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 11
Source Project: geowave   Source File: VectorIngestRunner.java    License: 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 12
Source Project: geowave   Source File: SchemaConverter.java    License: 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 13
Source Project: geowave   Source File: FeatureDataAdapter.java    License: 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 14
Source Project: geowave   Source File: FeatureDataAdapter.java    License: 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 15
Source Project: geowave   Source File: FeatureDataAdapter.java    License: 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 16
Source Project: geowave   Source File: FeatureDataAdapter.java    License: 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 17
Source Project: geowave   Source File: VisibilityConfiguration.java    License: 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 18
Source Project: geowave   Source File: BboxFunction.java    License: 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 19
Source Project: geowave   Source File: FeatureWritable.java    License: 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 20
Source Project: geowave   Source File: TimeDescriptors.java    License: 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 21
Source Project: geowave   Source File: QueryIndexHelper.java    License: 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 22
Source Project: geowave   Source File: FeatureDataUtils.java    License: 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 23
Source Project: geowave   Source File: FeatureAttributeDimensionField.java    License: 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 24
@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 25
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 26
Source Project: geowave   Source File: FeatureHyperLogLogStaticticsTest.java    License: 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 27
/**
 * 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;
}
 
Example 28
/**
 * Checks if the given schema contains a GeometryDescriptor that has a generic Geometry type.
 *
 * @param schema
 */
private boolean hasMixedGeometry(SimpleFeatureType schema) {
    for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) {
        if (isMixedGeometry(attDesc)) {
            return true;
        }
    }
    return false;
}
 
Example 29
Source Project: geowave   Source File: SchemaConverter.java    License: Apache License 2.0 5 votes vote down vote up
private static SimpleFeatureDataType attrDescToDataType(final AttributeDescriptor attrDesc) {
  boolean isGeom = false;
  DataType dataTypeOut = DataTypes.NullType;

  if (attrDesc.getType().getBinding().equals(String.class)) {

    dataTypeOut = DataTypes.StringType;
  } else if (attrDesc.getType().getBinding().equals(Double.class)) {
    dataTypeOut = DataTypes.DoubleType;
  } else if (attrDesc.getType().getBinding().equals(Float.class)) {
    dataTypeOut = DataTypes.FloatType;
  } else if (attrDesc.getType().getBinding().equals(Long.class)) {
    dataTypeOut = DataTypes.LongType;
  } else if (attrDesc.getType().getBinding().equals(Integer.class)) {
    dataTypeOut = DataTypes.IntegerType;
  } else if (attrDesc.getType().getBinding().equals(Boolean.class)) {
    dataTypeOut = DataTypes.BooleanType;
  } else if (attrDesc.getType().getBinding().equals(Date.class)) {
    dataTypeOut = DataTypes.TimestampType;
  }

  // Custom geometry types get WKB encoding
  else if (Geometry.class.isAssignableFrom(attrDesc.getType().getBinding())) {
    dataTypeOut = GeoWaveSpatialEncoders.geometryUDT;
    isGeom = true;
  }

  return new SimpleFeatureDataType(dataTypeOut, isGeom);
}
 
Example 30
Source Project: elasticgeo   Source File: FilterToElastic.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Writes the FilterBuilder for the attribute Expression.
 * 
 * @param expression the attribute.
 *
 */
@Override
public Object visit(PropertyName expression, Object extraData) {
    LOGGER.finest("exporting PropertyName");

    SimpleFeatureType featureType = this.featureType;

    Class<?> target = null;
    if(extraData instanceof Class) {
        target = (Class<?>) extraData;
    }

    //first evaluate expression against feature type get the attribute, 
    AttributeDescriptor attType = (AttributeDescriptor) expression.evaluate(featureType);

    String encodedField; 
    if ( attType != null ) {
        Map<Object, Object> userData = attType.getUserData();
        if( userData != null && userData.containsKey("full_name") ) {
            encodedField = userData.get("full_name").toString();
        } else {
            encodedField = attType.getLocalName();
        }
        if(target != null && target.isAssignableFrom(attType.getType().getBinding())) {
            // no need for casting, it's already the right type
            target = null;
        }
    } else {
        // fall back to just encoding the property name
        encodedField = expression.getPropertyName();
    }

    if (target != null) {
        LOGGER.fine("PropertyName type casting not implemented");
    }
    field = encodedField;

    return extraData;
}