Examples of PropertyFeatureReader


Examples of org.geotools.data.property.PropertyFeatureReader

        StringBuffer buf = new StringBuffer();
        // drop schema if exists to start clean
        buf.append("DROP SCHEMA IF EXISTS ").append(ONLINE_DB_SCHEMA).append(" CASCADE;\n");
        buf.append("CREATE SCHEMA ").append(ONLINE_DB_SCHEMA).append(";\n");
        for (String fileName : propertyFiles.keySet()) {
            PropertyFeatureReader reader = new PropertyFeatureReader(propertyFiles.get(fileName),
            // remove .properties as it will be added in PropertyFeatureReader constructor
                    fileName.substring(0, fileName.lastIndexOf(".properties")));
            SimpleFeatureType schema = reader.getFeatureType();
            String tableName = schema.getName().getLocalPart().toUpperCase();
            // create the table
            buf.append("CREATE TABLE ").append(ONLINE_DB_SCHEMA).append(".\"").append(tableName)
                    .append("\"(");
            List<GeometryDescriptor> geoms = new ArrayList<GeometryDescriptor>();
            // +pkey
            int size = schema.getAttributeCount() + 1;
            String[] fieldNames = new String[size];
            List<String> createParams = new ArrayList<String>();
            int j = 0;
            String field;
            String type;
            for (PropertyDescriptor desc : schema.getDescriptors()) {
                if (desc instanceof GeometryDescriptor) {
                    geoms.add((GeometryDescriptor) desc);
                } else {
                    field = "\"" + desc.getName() + "\" ";
                    type = Classes.getShortName(desc.getType().getBinding());
                    if (type.equalsIgnoreCase("String")) {
                        type = "TEXT";
                    } else if (type.equalsIgnoreCase("Double")) {
                        type = "DOUBLE PRECISION";
                    }
                    field += type;
                    createParams.add(field);
                }
                fieldNames[j] = desc.getName().toString();
                j++;
            }
            // Add numeric PK for sorting
            fieldNames[j] = "PKEY";
            createParams.add("\"PKEY\" TEXT");
            buf.append(StringUtils.join(createParams.iterator(), ", "));
            buf.append(");\n");
            buf.append("ALTER TABLE " + ONLINE_DB_SCHEMA + ".\"" + tableName + "\" ADD CONSTRAINT " + tableName + "_PK PRIMARY KEY (\"PKEY\")\n");

            // add geometry columns
            for (GeometryDescriptor geom : geoms) {
                buf.append("SELECT AddGeometryColumn ('").append(ONLINE_DB_SCHEMA).append("', ");
                buf.append("'").append(tableName).append("', ");
                buf.append("'").append(geom.getName().toString()).append("', ");
                int srid = getSrid(geom.getType());
                buf.append(srid).append(", ");
                // TODO: should read the properties file header to see if they're more specific
                buf.append("'GEOMETRY'").append(", ");
                // TODO: how to work this out properly?
                buf.append(geom.getType().getCoordinateReferenceSystem()==null? 2: geom.getType().getCoordinateReferenceSystem().getCoordinateSystem().getDimension());
                buf.append(");\n");
            }

            // then insert rows
            SimpleFeature feature;
            FeatureId id;
            while (reader.hasNext()) {
                buf.append("INSERT INTO ").append(ONLINE_DB_SCHEMA).append(".\"").append(tableName)
                        .append("\"(\"");
                feature = reader.next();
                buf.append(StringUtils.join(fieldNames, "\", \""));
                buf.append("\") ");
                buf.append("VALUES (");
                Collection<Property> properties = feature.getProperties();
                String[] values = new String[size];
View Full Code Here

Examples of org.geotools.data.property.PropertyFeatureReader

                .append(
                        "raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);")
                .append("END DROP_TABLE_OR_VIEW;\n");

        for (String fileName : propertyFiles.keySet()) {
            PropertyFeatureReader reader = new PropertyFeatureReader(propertyFiles.get(fileName),
            // remove .properties as it will be added in PropertyFeatureReader constructor
                    fileName.substring(0, fileName.lastIndexOf(".properties")));
            SimpleFeatureType schema = reader.getFeatureType();
            String tableName = schema.getName().getLocalPart().toUpperCase();
            // drop table if exists
            buf.append("CALL DROP_TABLE_OR_VIEW('").append(tableName).append("')\n");
            // create the table
            buf.append("CREATE TABLE ").append(tableName).append("(");
            // + pkey
            int size = schema.getAttributeCount() + 1;
            String[] fieldNames = new String[size];
            List<String> createParams = new ArrayList<String>();
            int j = 0;
            String type;
            String field;
            int spatialIndexCounter = 0;
            for (PropertyDescriptor desc : schema.getDescriptors()) {
                field = desc.getName().toString().toUpperCase();
                fieldNames[j] = field;
                if (desc instanceof GeometryDescriptor) {
                    type = "SDO_GEOMETRY";
                    // Update spatial index
                    int srid = getSrid(((GeometryType) desc.getType()));
                   
                    spatialIndex.append("DELETE FROM user_sdo_geom_metadata WHERE table_name = '")
                            .append(tableName).append("'\n");
   
                    spatialIndex
                            .append("Insert into user_sdo_geom_metadata ")
                            .append("(TABLE_NAME,COLUMN_NAME,DIMINFO,SRID)")
                            .append("values ('")
                            .append(tableName)
                            .append("','")
                            .append(field)
                            .append(
                                    "',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',140.962,144.909,0.00001),")
                            .append("MDSYS.SDO_DIM_ELEMENT('Y',-38.858,-33.98,0.00001)")
                            .append( //support 3d index
                                ((GeometryDescriptor) desc).getCoordinateReferenceSystem() != null
                                && ((GeometryDescriptor) desc).getCoordinateReferenceSystem().getCoordinateSystem().getDimension() == 3 ?
                                ", MDSYS.SDO_DIM_ELEMENT('Z',-100000, 100000, 1) )," : "),")
                            .append(srid).append(")\n");

                    // ensure it's <= 30 characters to avoid Oracle exception
                    String indexName = (tableName.length() <= 26 ? tableName : tableName.substring(
                            0, 26)) + "_IDX";
                    if (spatialIndexCounter > 0) {
                        // to avoid duplicate index name when there are > 1 geometry in the same table
                        indexName += spatialIndexCounter;
                    }

                    spatialIndex.append("CREATE INDEX \"").append(indexName).append("\" ON \"")
                            .append(tableName).append("\"(\"").append(field).append("\") ").append(
                                    "INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\"\n");
                    spatialIndexCounter++;
                } else {
                    type = Classes.getShortName(desc.getType().getBinding());
                    if (type.equalsIgnoreCase("String")) {
                        type = "NVARCHAR2(250)";
                    } else if (type.equalsIgnoreCase("Double")) {
                        type = "NUMBER";
                    }
                    // etc. assign as required
                }
                createParams.add(field + " " + type);
                j++;
            }
            // Add numeric PK for sorting
            fieldNames[j] = "PKEY";
            createParams.add("PKEY VARCHAR2(30)");
            buf.append(StringUtils.join(createParams.iterator(), ", "));
            buf.append(")\n");
            buf.append("ALTER TABLE " + tableName + " ADD CONSTRAINT " + tableName + " PRIMARY KEY (PKEY)\n");
            // then insert rows
            SimpleFeature feature;
            FeatureId id;
            while (reader.hasNext()) {
                buf.append("INSERT INTO ").append(tableName).append("(");
                feature = reader.next();
                buf.append(StringUtils.join(fieldNames, ", "));
                buf.append(") ");
                buf.append("VALUES (");
                Collection<Property> properties = feature.getProperties();
                String[] values = new String[size];
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.