Package org.geotools.feature

Examples of org.geotools.feature.AttributeTypeBuilder


                if (!isInRetainList || schema.getGeometryDescriptor() == descriptor) {
                    continue;
                }

                // build the attribute to return
                AttributeTypeBuilder builder = new AttributeTypeBuilder();
                builder.setName(schema.getName().getLocalPart() + "_" + descriptor.getName());
                builder.setNillable(descriptor.isNillable());
                builder.setBinding(descriptor.getType().getBinding());
                builder.setMinOccurs(descriptor.getMinOccurs());
                builder.setMaxOccurs(descriptor.getMaxOccurs());
                builder.setDefaultValue(descriptor.getDefaultValue());
                builder.setCRS(schema.getCoordinateReferenceSystem());
                AttributeDescriptor intersectionDescriptor = builder.buildDescriptor(schema
                        .getName().getLocalPart() + "_" + descriptor.getName(),
                        descriptor.getType());
                tb.add(intersectionDescriptor);
                tb.addBinding(descriptor.getType());
            }
View Full Code Here


        for (int i = 0; i < properties.length; i++) {
            types[i] = featureType.getDescriptor(properties[i]);

            if ((override != null) && types[i] instanceof GeometryDescriptor) {
                AttributeTypeBuilder ab = new AttributeTypeBuilder();
                ab.init(types[i]);
                ab.setCRS(override);
                types[i] = ab.buildDescriptor(types[i].getLocalName(), ab.buildGeometryType());
            }
        }

        if (typeName == null)
            typeName = featureType.getTypeName();
View Full Code Here

            // Create schema containing the attributes from both the feature collections
            SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
            for (AttributeDescriptor descriptor : delegate.getSchema().getAttributeDescriptors()) {
                if (sameNames(features.getSchema(), descriptor)
                        && !sameTypes(features.getSchema(), descriptor)) {
                    AttributeTypeBuilder builder = new AttributeTypeBuilder();
                    builder.setName(descriptor.getLocalName());
                    builder.setNillable(descriptor.isNillable());
                    builder.setBinding(String.class);
                    builder.setMinOccurs(descriptor.getMinOccurs());
                    builder.setMaxOccurs(descriptor.getMaxOccurs());
                    builder.setDefaultValue(descriptor.getDefaultValue());
                    builder.setCRS(this.delegate.features().next().getFeatureType()
                            .getCoordinateReferenceSystem());
                    AttributeDescriptor attributeDescriptor = builder.buildDescriptor(descriptor
                            .getName(), builder.buildType());
                    tb.add(attributeDescriptor);
                } else {
                    tb.add(descriptor);
                }
            }
View Full Code Here

        //grab the primary key
        PrimaryKey pkey = getDataStore().getPrimaryKey(entry);
        VirtualTable virtualTable = getDataStore().getVirtualTables().get(entry.getTypeName());
       
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        AttributeTypeBuilder ab = new AttributeTypeBuilder();
       
        // setup the read only marker if no pk or null pk or it's a view
        boolean readOnly = false;
        if(pkey == null || pkey instanceof NullPrimaryKey || virtualTable != null) {
            readOnly = true;
        }

        //set up the name
        String tableName = entry.getName().getLocalPart();
        tb.setName(tableName);

        //set the namespace, if not null
        if (entry.getName().getNamespaceURI() != null) {
            tb.setNamespaceURI(entry.getName().getNamespaceURI());
        } else {
            //use the data store
            tb.setNamespaceURI(getDataStore().getNamespaceURI());
        }

        //grab the state
        JDBCState state = getState();
       
        //grab the schema
        String databaseSchema = getDataStore().getDatabaseSchema();

        //ensure we have a connection
        Connection cx = getDataStore().getConnection(state);
       
        // grab the dialect
        SQLDialect dialect = getDataStore().getSQLDialect();


        //get metadata about columns from database
        try {
            DatabaseMetaData metaData = cx.getMetaData();
            // get metadata about columns from database
            List<ColumnMetadata> columns;
            if (virtualTable != null) {
                columns = getColumnMetadata(cx, virtualTable, dialect, getDataStore());
            } else {
                columns = getColumnMetadata(cx, databaseSchema, tableName, dialect);
            }

            for (ColumnMetadata column : columns) {
                String name = column.name;

                //do not include primary key in the type if not exposing primary key columns
                boolean pkColumn = false;
                for ( PrimaryKeyColumn pkeycol : pkey.getColumns() ) {
                    if ( name.equals( pkeycol.getName() ) ) {
                        if ( !state.isExposePrimaryKeyColumns() ) {
                            name = null;
                            break;
                        } else {
                            pkColumn = true;
                        }
                    }
                    // in views we don't know the pk type, grab it now
                    if(pkeycol.type == null) {
                        pkeycol.type = column.binding;
                    }
                }
            
                if (name == null) {
                    continue;
                }

                //check for association
                if (getDataStore().isAssociations()) {
                    getDataStore().ensureAssociationTablesExist(cx);

                    //check for an association
                    Statement st = null;
                    ResultSet relationships = null;
                    if ( getDataStore().getSQLDialect() instanceof PreparedStatementSQLDialect ) {
                        st = getDataStore().selectRelationshipSQLPS(tableName, name, cx);
                        relationships = ((PreparedStatement)st).executeQuery();
                    }
                    else {
                        String sql = getDataStore().selectRelationshipSQL(tableName, name);
                        getDataStore().getLogger().fine(sql);
                       
                        st = cx.createStatement();
                        relationships = st.executeQuery(sql);
                    }

                   try {
                        if (relationships.next()) {
                            //found, create a special mapping
                            tb.add(name, Association.class);

                            continue;
                        }
                    } finally {
                        getDataStore().closeSafe(relationships);
                        getDataStore().closeSafe(st);
                    }
                   
                }

                //first ask the dialect
                Class binding = column.binding;

                if (binding == null) {
                    //determine from type name mappings
                    binding = getDataStore().getMapping(column.typeName);
                }

                if (binding == null) {
                    //determine from type mappings
                    binding = getDataStore().getMapping(column.sqlType);
                }

                // if still not found, ignore the column we don't know about
                if (binding == null) {
                    getDataStore().getLogger().warning("Could not find mapping for '" + name
                            + "', ignoring the column and setting the feature type read only");
                  readOnly = true;
                  continue;
                }
               
                // store the native database type in the attribute descriptor user data
                ab.addUserData(JDBCDataStore.JDBC_NATIVE_TYPENAME, column.typeName);

                // nullability
                if (!column.nullable) {
                    ab.nillable(false);
                    ab.minOccurs(1);
                }
               
                AttributeDescriptor att = null;
               
                //determine if this attribute is a geometry or not
                if (Geometry.class.isAssignableFrom(binding)) {
                    //add the attribute as a geometry, try to figure out
                    // its srid first
                    Integer srid = null;
                    CoordinateReferenceSystem crs = null;
                    try {
                        if(virtualTable != null) {
                            srid = virtualTable.getNativeSrid(name);
                        } else {
                            srid = dialect.getGeometrySRID(databaseSchema, tableName, name, cx);
                        }
                        if(srid != null)
                            crs = dialect.createCRS(srid, cx);
                    } catch (Exception e) {
                        String msg = "Error occured determing srid for " + tableName + "."
                            + name;
                        getDataStore().getLogger().log(Level.WARNING, msg, e);
                    }
                   
                    // compute the dimension too
                    int dimension = 2;
                    try {
                        if(virtualTable != null) {
                            dimension = virtualTable.getDimension(name);
                        } else {
                            dimension = dialect.getGeometryDimension(databaseSchema, tableName, name, cx);
                        }
                    } catch(Exception e) {
                        String msg = "Error occured determing dimension for " + tableName + "."
                                + name;
                        getDataStore().getLogger().log(Level.WARNING, msg, e);
                    }

                    ab.setBinding(binding);
                    ab.setName(name);
                    ab.setCRS(crs);
                    if(srid != null) {
                        ab.addUserData(JDBCDataStore.JDBC_NATIVE_SRID, srid);
                    }
                    ab.addUserData(Hints.COORDINATE_DIMENSION, dimension);
                    att = ab.buildDescriptor(name, ab.buildGeometryType());
                } else {
                    //add the attribute
                    ab.setName(name);
                    ab.setBinding(binding);
                    att = ab.buildDescriptor(name, ab.buildType());
                }
                // mark primary key columns
                if (pkey.getColumn(att.getLocalName()) != null) {
                    att.getUserData().put(JDBCDataStore.JDBC_PRIMARY_KEY_COLUMN, true);
                }
View Full Code Here

        GeometryFactory gf = new GeometryFactory();
        Point point = gf.createPoint(new Coordinate(-10, 0));
       
        // make up a fake attribute with the same name, something that might happen
        // in chains of retyping where attributes are rebuilt
        AttributeTypeBuilder ab = new AttributeTypeBuilder();
        ab.binding(Point.class);
        AttributeDescriptor madeUp = ab.buildDescriptor(aname("geometry"));
       
        featureStore.modifyFeatures(new AttributeDescriptor[] { madeUp },
            new Object[] { point }, Filter.INCLUDE);

        SimpleFeatureCollection features = featureStore.getFeatures();
View Full Code Here

    @Override
    protected void connect() throws Exception {
        super.connect();
       
        // we need to use the type builder because the pk has min occurs = 1 on Oracle
        AttributeTypeBuilder atb = new AttributeTypeBuilder();
        atb.setMinOccurs(isPkNillable() ? 0 : 1);
        atb.setMaxOccurs(1);
        atb.setNillable(isPkNillable());
        atb.setName(FID);
        atb.setBinding(Integer.class);
        AttributeDescriptor fidDescriptor = atb.buildDescriptor(FID);
       
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setNamespaceURI(dataStore.getNamespaceURI());
        tb.setName(LAKESVIEW);
        tb.add(fidDescriptor);
View Full Code Here

    protected void init() {
        List<Schema> schemas = new ArrayList<Schema>();
        schemas.add(new XSSchema().profile()); // encoding of common java types
        Schema hack = new SchemaImpl(XS.NAMESPACE);

        AttributeTypeBuilder builder = new AttributeTypeBuilder();
        builder.setName("date");
        builder.setBinding(Date.class);
        hack.put(new NameImpl(XS.DATETIME), builder.buildType());

        schemas.add(hack);

        // GML 2
        //
View Full Code Here

        // in an attribute is equivalent to minOccurs == 0 as well
    boolean nillable = eg.isNillable()||eg.getMinOccurs() == 0;
        if( !nillable ){
            try{
                Object defaultValue = DataUtilities.defaultValue(type);
                AttributeTypeBuilder build = new AttributeTypeBuilder();
                build.setName( eg.getName() );
                build.setBinding( type );
                build.setNillable( nillable );
                build.setDefaultValue( defaultValue );

                return build.buildDescriptor(eg.getName());
                              
//                return AttributeTypeFactory.newAttributeDescriptor(
//                        eg.getName(),
//                        type,
//                        nillable,
//                        Filter.INCLUDE,
//                        defaultValue,
//                        null);
            } catch( IllegalArgumentException e ){
                // can happen if the type is not supported by the method. 
                // in this case I'm taking the easy way out and just not
                // having a default value.
                logger.warning("Don't know how to make a default value for: "+type
                        +". Consider making it nillable.");
               
                AttributeTypeBuilder build = new AttributeTypeBuilder();
                build.setName( eg.getName() );
                build.setBinding( type );
                build.setNillable( nillable );
                return build.buildDescriptor(eg.getName());
//                return AttributeTypeFactory.newAttributeType(
//                        eg.getName(),
//                        type,
//                        nillable);
            }
        }
        AttributeTypeBuilder build = new AttributeTypeBuilder();
        build.setName( eg.getName() );
        build.setBinding( type );
        build.setNillable( nillable );
        return build.buildDescriptor(eg.getName());
        //return AttributeTypeFactory.newAttributeType(eg.getName(),type,(nillable));
    }
View Full Code Here

                    }
                }

                if ( rebuild ) {
                    //rebuild with proper crs
                    AttributeTypeBuilder b = new AttributeTypeBuilder();
                    b.init(old);
                    b.setCRS( getCRS(info.getSRS()) );
                    ad = b.buildDescriptor(old.getLocalName());
                }
            }
            catch( Exception e ) {
                //log exception
            }
View Full Code Here

  public static SimpleFeatureType buildFeatureType(String sName, int iShapeType, Class<?>[] fields,
      String[] sFields, CoordinateReferenceSystem crs) {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(sName);

    AttributeTypeBuilder attBuilder = new AttributeTypeBuilder();
    builder.add(toGeometryAttribute(iShapeType, crs,attBuilder));
    builder.setDefaultGeometry("geom");
    for (int i = 0; i < sFields.length; i++) {
      AttributeType type = attBuilder.binding(fields[i]).buildType();
      AttributeDescriptor descriptor = attBuilder.buildDescriptor(sFields[i], type);
      builder.add(descriptor);
    }
    return builder.buildFeatureType();
   
  }
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.