Java Code Examples for org.geotools.feature.simple.SimpleFeatureTypeBuilder

The following examples show how to use org.geotools.feature.simple.SimpleFeatureTypeBuilder. 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: constellation   Source File: Shape.java    License: Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType generateFeatureType(final String uuid, final String srs,
        final String geometryName, final Class<? extends Geometry> geometryClass,
        final Map<String, Class<?>> attributes) {
    final SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
    featureTypeBuilder.setName(uuid);
    featureTypeBuilder.setSRS(srs);
    featureTypeBuilder.add(geometryName, geometryClass);
    featureTypeBuilder.add(NAME_ATTRIBUTE, String.class);
    featureTypeBuilder.add(CENTROID_LATITUDE_ATTRIBUTE, Double.class);
    featureTypeBuilder.add(CENTROID_LONGITUDE_ATTRIBUTE, Double.class);
    featureTypeBuilder.add(RADIUS_ATTRIBUTE, Double.class);
    if (attributes != null) {
        attributes.forEach(featureTypeBuilder::add);
    }
    return featureTypeBuilder.buildFeatureType();
}
 
Example 2
Source Project: hortonmachine   Source File: OmsZonalStats.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static SimpleFeatureBuilder createFeatureBuilder( CoordinateReferenceSystem crs, boolean hasUserTotalMean ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("stats");
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add(MIN, Double.class);
    b.add(MAX, Double.class);
    b.add(AVG, Double.class);
    b.add(VAR, Double.class);
    b.add(SDEV, Double.class);
    b.add(SUM, Double.class);
    if (hasUserTotalMean)
        b.add(AVGABSDEV, Double.class);
    b.add(ACTCELLS, Integer.class);
    b.add(INVCELLS, Integer.class);
    SimpleFeatureType type = b.buildFeatureType();
    return new SimpleFeatureBuilder(type);
}
 
Example 3
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals,
        List<LineString> horizontals ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POINT);
    b.setCRS(crs);
    b.add("the_geom", Point.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0]));
    Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0]));

    Geometry intersection = gHor.intersection(gVer);

    long index = 0;
    int numGeometries = intersection.getNumGeometries();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = intersection.getGeometryN(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example 4
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata )
        throws Exception {
    final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope();
    ReferencedEnvelope env2d = new ReferencedEnvelope(envelope);
    final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d));

    final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("lasdataenvelope");
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add("id", String.class);
    final SimpleFeatureType type = b.buildFeatureType();

    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    final Object[] values = new Object[]{polygon, lasFile.getName()};
    builder.addAll(values);
    final SimpleFeature feature = builder.buildFeature(null);
    ((DefaultFeatureCollection) outGeodata).add(feature);
    OmsVectorWriter.writeVector(outFile, outGeodata);
}
 
Example 5
/**
 * @param oldFeatureType the {@link FeatureType} of the existing features.
 * @throws FactoryRegistryException 
 * @throws SchemaException
 */
public FeatureGeometrySubstitutor( SimpleFeatureType oldFeatureType, Class< ? > newGeometryType ) throws Exception {

    List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType.getAttributeDescriptors();

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(oldFeatureType.getName());
    b.setCRS(oldFeatureType.getCoordinateReferenceSystem());

    if (newGeometryType == null) {
        b.addAll(oldAttributeDescriptors);
    } else {
        for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) {
            if (attributeDescriptor instanceof GeometryDescriptor) {
                b.add("the_geom", newGeometryType);
            } else {
                b.add(attributeDescriptor);
            }
        }
    }
    newFeatureType = b.buildFeatureType();
}
 
Example 6
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 7
/**
 * Builds a line feature from a dwg polyline 3D.
 * 
 * TODO handle these as contourlines
 * 
 */
public SimpleFeature convertDwgPolyline3D( String typeName, String layerName,
        DwgPolyline3D polyline3d, int id ) {
    double[][] ptos = polyline3d.getPts();
    CoordinateList coordList = new CoordinateList();
    if (ptos != null) {
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j][0], ptos[j][1], ptos[j][2]);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
 
Example 8
/**
 * Builds a line feature from a dwg polyline 2D.
 * 
 */
public SimpleFeature convertDwgLwPolyline( String typeName, String layerName,
        DwgLwPolyline lwPolyline, int id ) {
    Point2D[] ptos = lwPolyline.getVertices();
    if (ptos != null) {
        CoordinateList coordList = new CoordinateList();
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
 
Example 9
/**
 * Builds a line feature from a dwg line.
 * 
 */
public SimpleFeature convertDwgLine( String typeName, String layerName, DwgLine line, int id ) {
    double[] p1 = line.getP1();
    double[] p2 = line.getP2();
    Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]),
            new Point2D.Double(p2[0], p2[1])};
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example 10
Source Project: geowave   Source File: GeoLifeUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static SimpleFeatureType createGeoLifeTrackDataType() {

    final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
    simpleFeatureTypeBuilder.setName(GEOLIFE_TRACK_FEATURE);

    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();

    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Date.class).nillable(true).buildDescriptor("StartTimeStamp"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Date.class).nillable(true).buildDescriptor("EndTimeStamp"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("Duration"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("NumberPoints"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("TrackId"));
    return simpleFeatureTypeBuilder.buildFeatureType();
  }
 
Example 11
Source Project: geowave   Source File: CentroidManagerGeoWave.java    License: Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType createFeatureType(
    final SimpleFeatureType featureType,
    final Class<? extends Geometry> shapeClass) {
  try {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(featureType.getName().getLocalPart());
    builder.setNamespaceURI(featureType.getName().getNamespaceURI());
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    for (final AttributeDescriptor attr : featureType.getAttributeDescriptors()) {
      if (attr.getType() instanceof GeometryType) {
        builder.add(attr.getLocalName(), shapeClass);
      } else {
        builder.add(attr.getLocalName(), attr.getType().getBinding());
      }
    }
    return builder.buildFeatureType();
  } catch (final Exception e) {
    LOGGER.warn("Schema Creation Error.  Hint: Check the SRID.", e);
  }

  return null;
}
 
Example 12
@SuppressWarnings("nls")
public void testFeatureUtils() throws Exception {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("typename");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add("AttrName", String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Object[] values = new Object[]{GeometryUtilities.gf().createPoint(new Coordinate(0, 0)), "test"};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(type.getTypeName());

    Object attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrname");
    assertEquals("test", attr.toString());
    attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrnam");
    assertNull(attr);
}
 
Example 13
Source Project: geowave   Source File: BandFeatureIterator.java    License: Apache License 2.0 6 votes vote down vote up
private void init(final Filter cqlFilter) throws NoSuchAuthorityCodeException, FactoryException {
  final SimpleFeatureTypeBuilder typeBuilder =
      sceneIterator.getProvider().bandFeatureTypeBuilder();
  final SimpleFeatureType bandType = typeBuilder.buildFeatureType();

  Iterator<SimpleFeature> featureIterator = new FeatureIteratorIterator<>(sceneIterator);
  featureIterator =
      Iterators.concat(
          Iterators.transform(featureIterator, new SceneToBandFeatureTransform(bandType)));

  if ((cqlFilter != null) && !cqlFilter.equals(Filter.INCLUDE)) {
    final String[] attributes = DataUtilities.attributeNames(cqlFilter, bandType);

    // we can rely on the scene filtering if we don't have to check any
    // specific band filters
    if (ArrayUtils.contains(attributes, BAND_ATTRIBUTE_NAME)) {
      featureIterator =
          Iterators.filter(
              featureIterator,
              new SceneFeatureIterator.CqlFilterPredicate(cqlFilter));
    }
  }
  iterator = featureIterator;
}
 
Example 14
Source Project: geowave   Source File: FeatureDataUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static FeatureDataAdapter cloneFeatureDataAdapter(
    final DataStorePluginOptions storeOptions,
    final String originalTypeName,
    final String newTypeName) {

  // Get original feature type info
  final SimpleFeatureType oldType =
      FeatureDataUtils.getFeatureType(storeOptions, originalTypeName);

  // Build type using new name
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  sftBuilder.init(oldType);
  sftBuilder.setName(newTypeName);
  final SimpleFeatureType newType = sftBuilder.buildFeatureType();

  // Create new adapter that will use new typename
  final FeatureDataAdapter newAdapter = new FeatureDataAdapter(newType);

  return newAdapter;
}
 
Example 15
private SimpleFeatureCollection featureCollectionFromNonGroundCoordinates( CoordinateReferenceSystem crs,
        List<Coordinate> nonGroundCoordinateList ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("nongroundpoints");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Point.class);
    b.add("elev", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Coordinate c : nonGroundCoordinateList ) {
        Point g = gf.createPoint(c);
        Object[] values = new Object[]{g, c.z};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example 16
private static SimpleFeatureType createTrackFeatureType(GeoCoding geoCoding) {
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.setName("org.esa.snap.TrackPoint");
    /*0*/
    ftb.add("pixelPos", Point.class, geoCoding.getImageCRS());
    /*1*/
    ftb.add("geoPos", Point.class, DefaultGeographicCRS.WGS84);
    /*2*/
    ftb.add("data", Double.class);
    ftb.setDefaultGeometry(geoCoding instanceof CrsGeoCoding ? "geoPos" : "pixelPos");
    // GeoTools Bug: this doesn't work
    // ftb.userData("trackPoints", "true");
    final SimpleFeatureType ft = ftb.buildFeatureType();
    ft.getUserData().put("trackPoints", "true");
    return ft;
}
 
Example 17
/**
 * 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 18
Source Project: geowave   Source File: CustomIndexExample.java    License: Apache License 2.0 5 votes vote down vote up
private SimpleFeatureType getSimpleFeatureType() {
  final String NAME = "ExampleType";
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  final AttributeTypeBuilder atBuilder = new AttributeTypeBuilder();
  sftBuilder.setName(NAME);
  sftBuilder.add(atBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
  sftBuilder.add(atBuilder.binding(String.class).nillable(false).buildDescriptor("uuid"));

  return sftBuilder.buildFeatureType();
}
 
Example 19
Source Project: elasticgeo   Source File: TestUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static SimpleFeatureCollection createAggregationFeatures(List<Map<String,Object>> data) {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName( "testType" );
    builder.add("_aggregation", HashMap.class );
    builder.add("aString", String.class );
    final SimpleFeatureType featureType = builder.buildFeatureType();
    final DefaultFeatureCollection collection = new DefaultFeatureCollection();
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
    data.forEach(item -> {
        item.keySet().forEach(key -> featureBuilder.set(key, item.get(key)));
        collection.add(featureBuilder.buildFeature(null));
    });
    return collection;
}
 
Example 20
Source Project: elasticgeo   Source File: ElasticFilterTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addDateWithFormatToFeatureType(String format) {
    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.init(featureType);

    AttributeDescriptor dateAtt;
    AttributeTypeBuilder dateAttBuilder = new AttributeTypeBuilder();
    dateAttBuilder.setName("dateAttrWithFormat");
    dateAttBuilder.setBinding(Date.class);
    dateAtt = dateAttBuilder.buildDescriptor("dateAttrWithFormat", dateAttBuilder.buildType());
    dateAtt.getUserData().put(DATE_FORMAT, format);
    typeBuilder.add(dateAtt);

    featureType = typeBuilder.buildFeatureType();
    setFilterBuilder();
}
 
Example 21
Source Project: rya   Source File: GeoWaveGTQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
private static SimpleFeatureType getPointSimpleFeatureType() {
    final String name = "PointSimpleFeatureType";
    final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
    final AttributeTypeBuilder atBuilder = new AttributeTypeBuilder();
    sftBuilder.setName(name);
    sftBuilder.add(atBuilder.binding(String.class).nillable(false)
        .buildDescriptor("locationName"));
    sftBuilder.add(atBuilder.binding(Geometry.class).nillable(false)
        .buildDescriptor("geometry"));

    return sftBuilder.buildFeatureType();
}
 
Example 22
Source Project: geowave   Source File: FeatureDefinitionSet.java    License: Apache License 2.0 5 votes vote down vote up
private static void parseFeatureDefinition(final FeatureDefinition fd) {
  final SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
  sftb.setName(fd.name);
  final AttributeTypeBuilder atb = new AttributeTypeBuilder();
  // Class geomClass = null;
  // switch (fd.Type) {
  // case Geometry: {
  // geomClass = Geometry.class;
  // break;
  // }
  // case Point: {
  // geomClass = Point.class;
  // break;
  // }
  // case LineString: {
  // geomClass = LineString.class;
  // break;
  // }
  // case Polygon: {
  // geomClass = Polygon.class;
  // }
  // }
  // sftb.add(atb.binding(geomClass).nillable(false).buildDescriptor("geometry"));
  for (final AttributeDefinition ad : fd.attributes) {
    final AttributeType at = AttributeTypes.getAttributeType(ad.type);
    if (ad.name == null) {
      System.out.println("yo");
    }
    if (at != null) {
      sftb.add(
          atb.binding(at.getClassType()).nillable(true).buildDescriptor(
              normalizeOsmNames(ad.name)));
    }
  }
  final SimpleFeatureType sft = sftb.buildFeatureType();
  featureTypes.put(fd.name, sft);
  featureAdapters.put(fd.name, new FeatureDataAdapter(sft));
}
 
Example 23
/**
 * @param oldFeatureType the {@link FeatureType} of the existing features.
 * @param fieldArray the list of the names of new fields. 
 * @param classesArray the list of classes of the new fields.
 * @throws FactoryRegistryException 
 * @throws SchemaException
 */
public FeatureExtender( SimpleFeatureType oldFeatureType, String[] fieldArray,
        Class<?>[] classesArray ) throws FactoryRegistryException, SchemaException {

    List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType
            .getAttributeDescriptors();
    List<AttributeDescriptor> addedAttributeDescriptors = new ArrayList<AttributeDescriptor>();
    for( int i = 0; i < fieldArray.length; i++ ) {
        AttributeTypeBuilder build = new AttributeTypeBuilder();
        build.setNillable(true);
        build.setBinding(classesArray[i]);
        AttributeDescriptor descriptor = build.buildDescriptor(fieldArray[i]);
        addedAttributeDescriptors.add(descriptor);
    }

    List<AttributeDescriptor> newAttributesTypesList = new ArrayList<AttributeDescriptor>();
    for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) {
        newAttributesTypesList.add(attributeDescriptor);
    }
    newAttributesTypesList.addAll(addedAttributeDescriptors);

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(oldFeatureType.getName());
    b.setCRS(oldFeatureType.getCoordinateReferenceSystem());
    b.addAll(newAttributesTypesList);
    newFeatureType = b.buildFeatureType();
}
 
Example 24
public static SimpleFeature toDummyFeature( Geometry geom, CoordinateReferenceSystem crs ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("dummy");
    if (crs != null)
        b.setCRS(crs);
    b.add("the_geom", geom.getClass());
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Object[] values = new Object[]{geom};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(null);
    return feature;
}
 
Example 25
public static SimpleFeatureType getSimpleNotesfeatureType() {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("gpsimplenotes"); //$NON-NLS-1$
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class); //$NON-NLS-1$
        b.add(NOTES_textFN, String.class);
        b.add(NOTES_descFN, String.class);
        b.add(NOTES_tsFN, String.class);
        b.add(NOTES_altimFN, Double.class);
        b.add(NOTES_dirtyFN, Integer.class);
        SimpleFeatureType featureType = b.buildFeatureType();
        return featureType;
    }
 
Example 26
public static SimpleFeatureType getMediaFeaturetype() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("geopaparazzimediapoints");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);

    b.add(IMAGES_altimFN, String.class);
    b.add(IMAGES_tsFN, String.class);
    b.add(IMAGES_azimFN, Double.class);
    b.add(IMAGES_imageidFN, Long.class);
    SimpleFeatureType featureType = b.buildFeatureType();
    return featureType;
}
 
Example 27
Source Project: geowave   Source File: FeatureTranslatingIterator.java    License: Apache License 2.0 5 votes vote down vote up
private void initialize(final SimpleFeatureType originalType) {
  final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
  sftBuilder.setName(originalType.getName());
  for (final AttributeDescriptor ad : originalType.getAttributeDescriptors()) {
    if (fields.contains(ad.getLocalName())) {
      sftBuilder.add(ad.getLocalName(), ad.getClass());
    }
  }
  newType = sftBuilder.buildFeatureType();
  sfBuilder = new SimpleFeatureBuilder(newType);
}
 
Example 28
private SimpleFeature createPointTextFeature( String typeName, String layerName, int id,
        Coordinate coord, String textString ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, Point.class);
    b.add("text", String.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry point = gF.createPoint(coord);
    Object[] values = new Object[]{point, textString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example 29
Source Project: geowave   Source File: SimpleIngest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * * A simple feature is just a mechanism for defining attributes (a feature is just a collection
 * of attributes + some metadata) We need to describe what our data looks like so the serializer
 * (FeatureDataAdapter for this case) can know how to store it. Features/Attributes are also a
 * general convention of GIS systems in general.
 *
 * @return Simple Feature definition for our demo point feature
 */
public static SimpleFeatureType createPointFeatureType() {

  final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
  final AttributeTypeBuilder ab = new AttributeTypeBuilder();

  // Names should be unique (at least for a given GeoWave namespace) -
  // think about names in the same sense as a full classname
  // The value you set here will also persist through discovery - so when
  // people are looking at a dataset they will see the
  // type names associated with the data.
  builder.setName(FEATURE_NAME);

  // The data is persisted in a sparse format, so if data is nullable it
  // will not take up any space if no values are persisted.
  // Data which is included in the primary index (in this example
  // lattitude/longtiude) can not be null
  // Calling out latitude an longitude separately is not strictly needed,
  // as the geometry contains that information. But it's
  // convienent in many use cases to get a text representation without
  // having to handle geometries.
  builder.add(ab.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
  builder.add(ab.binding(Date.class).nillable(true).buildDescriptor("TimeStamp"));
  builder.add(ab.binding(Double.class).nillable(false).buildDescriptor("Latitude"));
  builder.add(ab.binding(Double.class).nillable(false).buildDescriptor("Longitude"));
  builder.add(ab.binding(String.class).nillable(true).buildDescriptor("TrajectoryID"));
  builder.add(ab.binding(String.class).nillable(true).buildDescriptor("Comment"));

  return builder.buildFeatureType();
}
 
Example 30
Source Project: geowave   Source File: TwitterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType createTwitterEventDataType() {

    final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder();
    simpleFeatureTypeBuilder.setName(TWITTER_SFT_NAME);

    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();

    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_USERID_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_USERNAME_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_TEXT_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_INREPLYTOUSER_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_INREPLYTOSTATUS_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor(
            TWITTER_RETWEETCOUNT_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor(
            TWITTER_LANG_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor(
            TWITTER_DTG_ATTRIBUTE));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor(
            TWITTER_GEOMETRY_ATTRIBUTE));

    return simpleFeatureTypeBuilder.buildFeatureType();
  }