Package org.geotools.feature

Examples of org.geotools.feature.AttributeTypeBuilder


public class OgcGenericFilters
{
    private static SimpleFeatureType reprojectGeometryType(Name geometryAttName) {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        AttributeTypeBuilder attBuilder  = new AttributeTypeBuilder();
        attBuilder.crs(DefaultGeographicCRS.WGS84);
        attBuilder.binding(MultiPolygon.class);
        GeometryDescriptor geomDescriptor = attBuilder.buildDescriptor(geometryAttName, attBuilder.buildGeometryType());
        builder.setName("dummy");
        builder.setCRS( DefaultGeographicCRS.WGS84 );
        builder.add(geomDescriptor);
        return builder.buildFeatureType();
    }
View Full Code Here


            ids.forceSchemaCRS(crs);
        }

        if (!file.exists()) {
            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
            AttributeDescriptor geomDescriptor = new AttributeTypeBuilder().crs(DefaultGeographicCRS.WGS84).binding(MultiPolygon.class).buildDescriptor("the_geom");
            builder.setName(SpatialIndexWriter._SPATIAL_INDEX_TYPENAME);
            builder.add(geomDescriptor);
            builder.add(SpatialIndexWriter._IDS_ATTRIBUTE_NAME, String.class);
            ids.createSchema(builder.buildFeatureType());
        }
View Full Code Here

        try {
            _applicationContext.getBean(initializedString);
        } catch (NoSuchBeanDefinitionException e) {
            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
            AttributeDescriptor geomDescriptor = new AttributeTypeBuilder().crs(DefaultGeographicCRS.WGS84).binding(MultiPolygon.class)
                    .buildDescriptor("the_geom");
            builder.setName("spatialIndex");
            builder.add(geomDescriptor);
            builder.add(SpatialIndexWriter._IDS_ATTRIBUTE_NAME, String.class);
            _datastore.createSchema(builder.buildFeatureType());
View Full Code Here

        try {
            type = Type.valueOf(typeName);
        } catch (IllegalArgumentException e) {
            throw ScriptRuntime.constructError("Error", "Unsupported field type: " + typeName);
        }
        AttributeTypeBuilder builder = new AttributeTypeBuilder();
        builder.setName(name);
        builder.setBinding(type.getBinding());

        Object descObj = getOptionalMember(config, "description", String.class);
        if (descObj != null) {
            builder.setDescription((String) descObj);
        }

        CoordinateReferenceSystem crs = null;
        if (config.has("projection", config)) {
            Object projObj = config.get("projection", config);
            if (projObj instanceof Projection) {
                crs = ((Projection) projObj).unwrap();
            } else if (projObj instanceof String) {
                crs = new Projection(getParentScope(), (String) projObj).unwrap();
            } else if (projObj != null){
                throw ScriptRuntime.constructError("Error", "Invalid projection object.");
            }
        }
        if (crs != null) {
            builder.setCRS(crs);
        }

        Object minOccursObj = getOptionalMember(config, "minOccurs", Number.class);
        int minOccurs = -1;
        if (minOccursObj != null) {
            minOccurs = ((Number) minOccursObj).intValue();
            if (minOccurs < -1) {
                throw ScriptRuntime.constructError("Error", "Invalid minOccurs value: " + Context.toString(minOccursObj));
            }
            builder.setMinOccurs(minOccurs);
        }

        Object maxOccursObj = getOptionalMember(config, "maxOccurs", Number.class);
        int maxOccurs = -1;
        if (maxOccursObj instanceof Number) {
            maxOccurs = ((Number) maxOccursObj).intValue();
            if (maxOccurs < minOccurs || maxOccurs == 0) {
                throw ScriptRuntime.constructError("Error", "Invalid maxOccurs value: " + Context.toString(maxOccursObj));
            }
            builder.setMaxOccurs(maxOccurs);
        } else if (minOccurs > -1) {
            maxOccurs = minOccurs == 0 ? 1 : minOccurs;
            builder.setMaxOccurs(maxOccurs);
        }

        Object isNillableObj = getOptionalMember(config, "isNillable", Boolean.class);
        if (isNillableObj != null) {
            builder.setNillable((Boolean) isNillableObj);
        }

        if (config.has("defaultValue", config)) {
            Object defaultValue = config.get("defaultValue", config);
            if (defaultValue != null) {
                builder.setDefaultValue(jsToJava(defaultValue));
            }
        }

        descriptor = builder.buildDescriptor(name);
    }
View Full Code Here

            final int rowIdType = colDef.getRowIdType();
            if (rowIdType == SeRegistration.SE_REGISTRATION_ROW_ID_COLUMN_TYPE_SDE) {
                continue; // skip over things we cannot edit modify or otherwise treat as
                // attributes
            }
            AttributeTypeBuilder b = new AttributeTypeBuilder();
            // call setDefaultValue before setBinding
            b.setDefaultValue(defValue);
            b.setBinding(typeClass);
            b.setName(attName);
            b.setNillable(isNilable);
            if (fieldLen > 0) {
                b.setLength(fieldLen);
            }
            // only set CRS if its a geometry type, otherwise
            // AttributeTypeBuilder
            // creates a GeometryAttributeType disregarding the class binding
            if (Geometry.class.isAssignableFrom(typeClass)) {
                b.setCRS(metadata);
            }

            AttributeDescriptor buildDescriptor = b.buildDescriptor(attName);
            attDescriptors.add(buildDescriptor);
        }

        return attDescriptors;
    }
View Full Code Here

   
    protected SimpleFeatureType getFeatureType(SimpleFeatureType origType, JoiningQuery query) throws IOException {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.init(origType);
       
        AttributeTypeBuilder ab = new AttributeTypeBuilder();
        if (query.getQueryJoins() != null) {
            for (int i = 0; i < query.getQueryJoins().size(); i++) {
                if (query.getQueryJoins().get(i).getIds().isEmpty()) {
                    // GEOT-4554: handle PK as default idExpression
                    PrimaryKey joinKey = null;
                    String joinTypeName = query.getQueryJoins().get(i).getJoiningTypeName();
                    SimpleFeatureType joinFeatureType = getDataStore().getSchema(joinTypeName);

                    try {
                        joinKey = getDataStore().getPrimaryKey(joinFeatureType);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    int j = 0;
                    for (PrimaryKeyColumn col : joinKey.getColumns()) {
                        query.getQueryJoins().get(i).addId(col.getName());
                        ab.setBinding(String.class);
                        builder.add(ab.buildDescriptor(new NameImpl(FOREIGN_ID) + "_" + i + "_" + j,
                                ab.buildType()));
                        j++;
                    }
                } else {
                    for (int j = 0; j < query.getQueryJoins().get(i).getIds().size(); j++) {
                        ab.setBinding(String.class);
                        builder.add(ab.buildDescriptor(new NameImpl(FOREIGN_ID) + "_" + i + "_" + 0,
                                ab.buildType()));
                    }
                }
            }
        }
        if (!query.hasIdColumn()) {
            // add primary key for the case where idExpression is not specified
            PrimaryKey key = null;

            try {
                key = getDataStore().getPrimaryKey(origType);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            for (int j = 0; j < key.getColumns().size(); j++) {
                ab.setBinding(String.class);
                builder.add(ab.buildDescriptor(PRIMARY_KEY + "_" + j,
                        ab.buildType()));
            }
        }
       
        return builder.buildFeatureType();
    }
View Full Code Here

        PrjFileReader prj = null;
        ShapefileReader shp = null;
        DbaseFileReader dbf = null;
        CoordinateReferenceSystem crs = null;

        AttributeTypeBuilder build = new AttributeTypeBuilder();
        List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
        try {
            shp = shpManager.openShapeReader(new GeometryFactory(), false);
            dbf = shpManager.openDbfReader(false);
            try {
                prj = shpManager.openPrjReader();

                if (prj != null) {
                    crs = prj.getCoordinateReferenceSystem();
                }
            } catch (FactoryException fe) {
                crs = null;
            }
           
            Class<?> geometryClass = JTSUtilities.findBestGeometryClass(shp.getHeader()
                    .getShapeType());
            build.setName(Classes.getShortName(geometryClass));
            build.setNillable(true);
            build.setCRS(crs);
            build.setBinding(geometryClass);

            GeometryType geometryType = build.buildGeometryType();
            attributes.add(build.buildDescriptor(BasicFeatureTypes.GEOMETRY_ATTRIBUTE_NAME,
                    geometryType));
            Set<String> usedNames = new HashSet<String>(); // record names in
            // case of
            // duplicates
            usedNames.add(BasicFeatureTypes.GEOMETRY_ATTRIBUTE_NAME);

            // take care of the case where no dbf and query wants all =>
            // geometry only
            if (dbf != null) {
                DbaseFileHeader header = dbf.getHeader();
                for (int i = 0, ii = header.getNumFields(); i < ii; i++) {
                    Class attributeClass = header.getFieldClass(i);
                    String name = header.getFieldName(i);
                    if (usedNames.contains(name)) {
                        String origional = name;
                        int count = 1;
                        name = name + count;
                        while (usedNames.contains(name)) {
                            count++;
                            name = origional + count;
                        }
                        build.addUserData(ShapefileDataStore.ORIGINAL_FIELD_NAME, origional);
                        build.addUserData(ShapefileDataStore.ORIGINAL_FIELD_DUPLICITY_COUNT, count);
                    }
                    usedNames.add(name);
                    int length = header.getFieldLength(i);

                    build.setNillable(true);
                    build.setLength(length);
                    build.setBinding(attributeClass);
                    attributes.add(build.buildDescriptor(name));
                }
            }
            return attributes;
        } finally {
View Full Code Here

        keywords = new HashSet<String>();
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName( layerName );
        builder.setNamespaceURI( config.getNamespace() );
        // Always add _id...
        AttributeTypeBuilder b = new AttributeTypeBuilder();
        b.setBinding( String.class );
        b.setName( "_id" );
        b.setNillable( false );
        b.setDefaultValue( null );
        b.setLength( 1024 );
        AttributeDescriptor a = b.buildDescriptor( "_id" );
        builder.add( a );

        // We could get this out of the table, exercise for the reader... TODO
        try
        {
            crs = CRS.decode( "EPSG:4326" );
        }
        catch (Throwable t)
        {
            crs = DefaultGeographicCRS.WGS84;
        }

        b = new AttributeTypeBuilder();
        b.setName( "geometry" );
        b.setNillable( false );
        b.setDefaultValue( null );
        b.setCRS( crs );
        // determine metadata for this collection
        metaData = getCollectionModel( coll, buildRule );
        // determine geometry type
        setGeometryType( metaData );

        switch (geometryType)
        {
        case GeometryCollection:
            b.setBinding( GeometryCollection.class );
            break;
        case LineString:
            b.setBinding( LineString.class );
            break;
        case Point:
            b.setBinding( Point.class );
            break;
        case Polygon:
            b.setBinding( Polygon.class );
            break;
        case MultiLineString:
            b.setBinding( MultiLineString.class );
            break;
        case MultiPoint:
            b.setBinding( MultiPoint.class );
            break;
        case MultiPolygon:
            b.setBinding( MultiPolygon.class );
            break;
        case Unknown:
            log.warning( "Unknown geometry for layer " + layerName
                    + " (but has valid distinct geometry.type)" );
            return;
        }

        a = b.buildDescriptor( "geometry" );
        builder.add( a );

        // Add the 2 known keywords...
        keywords.add( "_id" );
        keywords.add( "geometry" );
View Full Code Here

            keywords.add( propName );
            // cannot bind to nulls; only handle non-nulls
            if (dbcol != null)
            {
                // handle as native types
                AttributeTypeBuilder b = new AttributeTypeBuilder();
                b.setName( propName );
                b.setBinding( dbcol.getClass() );
                b.setNillable( true );
                b.setDefaultValue( null );
                b.setLength( 1024 );
                AttributeDescriptor a = b.buildDescriptor( propName );
                builder.add( a );

                // add attrs for nested JSON or Array objects
                if (dbcol instanceof BasicDBObject || dbcol instanceof BasicBSONList)
                {
View Full Code Here

   * feature collection types.
   */
  public SimpleFeatureTypeBuilder(FeatureTypeFactory factory) {
    this.factory = factory;
   
    attributeBuilder = new AttributeTypeBuilder();
    setBindings( new SimpleSchema() );
    reset();
  }
View Full Code Here

TOP

Related Classes of org.geotools.feature.AttributeTypeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.