Java Code Examples for org.opengis.feature.type.AttributeDescriptor#getDefaultValue()

The following examples show how to use org.opengis.feature.type.AttributeDescriptor#getDefaultValue() . 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: 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 2
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 3
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 4
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 5
Source File: FeatureNumericHistogramStaticticsTest.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 6
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 7
Source File: SimpleFeatureCentroidExractorTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws SchemaException {
  final SimpleFeatureType schema =
      DataUtilities.createType("testGeo", "location:Point:srid=4326,name:String");
  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 feature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());
  final GeometryFactory geoFactory = new GeometryFactory();

  feature.setAttribute("location", geoFactory.createPoint(new Coordinate(-45, 45)));

  final Point point = extractor.getCentroid(feature);
  assertEquals(4326, point.getSRID());
}
 
Example 8
Source File: CQLQueryFilterTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws SchemaException, CQLException {
  type =
      DataUtilities.createType(
          "geostuff",
          "geom:Geometry:srid=4326,pop:java.lang.Long,pid:String");

  final List<AttributeDescriptor> descriptors = type.getAttributeDescriptors();
  defaults = new Object[descriptors.size()];
  int p = 0;
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }
}
 
Example 9
Source File: FeatureCountMinSketchStaticticsTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
private SimpleFeature create(final String pid) {
  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);

  return newFeature;
}
 
Example 10
Source File: CentroidManagerGeoWave.java    From geowave with Apache License 2.0 5 votes vote down vote up
public SimpleFeatureConverter(
    final FeatureDataAdapter adapter,
    final Class<? extends Geometry> shapeClass) {
  type = createFeatureType(adapter.getFeatureType(), shapeClass);
  int p = 0;
  this.shapeClass = shapeClass;
  final List<AttributeDescriptor> descriptors =
      adapter.getFeatureType().getAttributeDescriptors();
  defaults = new Object[descriptors.size()];
  for (final AttributeDescriptor descriptor : descriptors) {
    defaults[p++] = descriptor.getDefaultValue();
  }
}
 
Example 11
Source File: FeatureSerializationTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws SchemaException {
  final Kryo kryo = new Kryo();

  kryo.register(SimpleFeatureImpl.class, new FeatureSerializer());

  final SimpleFeatureType schema =
      DataUtilities.createType("testGeo", "location:Point:srid=4326,name:String");
  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 feature =
      SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString());
  final GeometryFactory geoFactory = new GeometryFactory();

  feature.setAttribute("location", geoFactory.createPoint(new Coordinate(-45, 45)));
  final Output output = new OutputChunked();
  kryo.getSerializer(SimpleFeatureImpl.class).write(kryo, output, feature);
  final Input input = new InputChunked();
  input.setBuffer(output.getBuffer());
  final SimpleFeature f2 =
      (SimpleFeature) kryo.getSerializer(SimpleFeatureImpl.class).read(
          kryo,
          input,
          SimpleFeatureImpl.class);
  assertEquals(feature, f2);
}
 
Example 12
Source File: FeatureDataAdapterTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void testInferredRange() throws SchemaException {

  final SimpleFeatureType schema =
      DataUtilities.createType(
          "http://foo",
          "sp.geostuff",
          "geometry:Geometry:srid=4326,pop:java.lang.Long,start:Date,end:Date,pid:String");

  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", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("start", time1);
  newFeature.setAttribute("end", time2);
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));

  final FeatureDataAdapter dataAdapter =
      new FeatureDataAdapter(
          schema,
          new GlobalVisibilityHandler<SimpleFeature, Object>("default"));
  final Index spatialIndex =
      new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions());
  dataAdapter.init(spatialIndex);
  final byte[] binary = dataAdapter.toBinary();

  final FeatureDataAdapter dataAdapterCopy = new FeatureDataAdapter();
  dataAdapterCopy.fromBinary(binary);

  assertEquals("http://foo", dataAdapterCopy.getFeatureType().getName().getNamespaceURI());

  assertEquals(dataAdapterCopy.getTypeName(), dataAdapter.getTypeName());
  assertEquals(dataAdapterCopy.getFeatureType(), dataAdapter.getFeatureType());
  assertEquals(
      Boolean.TRUE,
      dataAdapterCopy.getFeatureType().getDescriptor("end").getUserData().get("end"));
  assertEquals(
      Boolean.TRUE,
      dataAdapterCopy.getFeatureType().getDescriptor("start").getUserData().get("start"));

  final List<IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object>> handlers =
      dataAdapterCopy.getDefaultTypeMatchingHandlers(schema);
  boolean found = false;
  for (final IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object> handler : handlers) {
    found |=
        ((handler instanceof FeatureTimeRangeHandler)
            && ((((FeatureTimeRangeHandler) handler).toIndexValue(
                newFeature).toNumericData().getMin() - time1.getTime()) < 0.001)
            && ((((FeatureTimeRangeHandler) handler).toIndexValue(
                newFeature).toNumericData().getMax() - time2.getTime()) < 0.001));
  }

  assertTrue(found);
}
 
Example 13
Source File: GeoWaveAvroFeatureDataAdapterTest.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Test
public void testInferredRange() throws SchemaException {

  final SimpleFeatureType schema =
      DataUtilities.createType(
          "sp.geostuff",
          "geometry:Geometry:srid=4326,pop:java.lang.Long,start:Date,end:Date,pid:String");

  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", Long.valueOf(100));
  newFeature.setAttribute("pid", UUID.randomUUID().toString());
  newFeature.setAttribute("start", time1);
  newFeature.setAttribute("end", time2);
  newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));

  final GeoWaveAvroFeatureDataAdapter dataAdapter =
      new GeoWaveAvroFeatureDataAdapter(
          schema,
          new GlobalVisibilityHandler<SimpleFeature, Object>("default"));
  final Index index = new SpatialIndexBuilder().createIndex();
  dataAdapter.init(index);
  final byte[] binary = dataAdapter.toBinary();

  final GeoWaveAvroFeatureDataAdapter dataAdapterCopy = new GeoWaveAvroFeatureDataAdapter();
  dataAdapterCopy.fromBinary(binary);

  assertEquals(dataAdapterCopy.getTypeName(), dataAdapter.getTypeName());
  assertEquals(dataAdapterCopy.getFeatureType(), dataAdapter.getFeatureType());
  assertEquals(
      Boolean.TRUE,
      dataAdapterCopy.getFeatureType().getDescriptor("end").getUserData().get("end"));
  assertEquals(
      Boolean.TRUE,
      dataAdapterCopy.getFeatureType().getDescriptor("start").getUserData().get("start"));

  final List<IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object>> handlers =
      dataAdapterCopy.getDefaultTypeMatchingHandlers(schema);
  boolean found = false;
  for (final IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object> handler : handlers) {
    found |=
        ((handler instanceof FeatureTimeRangeHandler)
            && ((((FeatureTimeRangeHandler) handler).toIndexValue(
                newFeature).toNumericData().getMin() - time1.getTime()) < 0.001)
            && ((((FeatureTimeRangeHandler) handler).toIndexValue(
                newFeature).toNumericData().getMax() - time2.getTime()) < 0.001));
  }

  assertTrue(found);
}
 
Example 14
Source File: AnalyticFeature.java    From geowave with Apache License 2.0 4 votes vote down vote up
public static SimpleFeature createGeometryFeature(
    final SimpleFeatureType featureType,
    final String batchId,
    final String dataId,
    final String name,
    final String groupID,
    final double weight,
    final Geometry geometry,
    final String[] extraDimensionNames,
    final double[] extraDimensions,
    final int zoomLevel,
    final int iteration,
    final long count) {
  if (extraDimensionNames.length != extraDimensions.length) {
    LOGGER.error(
        "The number of extraDimension names does not equal the number of extraDimensions");
    throw new IllegalArgumentException(
        "The number of extraDimension names does not equal the number of extraDimensions");
  }
  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, dataId);
  newFeature.setAttribute(ClusterFeatureAttribute.NAME.attrName(), name);
  newFeature.setAttribute(ClusterFeatureAttribute.GROUP_ID.attrName(), groupID);
  newFeature.setAttribute(ClusterFeatureAttribute.ITERATION.attrName(), iteration);
  newFeature.setAttribute(ClusterFeatureAttribute.WEIGHT.attrName(), weight);
  newFeature.setAttribute(ClusterFeatureAttribute.BATCH_ID.attrName(), batchId);
  newFeature.setAttribute(ClusterFeatureAttribute.COUNT.attrName(), count);
  newFeature.setAttribute(ClusterFeatureAttribute.GEOMETRY.attrName(), geometry);
  newFeature.setAttribute(ClusterFeatureAttribute.ZOOM_LEVEL.attrName(), zoomLevel);
  int i = 0;
  for (final String dimName : extraDimensionNames) {
    newFeature.setAttribute(dimName, new Double(extraDimensions[i++]));
  }
  return newFeature;
}