/** * sustituye el esquema de JUMP por un esquema automático de Geopista. Para una integración * rápida. SOLO PARA PRUEBAS * * @param feature */ public static GeopistaFeature vampiriceSchema(Feature feature) { FeatureSchema fSchema = feature.getSchema(); GeopistaSchema gSchema = new GeopistaSchema(); // crea el atributo Table defTable = new Table("DatosCapa", "Tabla de la BBDD para esta capa."); for (int i = 0; i < fSchema.getAttributeCount(); i++) { // define Dominio, Columna y añade al esquema Domain defDomain; if (fSchema.getAttributeType(i) == AttributeType.DOUBLE || fSchema.getAttributeType(i) == AttributeType.FLOAT) { defDomain = new NumberDomain("?[-INF:INF]", "Default Double Number."); } else if (fSchema.getAttributeType(i) == AttributeType.INTEGER || fSchema.getAttributeType(i) == AttributeType.LONG) { // Definir patron para excluir los decimales. defDomain = new NumberDomain("?[-INF:INF]", "Default Integer Number"); } else { defDomain = new StringDomain("?[.*]", "Dominio por defecto."); } Column col = new Column(fSchema.getAttributeName(i), "Columna automática.", defTable, defDomain); gSchema.addAttribute( fSchema.getAttributeName(i), fSchema.getAttributeType(i), col, READ_WRITE); } GeopistaFeature gFeature = new GeopistaFeature(gSchema); for (int i = 0; i < fSchema.getAttributeCount(); i++) { gFeature.setAttribute(fSchema.getAttributeName(i), feature.getAttribute(i)); } return gFeature; }
protected void copySelectedAttributes() { this.attributes = new FeatureSchema(); for (int i = 0; i < tempAttributes.getAttributeCount(); i++) { for (int i2 = 0; i2 < this.onlyTypes.length; i2++) { if (this.tempAttributes.getAttributeType(i) == this.onlyTypes[i2]) { this.attributes.addAttribute( tempAttributes.getAttributeName(i), tempAttributes.getAttributeType(i)); } } } }
public int getNumOfAttributes() { return attributes.getAttributeCount(); }
/** @return the attribute-name as a String. */ public String getAttribute() { if (attributes.getAttributeCount() > 0) return this.attributes.getAttributeName(this.attributeBox.getSelectedIndex()); return null; }
/** * Write a dbf file with the information from the featureCollection. * * @param featureCollection column data from collection * @param fname name of the dbf file to write to */ void writeDbf(FeatureCollection featureCollection, String fname) throws Exception { DbfFileWriter dbf; FeatureSchema fs; int t; int f; int u; int num; fs = featureCollection.getFeatureSchema(); // -1 because one of the columns is geometry DbfFieldDef[] fields = new DbfFieldDef[fs.getAttributeCount() - 1]; // dbf column type and size f = 0; for (t = 0; t < fs.getAttributeCount(); t++) { AttributeType columnType = fs.getAttributeType(t); String columnName = fs.getAttributeName(t); if (columnType == AttributeType.INTEGER) { fields[f] = new DbfFieldDef(columnName, 'N', 16, 0); f++; } else if (columnType == AttributeType.DOUBLE) { fields[f] = new DbfFieldDef(columnName, 'N', 33, 16); f++; } else if (columnType == AttributeType.STRING) { int maxlength = findMaxStringLength(featureCollection, t); if (maxlength > 255) { throw new Exception( "ShapefileWriter does not support strings longer than 255 characters"); } fields[f] = new DbfFieldDef(columnName, 'C', maxlength, 0); f++; } else if (columnType == AttributeType.DATE) { fields[f] = new DbfFieldDef(columnName, 'D', 8, 0); f++; } else if (columnType == AttributeType.GEOMETRY) { // do nothing - the .shp file handles this } else { throw new Exception("Shapewriter: unsupported AttributeType found in featurecollection."); } } // write header dbf = new DbfFileWriter(fname); dbf.writeHeader(fields, featureCollection.size()); // write rows num = featureCollection.size(); List features = featureCollection.getFeatures(); for (t = 0; t < num; t++) { // System.out.println("dbf: record "+t); Feature feature = (Feature) features.get(t); Vector DBFrow = new Vector(); // make data for each column in this feature (row) for (u = 0; u < fs.getAttributeCount(); u++) { AttributeType columnType = fs.getAttributeType(u); if (columnType == AttributeType.INTEGER) { Object a = feature.getAttribute(u); if (a == null) { DBFrow.add(new Integer(0)); } else { DBFrow.add((Integer) a); } } else if (columnType == AttributeType.DOUBLE) { Object a = feature.getAttribute(u); if (a == null) { DBFrow.add(new Double(0.0)); } else { DBFrow.add((Double) a); } } else if (columnType == AttributeType.DATE) { Object a = feature.getAttribute(u); if (a == null) { DBFrow.add(""); } else { DBFrow.add(DbfFile.DATE_PARSER.format((Date) a)); } } else if (columnType == AttributeType.STRING) { Object a = feature.getAttribute(u); if (a == null) { DBFrow.add(new String("")); } else { // MD 16 jan 03 - added some defensive programming if (a instanceof String) { DBFrow.add(a); } else { DBFrow.add(a.toString()); } } } } dbf.writeRecord(DBFrow); } dbf.close(); }