Java Code Examples for org.opengis.feature.simple.SimpleFeatureType#getDescriptor()

The following examples show how to use org.opengis.feature.simple.SimpleFeatureType#getDescriptor() . 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: 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 2
Source File: MathAggregationFunction.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(functionName() + " takes exactly 1 parameter");
  }
  if (functionArgs[0].equals("*")) {
    throw new RuntimeException(functionName() + " expects a numeric column.");
  }
  final FieldNameParam columnName = new FieldNameParam(functionArgs[0]);
  AttributeDescriptor descriptor = featureType.getDescriptor(columnName.getFieldName());
  if (descriptor == null) {
    throw new RuntimeException(
        "No attribute called '" + columnName.getFieldName() + "' was found in the given type.");
  }
  if (!Number.class.isAssignableFrom(descriptor.getType().getBinding())) {
    throw new RuntimeException(
        functionName()
            + " aggregation only works on numeric fields, given field was of type "
            + descriptor.getType().getBinding().getName()
            + ".");
  }
  return aggregation(columnName);
}
 
Example 3
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 4
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 5
Source File: ProfileDataTableModelTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    // Draw a "Z"
    path = new Path2D.Double();
    path.moveTo(0, 0);
    path.lineTo(3, 0);
    path.lineTo(0, 3);
    path.lineTo(3, 3);

    product = new Product("p", "t", 4, 4);
    band = product.addBand("b", "4 * (Y-0.5) + (X-0.5) + 0.1");

    dataSourceConfig = new ProfilePlotPanel.DataSourceConfig();
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.setName("ft");
    ftb.add("lat", Double.class);
    ftb.add("lon", Double.class);
    ftb.add("data", Double.class);
    SimpleFeatureType ft = ftb.buildFeatureType();
    DefaultFeatureCollection fc = new DefaultFeatureCollection("id", ft);
    fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.3}, ft, new FeatureIdImpl("id1"), false));
    fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.5}, ft, new FeatureIdImpl("id2"), false));
    fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.7}, ft, new FeatureIdImpl("id3"), false));
    fc.add(new SimpleFeatureImpl(new Object[]{0, 0, 0.1}, ft, new FeatureIdImpl("id4"), false));
    dataSourceConfig.pointDataSource = new VectorDataNode("vd", fc);
    dataSourceConfig.dataField = ft.getDescriptor("data");
    dataSourceConfig.boxSize = 1;
    dataSourceConfig.computeInBetweenPoints = true;
}
 
Example 6
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 7
Source File: CountFunction.java    From geowave with Apache License 2.0 5 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("COUNT takes exactly 1 parameter");
  }
  final FieldNameParam columnName =
      functionArgs[0].equals("*") ? null : new FieldNameParam(functionArgs[0]);
  if (columnName != null && featureType.getDescriptor(columnName.getFieldName()) == null) {
    throw new RuntimeException(
        "No attribute called '" + columnName.getFieldName() + "' was found in the given type.");
  }
  return new VectorCountAggregation(columnName);
}
 
Example 8
Source File: StatsConfigurationCollection.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void updateType(final SimpleFeatureType type) {
  for (final Map.Entry<String, StatsConfigurationCollection> item : attConfig.entrySet()) {
    final AttributeDescriptor desc = type.getDescriptor(item.getKey());
    if (desc == null) {
      LOGGER.error("Attribute " + item.getKey() + " not found for statistics configuration");
      continue;
    }
    desc.getUserData().put("stats", item.getValue());
  }
}
 
Example 9
Source File: TimeDescriptors.java    From geowave with Apache License 2.0 5 votes vote down vote up
public void update(
    final SimpleFeatureType type,
    final TimeDescriptorConfiguration configuration) {
  if (configuration.timeName != null) {
    time = type.getDescriptor(configuration.timeName);
  }
  if (configuration.startRangeName != null) {
    startRange = type.getDescriptor(configuration.startRangeName);
  }
  if (configuration.endRangeName != null) {
    endRange = type.getDescriptor(configuration.endRangeName);
  }
}
 
Example 10
Source File: GeoWaveVectorMetadataReader.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
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 11
Source File: GeoWaveGTPluginUtils.java    From geowave with Apache License 2.0 4 votes vote down vote up
protected static Object convertToType(
    final String attrName,
    final Object value,
    final SimpleFeatureType featureType) {
  final AttributeDescriptor descriptor = featureType.getDescriptor(attrName);
  if (descriptor == null) {
    return value;
  }
  final Class<?> attrClass = descriptor.getType().getBinding();
  if (attrClass.isInstance(value)) {
    return value;
  }
  if (Number.class.isAssignableFrom(attrClass) && Number.class.isInstance(value)) {
    if (Double.class.isAssignableFrom(attrClass)) {
      return ((Number) value).doubleValue();
    }
    if (Float.class.isAssignableFrom(attrClass)) {
      return ((Number) value).floatValue();
    }
    if (Long.class.isAssignableFrom(attrClass)) {
      return ((Number) value).longValue();
    }
    if (Integer.class.isAssignableFrom(attrClass)) {
      return ((Number) value).intValue();
    }
    if (Short.class.isAssignableFrom(attrClass)) {
      return ((Number) value).shortValue();
    }
    if (Byte.class.isAssignableFrom(attrClass)) {
      return ((Number) value).byteValue();
    }
    if (BigInteger.class.isAssignableFrom(attrClass)) {
      return BigInteger.valueOf(((Number) value).longValue());
    }
    if (BigDecimal.class.isAssignableFrom(attrClass)) {
      return BigDecimal.valueOf(((Number) value).doubleValue());
    }
  }
  if (Calendar.class.isAssignableFrom(attrClass)) {
    if (Date.class.isInstance(value)) {
      final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
      c.setTime((Date) value);
      return c;
    }
  }
  if (Timestamp.class.isAssignableFrom(attrClass)) {
    if (Date.class.isInstance(value)) {
      final Timestamp ts = new Timestamp(((Date) value).getTime());
      return ts;
    }
  }
  return value;
}