org.opengis.feature.type.GeometryType Java Examples

The following examples show how to use org.opengis.feature.type.GeometryType. 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: GamaGisGeometry.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public GamaGisGeometry(final Geometry g, final Feature feature) {
	super(g);
	if (feature != null) {
		// We filter out the geometries (already loaded before)
		for (final Property p : feature.getProperties()) {
			if (!(p.getType() instanceof GeometryType)) {
				final String type = p.getDescriptor().getType().getBinding().getSimpleName();
				if ("String".equals(type)) {
					String val = (String) p.getValue();
					if (val != null && ((val.startsWith("'") && val.endsWith("'")) || (val.startsWith("\"") && val.endsWith("\""))))
						val = val.substring(1, val.length() - 1);
					setAttribute(p.getName().getLocalPart(), val);

				} else
					setAttribute(p.getName().getLocalPart(), p.getValue());
			}
		}
	}
}
 
Example #2
Source File: GamaGeoJsonFile.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IList<String> getAttributes(final IScope scope) {
	final Map<String, String> attributes = new LinkedHashMap<>();
	final SimpleFeatureCollection store = getFeatureCollection(scope);
	final java.util.List<AttributeDescriptor> att_list = store.getSchema().getAttributeDescriptors();
	for (final AttributeDescriptor desc : att_list) {
		String type;
		if (desc.getType() instanceof GeometryType) {
			type = "geometry";
		} else {
			type = Types.get(desc.getType().getBinding()).toString();
		}
		attributes.put(desc.getName().getLocalPart(), type);
	}

	return GamaListFactory.wrap(Types.STRING, attributes.keySet());
}
 
Example #3
Source File: CentroidManagerGeoWave.java    From geowave with 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 #4
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #5
Source File: DataSourceInfo.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();

                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type =
                        featureTypeFactory.createGeometryType(
                                new NameImpl(RASTER_GEOMETRY_FIELD),
                                GridCoverage2D.class,
                                crs,
                                isIdentifiable,
                                isAbstract,
                                restrictions,
                                superType,
                                description);
                GeometryDescriptor descriptor =
                        featureTypeFactory.createGeometryDescriptor(
                                type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);

                rasterPropertyDescriptorList.add(descriptor);
            }

            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
 
Example #6
Source File: GeometryDataSetGenerator.java    From geowave with Apache License 2.0 5 votes vote down vote up
private SimpleFeature createFeatureWithGeometry(final Geometry geometry) {
  final Object[] values = new Object[builder.getFeatureType().getAttributeCount()];
  for (int i = 0; i < values.length; i++) {
    final AttributeDescriptor desc = builder.getFeatureType().getDescriptor(i);
    if (desc.getType() instanceof GeometryType) {
      values[i] = geometry;
    } else {
      final Class<?> binding = desc.getType().getBinding();
      if (String.class.isAssignableFrom(binding)) {
        values[i] = UUID.randomUUID().toString();
      }
    }
  }
  return builder.buildFeature(UUID.randomUUID().toString(), values);
}
 
Example #7
Source File: CreateExternalDataSource.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Determine geometry type.
 *
 * @param type the type
 */
private void determineGeometryType(GeometryType type) {
    Class<?> bindingType = type.getBinding();

    dsInfo.setGeometryType(GeometryTypeMapping.getGeometryType(bindingType));
}
 
Example #8
Source File: OmsVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * You cannot call this once the dialog is closed, see the okPressed method.
 * @param originalFeatureType 
 * @param expressions 
 * @param names 
 * @return a SimpleFeatureType created based on the contents of Text
 */
private SimpleFeatureType createFeatureType( String expressionString, SimpleFeatureType originalFeatureType,
        List<String> names, List<Expression> expressions ) throws SchemaException {

    SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();

    for( int i = 0; i < names.size(); i++ ) {
        String name = names.get(i);

        Expression expression = expressions.get(i);

        Object value = expression.evaluate(sample);

        // hack because sometimes expression returns null. I think the real bug is with
        // AttributeExpression
        Class< ? > binding = null;
        if (value == null) {
            if (expression instanceof PropertyName) {
                String path = ((PropertyName) expression).getPropertyName();
                AttributeType attributeType = sample.getFeatureType().getType(path);
                if (attributeType == null) {
                    throw new ModelsIllegalargumentException("Attribute type is null", this.getClass().getSimpleName(), pm);
                }
                binding = attributeType.getClass();
            }
        } else {
            binding = value.getClass();
        }

        if (binding == null) {
            throw new ModelsIllegalargumentException("Binding is null", this.getClass().getSimpleName(), pm);
        }

        if (Geometry.class.isAssignableFrom(binding)) {
            CoordinateReferenceSystem crs;
            AttributeType originalAttributeType = originalFeatureType.getType(name);
            if (originalAttributeType instanceof GeometryType) {
                crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
            } else {
                crs = originalFeatureType.getCoordinateReferenceSystem();
            }
            build.crs(crs);

            build.add(name, binding);
        } else {
            build.add(name, binding);
        }
    }
    build.setName(getNewTypeName(originalFeatureType.getTypeName()));

    return build.buildFeatureType();
}