Java Code Examples for org.opengis.feature.simple.SimpleFeatureType

The following examples show how to use org.opengis.feature.simple.SimpleFeatureType. 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   Author: constellation-app   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   Author: TheHortonMachine   File: FeatureElevationComparer.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param newGeometry new geometry to insert.
 */
public void substituteGeometry( Geometry newGeometry ) {
    if (toRemove) {
        return;
    }
    if (newGeometry.getLength() < lengthThreshold) {
        feature = null;
        geometry = null;
        toRemove = true;
        return;
    }

    Object[] attributes = feature.getAttributes().toArray();
    Object[] newAttributes = new Object[attributes.length];
    System.arraycopy(attributes, 0, newAttributes, 0, attributes.length);
    newAttributes[0] = newGeometry;

    SimpleFeatureType featureType = feature.getFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    builder.addAll(newAttributes);
    feature = builder.buildFeature(feature.getID());
    geometry = newGeometry;
    bufferPolygon = geometry.buffer(buffer);
}
 
Example #3
Source Project: sldeditor   Author: robward-scisys   File: DataSourceInfo.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the feature store.
 *
 * @return the feature store
 */
public FeatureStore<SimpleFeatureType, SimpleFeature> getFeatureStore() {
    FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = null;

    if(dataStore != null)
    {
        try
        {
            FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName);

            featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }
    return featureStore;
}
 
Example #4
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsGridsGenerator.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void createPolygons( CoordinateReferenceSystem crs, GeometryFactory gf, List<Geometry> polygons ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POLYGON);
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    long index = 0;
    int numGeometries = polygons.size();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = polygons.get(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example #5
Source Project: geowave   Author: locationtech   File: FeatureDataUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String getGeomField(final DataStorePluginOptions dataStore, final String typeName) {
  final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
  final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();

  final DataTypeAdapter<?> adapter =
      adapterStore.getAdapter(internalAdapterStore.getAdapterId(typeName)).getAdapter();

  if ((adapter != null) && (adapter instanceof GeotoolsFeatureDataAdapter)) {
    final GeotoolsFeatureDataAdapter gtAdapter = (GeotoolsFeatureDataAdapter) adapter;
    final SimpleFeatureType featureType = gtAdapter.getFeatureType();

    if (featureType.getGeometryDescriptor() != null) {
      return featureType.getGeometryDescriptor().getLocalName();
    }
  }

  return null;
}
 
Example #6
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsLasConverter.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source Project: snap-desktop   Author: senbox-org   File: ExportGeometryActionTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testWritingShapeFile_Geometry() throws Exception {
    SimpleFeatureType sft = createPlainFeatureType("Polygon", Geometry.class, DefaultGeographicCRS.WGS84);

    GeometryFactory gf = new GeometryFactory();
    Polygon polygon = gf.createPolygon(gf.createLinearRing(new Coordinate[]{
            new Coordinate(0, 0),
            new Coordinate(1, 0),
            new Coordinate(0, 1),
            new Coordinate(0, 0),
    }), null);
    SimpleFeature polygonFeature = createPlainFeature(sft, "_1", polygon, "");


    ArrayList<SimpleFeature> features = new ArrayList<>();
    features.add(polygonFeature);
    Class<Polygon> geomType = Polygon.class;
    doExportImport(features, geomType);
}
 
Example #8
Source Project: geowave   Author: locationtech   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 #9
Source Project: snap-desktop   Author: senbox-org   File: SimpleFeatureShapeFigureTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMixedGeometries_2() {

    SimpleFeatureType sft = createPlainFeatureType("Geometry", Geometry.class, DefaultGeographicCRS.WGS84);

    Geometry geometry;
    SimpleFeature feature;
    SimpleFeatureShapeFigure figure;

    geometry = createPoint();
    feature = createPlainFeature(sft, "_4", geometry, "");
    figure = new SimpleFeatureShapeFigure(feature, sceneTransformProvider, new DefaultFigureStyle());
    Assert.assertEquals(geometry, figure.getGeometry());
    Assert.assertNotNull(figure.getShape());
    Assert.assertEquals(Figure.Rank.POINT, figure.getRank());

    geometry = createGeometryCollection();
    feature = createPlainFeature(sft, "_5", geometry, "");
    figure = new SimpleFeatureShapeFigure(feature, sceneTransformProvider, new DefaultFigureStyle());
    Assert.assertEquals(geometry, figure.getGeometry());
    Assert.assertNotNull(figure.getShape());
    Assert.assertEquals(Figure.Rank.NOT_SPECIFIED, figure.getRank());
}
 
Example #10
@Before
public void init() throws Exception {
	ClassLoader classloader = Thread.currentThread().getContextClassLoader();
	URL url = classloader.getResource(SHAPE_FILE);
	DataStore dataStore = new ShapefileDataStore(url);
	featureModel = new GeoToolsFeatureModel(dataStore, LAYER_NAME, 4326, converterService);
	featureModel.setLayerInfo(layerInfo);

	FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureModel.getFeatureSource();
	FeatureIterator<SimpleFeature> fi = fs.getFeatures().features();
	feature = fi.next();
	feature = fi.next();
	feature = fi.next();
	feature = fi.next();
	feature = fi.next();
}
 
Example #11
Source Project: snap-desktop   Author: senbox-org   File: PutStatisticsIntoVectorDataAction.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void exchangeVDN(SimpleFeatureType featureType, FeatureStatisticsWriter featureStatisticsWriter) {
        final VectorDataNode originalVDN = featureType2VDN.get(featureType);
        final VectorDataNode vectorDataNode = createVectorDataNode(featureStatisticsWriter, originalVDN);
        final ProductNodeGroup<VectorDataNode> vectorDataNodeGroup = provider.getVectorDataNodeGroup();
        vectorDataNodeGroup.remove(originalVDN);
        originalVDN.dispose();
        vectorDataNodeGroup.add(vectorDataNode);
        //todo solve this one
//        final JInternalFrame internalFrame = VisatApp.getApp().findInternalFrame(originalVDN);
//        if (internalFrame != null) {
//            try {
//                internalFrame.setClosed(true);
//            } catch (PropertyVetoException ignored) {
//                 ok
//            }
//        }
        final ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView();
        if (sceneView != null) {
            sceneView.setLayersVisible(vectorDataNode);
        }
    }
 
Example #12
Source Project: rya   Author: apache   File: GeoWaveFeatureReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLike() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            ECQL.toFilter("pid like '" + pids.get(
                    0).substring(
                    0,
                    1) + "%'"),
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertEquals(1, count);
}
 
Example #13
@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 #14
Source Project: geowave   Author: locationtech   File: DateFieldRetypingSource.java    License: Apache License 2.0 6 votes vote down vote up
public DateFieldRetypingSource(
    final SimpleFeatureType typeIn,
    final Map<String, String> fieldNameToTimestampFormat) {
  this.typeIn = typeIn;
  this.fieldNameToTimestampFormat = fieldNameToTimestampFormat;

  fieldToFormatObjMap = new ThreadLocal<Map<String, SimpleDateFormat>>() {
    @Override
    protected Map<String, SimpleDateFormat> initialValue() {
      final Map<String, SimpleDateFormat> localFieldToFormat = new HashMap<>();
      for (final Entry<String, String> entry : fieldNameToTimestampFormat.entrySet()) {
        localFieldToFormat.put(entry.getKey(), new SimpleDateFormat(entry.getValue()));
      }
      return localFieldToFormat;
    }
  };
}
 
Example #15
Source Project: rya   Author: apache   File: GeoWaveFeatureReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
    // Filter it so that it only queries for everything but the first pid.
    // There's only 2 pids total so it should just return the second one.
    final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
    final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
    final Query query = new Query(
            "GeoWaveFeatureReaderTest",
            filter,
            new String[] {
                "geometry",
                "pid"
            });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
        dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count == pids.size() - 1);
}
 
Example #16
Source Project: geowave   Author: locationtech   File: QueryOptionsIT.java    License: Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType getSimpleFeatureType(final String typeName) {
  SimpleFeatureType type = null;
  try {
    type =
        DataUtilities.createType(
            typeName,
            CITY_ATTRIBUTE
                + ":String,"
                + STATE_ATTRIBUTE
                + ":String,"
                + POPULATION_ATTRIBUTE
                + ":Double,"
                + LAND_AREA_ATTRIBUTE
                + ":Double,"
                + GEOMETRY_ATTRIBUTE
                + ":Geometry");
  } catch (final SchemaException e) {
    System.out.println("Unable to create SimpleFeatureType");
  }
  return type;
}
 
Example #17
Source Project: rya   Author: apache   File: GeoMesaGeoIndexer.java    License: Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
    SimpleFeatureType featureType;

    final String[] datastoreFeatures = dataStore.getTypeNames();
    if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
        featureType = dataStore.getSchema(FEATURE_NAME);
    } else {
        final String featureSchema = SUBJECT_ATTRIBUTE + ":String," //
                + PREDICATE_ATTRIBUTE + ":String," //
                + OBJECT_ATTRIBUTE + ":String," //
                + CONTEXT_ATTRIBUTE + ":String," //
                + GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326;geomesa.mixed.geometries='true'";
        featureType = SimpleFeatureTypes.createType(FEATURE_NAME, featureSchema);
        dataStore.createSchema(featureType);
    }
    return featureType;
}
 
Example #18
Source Project: geowave   Author: locationtech   File: SimpleFeatureGeoWaveWrapper.java    License: Apache License 2.0 6 votes vote down vote up
public InternalIterator(
    final SimpleFeatureCollection featureCollection,
    final String visibility,
    final Filter filter) {
  this.filter = filter;
  featureIterator = featureCollection.features();
  final SimpleFeatureType originalSchema = featureCollection.getSchema();
  SimpleFeatureType retypedSchema =
      SimpleFeatureUserDataConfigurationSet.configureType(originalSchema);
  if (retypingPlugin != null) {
    source = retypingPlugin.getRetypingSource(originalSchema);
    if (source != null) {
      retypedSchema = source.getRetypedSimpleFeatureType();
      builder = new SimpleFeatureBuilder(retypedSchema);
    }
  }
  if ((visibility == null) || visibility.isEmpty()) {
    dataAdapter = new FeatureDataAdapter(retypedSchema);
  } else {
    dataAdapter =
        new FeatureDataAdapter(
            retypedSchema,
            new GlobalVisibilityHandler<SimpleFeature, Object>(visibility));
  }
}
 
Example #19
Source Project: geowave   Author: locationtech   File: SerializableAdapterStoreTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialization() throws ClassNotFoundException, IOException {
  final SimpleFeatureType ftype =
      AnalyticFeature.createGeometryFeatureAdapter(
          "centroid",
          new String[] {"extra1"},
          BasicFeatureTypes.DEFAULT_NAMESPACE,
          ClusteringUtils.CLUSTERING_CRS).getFeatureType();

  final Index index = new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions());
  final FeatureDataAdapter adapter = new FeatureDataAdapter(ftype);
  adapter.init(index);
  final SerializableAdapterStore store =
      new SerializableAdapterStore(new MemoryAdapterStore(new DataTypeAdapter<?>[] {adapter}));

  final String id = "centroid";
  assertNotNull(checkSerialization(store).getAdapter(id));
}
 
Example #20
Source Project: geomajas-project-server   Author: geomajas   File: GeoToolsLayer.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Envelope getBounds(Filter filter) throws LayerException {
	FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource();
	if (source instanceof FeatureStore<?, ?>) {
		SimpleFeatureStore store = (SimpleFeatureStore) source;
		transactionSynchronization.synchTransaction(store);
	}
	try {
		FeatureCollection<SimpleFeatureType, SimpleFeature> fc;
		if (null == filter) {
			fc = source.getFeatures();
		} else {
			fc = source.getFeatures(filter);
		}
		FeatureIterator<SimpleFeature> it = fc.features();
		transactionSynchronization.addIterator(it);
		return fc.getBounds();
	} catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well
		throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM);
	}
}
 
Example #21
Source Project: geowave   Author: locationtech   File: GpxUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType createGPXRouteDataType() {

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

    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();

    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Name"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("NumberPoints"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("TrackId"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Symbol"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("User"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Description"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Source"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Comment"));

    return simpleFeatureTypeBuilder.buildFeatureType();
  }
 
Example #22
Source Project: geowave   Author: locationtech   File: AbstractSimpleFeatureIngestPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DataTypeAdapter<SimpleFeature>[] getDataAdapters(final String globalVisibility) {
  final FieldVisibilityHandler<SimpleFeature, Object> fieldVisiblityHandler =
      ((globalVisibility != null) && !globalVisibility.isEmpty())
          ? new GlobalVisibilityHandler<>(globalVisibility)
          : null;
  final SimpleFeatureType[] types = getTypes();
  final DataTypeAdapter<SimpleFeature>[] retVal = new DataTypeAdapter[types.length];
  for (int i = 0; i < types.length; i++) {
    retVal[i] = newAdapter(types[i], fieldVisiblityHandler);
  }
  return retVal;
}
 
Example #23
Source Project: TomboloDigitalConnector   Author: FutureCitiesCatapult   File: AbstractGeotoolsDataStoreImporter.java    License: MIT License 5 votes vote down vote up
private void withSubjects(FeatureReader<SimpleFeatureType, SimpleFeature> featureReader, DataStore dataStore, BiConsumer<SimpleFeature, Subject> fn) throws IOException, FactoryException, TransformException {
    MathTransform crsTransform = GeotoolsDataStoreUtils.makeCrsTransform(getSourceEncoding());

    while(featureReader.hasNext()) {
        SimpleFeature feature = featureReader.next();
        buildSubjectFromFeature(feature, crsTransform).ifPresent(subject -> {
            fn.accept(feature, subject);
            subjectBuffer.add(subject);
        });
        flushBufferIfRequired();
    }

    flushBuffer();
}
 
Example #24
Source Project: geowave   Author: locationtech   File: GpxUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType createGPXTrackDataType() {

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

    final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder();

    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Name"));
    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"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("UserId"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("User"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Description"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Tags"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Source"));
    simpleFeatureTypeBuilder.add(
        attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Comment"));

    return simpleFeatureTypeBuilder.buildFeatureType();
  }
 
Example #25
Source Project: geowave   Author: locationtech   File: SimpleFeatureUserDataConfigurationSet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates the SFT with the entire list of SimpleFeatureUserDataConfiguration(s)
 *
 * @param type - SF type to be updated
 */
public void updateType(final SimpleFeatureType type) {
  final List<SimpleFeatureUserDataConfiguration> sfudc =
      getConfigurationsForType(type.getTypeName());

  // Go through list of SFUD configurations and update each one in the
  // passed in SF type

  for (final SimpleFeatureUserDataConfiguration configuration : sfudc) {
    configuration.updateType(type);
  }
}
 
Example #26
Source Project: elasticgeo   Author: ngageoint   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;
}
 
Example #27
Source Project: geowave   Author: locationtech   File: GeoWaveAvroFeatureWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts a SimpleFeature to an avroSimpleFeature and then serializes it.
 *
 * @param sf Simple Feature to be serialized
 * @param avroObjectToReuse null or AvroSimpleFeature instance to be re-used. If null a new
 *        instance will be allocated
 * @param defaultClassifications null map of attribute names vs. classification. if null all
 *        values will be set to the default classification
 * @param defaultClassification null or default classification. if null and defaultClassifications
 *        are not provided an exception will be thrown
 * @return the serialized feature
 * @throws IOException
 */
public byte[] serializeAvroSimpleFeature(
    final SimpleFeature sf,
    AvroSimpleFeature avroObjectToReuse,
    final Map<String, String> defaultClassifications,
    final String defaultClassification) throws IOException {
  if (sf == null) {
    throw new IOException("Feature cannot be null");
  }

  if ((defaultClassification == null) && (defaultClassifications == null)) {
    throw new IOException(
        "if per attribute classifications aren't provided then a default classification must be provided");
  }

  final SimpleFeatureType sft = sf.getType();
  if (avroObjectToReuse == null) {
    avroObjectToReuse = new AvroSimpleFeature();
  }

  final AvroFeatureDefinition fd =
      GeoWaveAvroFeatureUtils.buildFeatureDefinition(
          avroObjectToReuse.getFeatureType(),
          sft,
          defaultClassifications,
          defaultClassification);
  avroObjectToReuse.setFeatureType(fd);

  final AvroAttributeValues av = GeoWaveAvroFeatureUtils.buildAttributeValue(sf, sft);
  avroObjectToReuse.setValue(av);

  return serializeAvroSimpleFeature(avroObjectToReuse);
}
 
Example #28
Source Project: hortonmachine   Author: TheHortonMachine   File: FeatureUtilities.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #29
Source Project: geowave   Author: locationtech   File: FeatureDataUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SimpleFeatureType decodeType(
    final String nameSpace,
    final String typeName,
    final String typeDescriptor,
    final String axis) throws SchemaException {

  SimpleFeatureType featureType =
      (nameSpace != null) && (nameSpace.length() > 0)
          ? DataUtilities.createType(nameSpace, typeName, typeDescriptor)
          : DataUtilities.createType(typeName, typeDescriptor);

  final String lCaseAxis = axis.toLowerCase(Locale.ENGLISH);
  final CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
  final String typeAxis = getAxis(crs);
  // Default for EPSG:4326 is lat/long, If the provided type was
  // long/lat, then re-establish the order
  if ((crs != null)
      && crs.getIdentifiers().toString().contains("EPSG:4326")
      && !lCaseAxis.equalsIgnoreCase(typeAxis)) {
    final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.init(featureType);

    try {
      // truely no way to force lat first
      // but it is the default in later versions of GeoTools.
      // this all depends on the authority at the time of creation
      featureType =
          SimpleFeatureTypeBuilder.retype(
              featureType,
              CRS.decode("EPSG:4326", lCaseAxis.equals("east")));
    } catch (final FactoryException e) {
      throw new SchemaException("Cannot decode EPSG:4326", e);
    }
  }
  return featureType;
}
 
Example #30
Source Project: geowave   Author: locationtech   File: FeatureDataAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SimpleFeatureType getFeatureType() {
  if (reprojectedFeatureType == null) {
    return persistedFeatureType;
  }
  return reprojectedFeatureType;
}