org.opengis.feature.type.Name Java Examples

The following examples show how to use org.opengis.feature.type.Name. 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: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOnlySourceFieldsWithSourceFiltering() throws Exception {
    init();
    dataStore.setSourceFilteringEnabled(true);
    Name name = new NameImpl("active");
    for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){
        if (attribute.isStored()) {
            attribute.setUse(false);
        }
    }
    featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME);

    assertEquals(11, featureSource.getCount(Query.ALL));

    SimpleFeatureIterator features = featureSource.getFeatures().features();
    for (int i=0; i<11; i++) {
        assertTrue(features.hasNext());
        features.next();
    }
}
 
Example #2
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOnlyStoredFieldsWithSourceFiltering() throws Exception {
    init();
    dataStore.setSourceFilteringEnabled(true);
    Name name = new NameImpl("active");
    for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){
        if (!attribute.isStored()) {
            attribute.setUse(false);
        }
    }
    assertEquals(11, featureSource.getCount(Query.ALL));
    SimpleFeatureIterator features = featureSource.getFeatures().features();
    for (int i=0; i<11; i++) {
        assertTrue(features.hasNext());
        features.next();
    }
}
 
Example #3
Source File: DatabaseClient.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Connect to datastore.
 *
 * @param dataStore the data store
 */
private void connectToDatastore(DataStore dataStore) {
    try {
        List<Name> nameList = dataStore.getNames();

        if (nameList != null) {
            for (Name name : nameList) {
                if (hasGeometryField(dataStore, name)) {
                    featureClassList.add(name.getLocalPart());
                }
            }
        }

        dataStore.dispose();
        connected = true;
    } catch (Exception e) {
        ConsoleManager.getInstance().exception(this, e);
    }
}
 
Example #4
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOnlySourceFields() throws Exception {
    init();
    Name name = new NameImpl("active");
    for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){
        if (attribute.isStored()) {
            attribute.setUse(false);
        }
    }
    featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME);

    assertEquals(11, featureSource.getCount(Query.ALL));

    SimpleFeatureIterator features = featureSource.getFeatures().features();
    for (int i=0; i<11; i++) {
        assertTrue(features.hasNext());
        features.next();
    }
}
 
Example #5
Source File: ElasticFeatureFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOnlyStoredFields() throws Exception {
    init();
    Name name = new NameImpl("active");
    for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){
        if (!attribute.isStored()) {
            attribute.setUse(false);
        }
    }
    assertEquals(11, featureSource.getCount(Query.ALL));
    SimpleFeatureIterator features = featureSource.getFeatures().features();
    for (int i=0; i<11; i++) {
        assertTrue(features.hasNext());
        features.next();
    }
}
 
Example #6
Source File: ElasticConfigurationPage.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private ElasticLayerConfiguration fillElasticAttributes(ResourceInfo ri) {

        ElasticLayerConfiguration layerConfig = (ElasticLayerConfiguration) ri.getMetadata()
                .get(ElasticLayerConfiguration.KEY);

        if (layerConfig == null) {
            layerConfig = new ElasticLayerConfiguration(ri.getName());
            ri.getMetadata().put(ElasticLayerConfiguration.KEY, layerConfig);
        }

        try {
            ElasticDataStore dataStore = (ElasticDataStore) ((DataStoreInfo) ri.getStore())
                    .getDataStore(new NullProgressListener());

            ArrayList<ElasticAttribute> result = new ArrayList<>();
            Map<String, ElasticAttribute> tempMap = new HashMap<>();
            final List<ElasticAttribute> attributes = layerConfig.getAttributes();
            for (ElasticAttribute att : attributes) {
                tempMap.put(att.getName(), att);
            }

            final String docType = layerConfig.getDocType();
            final Name layerName = new NameImpl(layerConfig.getLayerName());
            dataStore.getDocTypes().put(layerName, docType);
            for (ElasticAttribute at : dataStore.getElasticAttributes(layerName)) {
                if (tempMap.containsKey(at.getName())) {
                    at = tempMap.get(at.getName());
                }
                result.add(at);
            }
            layerConfig.getAttributes().clear();
            layerConfig.getAttributes().addAll(result);
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
        Collections.sort(layerConfig.getAttributes());
        return layerConfig;
    }
 
Example #7
Source File: DateFieldRetypingSource.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object retypeAttributeValue(final Object value, final Name attributeName) {
  Object outValue = value;
  final String localName = attributeName.getLocalPart();
  final SimpleDateFormat formatForName = fieldToFormatObjMap.get().get(localName);
  if ((value != null) && (formatForName != null)) {
    try {
      outValue = formatForName.parse(value.toString());
    } catch (final ParseException e) {
      LOGGER.error("Failed to parse: " + localName + ": " + value.toString());
    }
  }
  return outValue;
}
 
Example #8
Source File: ElasticDataStore.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
public String getDocType(Name typeName) {
    final String docType;
    if (docTypes.containsKey(typeName)) {
        docType = docTypes.get(typeName);
    } else {
        docType = typeName.getLocalPart();
    }
    return docType;
}
 
Example #9
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 #10
Source File: ElasticDataStore.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ContentFeatureSource getFeatureSource(Name name, Transaction tx)
        throws IOException {

    final ElasticLayerConfiguration layerConfig = layerConfigurations.get(name.getLocalPart());
    if (layerConfig != null) {
        docTypes.put(name, layerConfig.getDocType());
    }
    final ContentFeatureSource featureSource = super.getFeatureSource(name, tx);
    featureSource.getEntry().getState(Transaction.AUTO_COMMIT).flush();

    return featureSource;
}
 
Example #11
Source File: ElasticDataStore.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected List<Name> createTypeNames() {
    final List<Name> names = new ArrayList<>();
    names.addAll(baseTypeNames);
    names.addAll(docTypes.keySet());
    return names;
}
 
Example #12
Source File: GeoWaveGTDataStore.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Name> createTypeNames() throws IOException {
  final List<Name> names = new ArrayList<>();
  try (final CloseableIterator<InternalDataAdapter<?>> adapters = adapterStore.getAdapters()) {
    while (adapters.hasNext()) {
      final InternalDataAdapter<?> adapter = adapters.next();
      if (adapter.getAdapter() instanceof GeotoolsFeatureDataAdapter) {
        names.add(((GeotoolsFeatureDataAdapter) adapter.getAdapter()).getFeatureType().getName());
      }
    }
  }
  return names;
}
 
Example #13
Source File: ElasticFeatureTypeCallback.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dispose(FeatureTypeInfo info,
        DataAccess<? extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) {
    final ElasticLayerConfiguration layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY);
    if (layerConfig != null) {
        layerConfig.getAttributes().stream()
                .filter(attr -> attr.getName().equals(info.getName()))
                .findFirst()
                .ifPresent(attribute -> layerConfig.getAttributes().remove(attribute));
        ((ElasticDataStore) dataAccess).getDocTypes().remove(info.getQualifiedName());
    }
}
 
Example #14
Source File: ElasticFeatureTypeCallback.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean initialize(FeatureTypeInfo info,
        DataAccess<? extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) {

    ElasticLayerConfiguration layerConfig;
    layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY);
    if (layerConfig == null) {
        layerConfig = new ElasticLayerConfiguration(info.getName());
    }

    ((ElasticDataStore) dataAccess).setLayerConfiguration(layerConfig);

    return false;
}
 
Example #15
Source File: SelectedProcessFunction.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the function name.
 *
 * @return the function name
 */
public Name getFunctionName() {
    if (builtInSelected) {
        if (builtInProcessFunction == null) {
            return null;
        }
        return builtInProcessFunction.getFunctionName();
    } else {
        if (selectedCustomFunction == null) {
            return null;
        }
        return new NameImpl(selectedCustomFunction.getTitle().getValue());
    }
}
 
Example #16
Source File: InlineFeatureUtils.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determine geometry type.
 *
 * @param geometryDescriptor the geometry descriptor
 * @param simpleFeatureCollection the simple feature collection
 * @return the geometry type enum
 */
public static GeometryTypeEnum determineGeometryType(
        GeometryDescriptor geometryDescriptor,
        SimpleFeatureCollection simpleFeatureCollection) {

    if (geometryDescriptor == null) {
        return GeometryTypeEnum.UNKNOWN;
    }

    if (simpleFeatureCollection == null) {
        return GeometryTypeEnum.UNKNOWN;
    }

    Class<?> bindingType = geometryDescriptor.getType().getBinding();

    if (bindingType == Geometry.class) {
        Name geometryName = geometryDescriptor.getName();
        SimpleFeatureIterator iterator = simpleFeatureCollection.features();

        List<GeometryTypeEnum> geometryFeatures = new ArrayList<>();

        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();

            Object value = feature.getAttribute(geometryName);

            if (value != null) {
                GeometryTypeEnum geometryType =
                        GeometryTypeMapping.getGeometryType(value.getClass());

                if (!geometryFeatures.contains(geometryType)) {
                    geometryFeatures.add(geometryType);
                }
            }
        }
        return (combineGeometryType(geometryFeatures));
    } else {
        return GeometryTypeMapping.getGeometryType(bindingType);
    }
}
 
Example #17
Source File: DataSourceImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Read attributes.
 *
 * @param attributeData the attribute data
 */
/*
 * (non-Javadoc)
 *
 * @see
 * com.sldeditor.datasource.DataSourceInterface#updateAttributes(com.sldeditor.render.iface.
 * RenderAttributeDataInterface)
 */
@Override
public void readAttributes(DataSourceAttributeListInterface attributeData) {
    if (attributeData == null) {
        return;
    }

    List<DataSourceAttributeData> valueMap = new ArrayList<>();

    SimpleFeatureCollection featureCollection = dataSourceInfo.getFeatureCollection();
    if (featureCollection != null) {
        SimpleFeatureIterator iterator = featureCollection.features();

        Map<Integer, Name> fieldNameMap = dataSourceInfo.getFieldNameMap();
        Map<Integer, Class<?>> fieldTypeMap = dataSourceInfo.getFieldTypeMap();

        if (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();

            extractAttributes(valueMap, fieldNameMap, fieldTypeMap, feature);
        }

        iterator.close();
    }

    attributeData.setData(valueMap);
}
 
Example #18
Source File: DistributedRenderProcessUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Expression getRenderingProcess() {
  if (SINGLETON_RENDER_PROCESS == null) {
    final ProcessFactory processFactory =
        new AnnotatedBeanProcessFactory(
            Text.text("Internal GeoWave Process Factory"),
            "internal",
            InternalDistributedRenderProcess.class);
    final Name processName = new NameImpl("internal", "InternalDistributedRender");
    final RenderingProcess process = (RenderingProcess) processFactory.create(processName);
    final Map<String, Parameter<?>> parameters = processFactory.getParameterInfo(processName);
    final InternalProcessFactory factory = new InternalProcessFactory();
    // this is kinda a hack, but the only way to instantiate a process
    // is
    // for it to have a registered process factory, so temporarily
    // register
    // the process factory
    Processors.addProcessFactory(factory);

    SINGLETON_RENDER_PROCESS =
        new RenderingProcessFunction(
            processName,
            Collections.singletonList(
                new ParameterFunction(
                    null,
                    Collections.singletonList(new LiteralExpressionImpl("data")))),
            parameters,
            process,
            null);
    Processors.removeProcessFactory(factory);
  }
  return SINGLETON_RENDER_PROCESS;
}
 
Example #19
Source File: DatabaseClient.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks for the presence of a geometry field.
 *
 * @param dataStore the data store
 * @param name the name
 * @return true, if geometry field present
 */
private boolean hasGeometryField(DataStore dataStore, Name name) {
    try {
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(name);
        GeometryDescriptor geometryDescriptor =
                featureSource.getSchema().getGeometryDescriptor();

        return (geometryDescriptor != null);

    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return false;
}
 
Example #20
Source File: DataSourceImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Read attributes.
 *
 * @param attributeData the attribute data
 */
/* (non-Javadoc)
 * @see com.sldeditor.datasource.DataSourceInterface#updateAttributes(com.sldeditor.render.iface.RenderAttributeDataInterface)
 */
@Override
public void readAttributes(DataSourceAttributeListInterface attributeData) {
    if(attributeData == null)
    {
        return;
    }

    List<DataSourceAttributeData> valueMap = new ArrayList<DataSourceAttributeData>();

    SimpleFeatureCollection featureCollection = dataSourceInfo.getFeatureCollection();
    if(featureCollection != null)
    {
        SimpleFeatureIterator iterator = featureCollection.features();
        if(iterator.hasNext())
        {
            SimpleFeature feature = iterator.next();

            List<Object> attributes = feature.getAttributes();
            for (int i = 0; i < attributes.size(); i++)
            {
                Name fieldName = fieldNameMap.get(i);

                DataSourceAttributeData data = new DataSourceAttributeData(fieldName,
                        fieldTypeMap.get(i),
                        attributes.get(i));

                valueMap.add(data);
            }
        }
    }

    attributeData.setData(valueMap);
}
 
Example #21
Source File: GeoToolsLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Update an existing feature. Made package private for testing purposes.
 *
 * @param feature feature to update
 * @throws LayerException oops
 */
void update(Object feature) throws LayerException {
	SimpleFeatureSource source = getFeatureSource();
	if (source instanceof SimpleFeatureStore) {
		SimpleFeatureStore store = (SimpleFeatureStore) source;
		String featureId = getFeatureModel().getId(feature);
		Filter filter = filterService.createFidFilter(new String[] { featureId });
		transactionSynchronization.synchTransaction(store);
		List<Name> names = new ArrayList<Name>();
		Map<String, Attribute> attrMap = getFeatureModel().getAttributes(feature);
		List<Object> values = new ArrayList<Object>();
		for (Map.Entry<String, Attribute> entry : attrMap.entrySet()) {
			String name = entry.getKey();
			names.add(store.getSchema().getDescriptor(name).getName());
			values.add(entry.getValue().getValue());
		}

		try {
			store.modifyFeatures(names.toArray(new Name[names.size()]), values.toArray(), filter);
			store.modifyFeatures(store.getSchema().getGeometryDescriptor().getName(), getFeatureModel()
					.getGeometry(feature), filter);
			log.debug("Updated feature {} in {}", featureId, getFeatureSourceName());
		} catch (IOException ioe) {
			featureModelUsable = false;
			throw new LayerException(ioe, ExceptionCode.LAYER_MODEL_IO_EXCEPTION);
		}
	} else {
		log.error("Don't know how to create or update " + getFeatureSourceName() + ", class "
				+ source.getClass().getName() + " does not implement SimpleFeatureStore");
		throw new LayerException(ExceptionCode.CREATE_OR_UPDATE_NOT_IMPLEMENTED, getFeatureSourceName(), source
				.getClass().getName());
	}
}
 
Example #22
Source File: GeoWaveGTDataStore.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public void removeSchema(final Name typeName) throws IOException {
  this.removeSchema(typeName.getLocalPart());
}
 
Example #23
Source File: SimpleFeatureWrapper.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Property> getProperties(final Name name) {
  return simpleFeature.getProperties(name);
}
 
Example #24
Source File: NonLenientFilterFactoryImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public PropertyName property(Name name) {
	AttributeExpressionImpl expression = (AttributeExpressionImpl) super.property(name);
	expression.setLenient(false);
	return expression;
}
 
Example #25
Source File: SimpleFeatureWrapper.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Name getName() {
  return simpleFeature.getName();
}
 
Example #26
Source File: SimpleFeatureWrapper.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Property getProperty(final Name name) {
  return simpleFeature.getProperty(name);
}
 
Example #27
Source File: SimpleFeatureWrapper.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Object getAttribute(final Name name) {
  return simpleFeature.getAttribute(name);
}
 
Example #28
Source File: SimpleFeatureWrapper.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public void setAttribute(final Name name, final Object value) {
  simpleFeature.setAttribute(name, value);
}
 
Example #29
Source File: DummyJdbcFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
protected List<Name> createTypeNames() throws IOException {
	return null;
}
 
Example #30
Source File: GeoWaveGTDataStore.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public ContentFeatureSource getFeatureSource(final Name typeName) throws IOException {
  return getFeatureSource(typeName.getLocalPart(), Transaction.AUTO_COMMIT);
}