Package org.opengis.feature.type

Examples of org.opengis.feature.type.GeometryDescriptor


            return null;
        }
       
        List<ReferencedEnvelope> envs = new ArrayList();
        for (TessellationInfo tinfo : tinfos) {
            GeometryDescriptor gatt =
                (GeometryDescriptor) featureType.getDescriptor(tinfo.getColumName());
           
            ReferencedEnvelope env = new ReferencedEnvelope(gatt.getCoordinateReferenceSystem());
            env.init(tinfo.getUBounds());
            envs.add(env);
        }
       
       
View Full Code Here


        String tableName = featureType.getName().getLocalPart();

        // register all geometry columns in the database
        for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
            if (att instanceof GeometryDescriptor) {
                GeometryDescriptor gd = (GeometryDescriptor) att;
               
                //figure out the native db srid
                int srid = 0;
                   
                Integer epsg = null;
                if (gd.getCoordinateReferenceSystem() != null) {
                    try {
                        epsg = CRS.lookupEpsgCode(gd.getCoordinateReferenceSystem(), true);
                    }
                    catch(Exception e) {
                        LOGGER.log(Level.WARNING, "Error looking up epsg code", e);
                    }
                }

                if (epsg != null) {
                    String sql = "SELECT SRID FROM SYSSPATIAL.spatial_ref_sys"
                            + " WHERE AUTH_SRID = ?";
                    LOGGER.log(Level.FINE, sql + ";{0}", epsg);
                   
                    PreparedStatement ps = cx.prepareStatement(sql);
                    try {
                        ps.setInt(1, epsg);
                       
                        ResultSet rs = ps.executeQuery();
                        try {
                            if (rs.next()) {
                                srid = rs.getInt("SRID");
                            }
                            else {
                                LOGGER.warning("EPSG Code " + epsg + " does not map to SRID");
                            }
                        }
                        finally {
                            dataStore.closeSafe(ps);
                        }
                    }
                    finally {
                        dataStore.closeSafe(ps);
                    }
                }
               
                // grab the geometry type
                String geomType = CLASS_TO_TYPE.get(gd.getType().getBinding());
                geomType = geomType != null ? geomType : "GEOMETRY";

                //insert into geometry columns table
                String sql =
                    "INSERT INTO SYSSPATIAL.GEOMETRY_COLUMNS (F_TABLE_CATALOG, F_TABLE_SCHEMA, " +
                        "F_TABLE_NAME, F_GEOMETRY_COLUMN, COORD_DIMENSION, SRID, GEOM_TYPE) " +
                    "VALUES (?, ?, ?, ?, 2, ?, ?)";
                LOGGER.log(Level.FINE, sql + ";{0},{1},{2},{3},{4},{5}",
                    new Object[]{"", schemaName, tableName, gd.getLocalName(), srid, geomType});

                PreparedStatement ps = cx.prepareStatement(sql);
                try {
                    ps.setString(1, "");
                    ps.setString(2, schemaName);
                    ps.setString(3, tableName);
                    ps.setString(4, gd.getLocalName());
                    ps.setInt(5, srid);
                    ps.setString(6, geomType);
                   
                    ps.execute();
                }
                finally {
                    dataStore.closeSafe(ps);
                }

                //create the spatial index table
                PrimaryKey pkey = dataStore.getPrimaryKeyFinder()
                    .getPrimaryKey(dataStore, schemaName, tableName, cx);
                if (!(pkey instanceof NullPrimaryKey)) {
                    String indexTableName = tableName + "_" + gd.getLocalName() + "_idx";
                    String hashIndex = indexTableName + "_idx";
                   
                    // drop index hash index if exists
                    StringBuffer sb = new StringBuffer("DROP HASH INDEX ");
                    encodeTableName(schemaName, hashIndex, sb);
                   
                    sql = sb.toString();
                    LOGGER.fine(sql);
                   
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    }
                    catch(SQLException e) {
                        //ignore
                    }
                    finally {
                        dataStore.closeSafe(ps);
                    }
                   
                    // drop index table if exists
                    sb = new StringBuffer("DROP TABLE ");
                    encodeTableName(schemaName, indexTableName, sb);
                   
                    sql = sb.toString();
                    LOGGER.fine(sql);
                   
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    }
                    catch(SQLException e) {
                        //ignore
                    }
                    finally {
                        dataStore.closeSafe(ps);
                    }

                    // create index table
                    sb = new StringBuffer("CREATE MULTISET TABLE ");
                    encodeTableName(schemaName, indexTableName, sb);
                    sb.append("( ");
                   
                    for (PrimaryKeyColumn col : pkey.getColumns()) {
                        encodeColumnName(col.getName(), sb);
                       
                        String typeName = lookupSqlTypeName(cx, schemaName, tableName, col.getName());
                        sb.append(" ").append(typeName).append(" NOT NULL, ");
                    }
                    if (!pkey.getColumns().isEmpty()) {
                        // @todo only looking at first primary key
                        // more multiply keyed tables, this at least ensures some speed
                        sb.append("cellid INTEGER NOT NULL)");
                        sb.append("PRIMARY INDEX (");
                        encodeColumnName(pkey.getColumns().get(0).getName(), sb);
                        sb.append(")");
                    }
                    sql = sb.toString();
                    LOGGER.fine(sql);
                    try {
                       ps = cx.prepareStatement(sql);
                       ps.execute();
                    } finally {
                        dataStore.closeSafe(ps);
                    }

                    // create hash
                    sb = new StringBuffer("CREATE HASH INDEX " + hashIndex + " (cellid) ON " + indexTableName + " ORDER BY (cellid)");
                    sql = sb.toString();
                    LOGGER.fine(sql);
                    try {
                        ps = cx.prepareStatement(sql);
                        ps.execute();
                    } finally {
                        dataStore.closeSafe(ps);
                    }

                    installTriggers(cx,tableName,gd.getLocalName(),indexTableName,pkey.getColumns());
                   
                }
                else {
                    LOGGER.warning("No primary key for " + schemaName + "." + tableName + ". Unable"
                       + " to create spatial index.");
View Full Code Here

                        }
                    }
                }
                attrDescrs.add(descr);
            }
            GeometryDescriptor geomDescr = (GeometryDescriptor) baseType.getDescriptor(info
                    .getGeomPropertyName());

            featureTyp = new SimpleFeatureTypeImpl(new NameImpl(
                    dataStore.getNamespace() == null ? null : dataStore.getNamespace().toString(),
                    info.getFeatureName()), attrDescrs, geomDescr, false, null, null, baseType
View Full Code Here

       
        try {
            //post process the feature type and set up constraints based on geometry type
            for ( PropertyDescriptor ad : featureType.getDescriptors() ) {
                if ( ad instanceof GeometryDescriptor ) {
                    GeometryDescriptor gd = (GeometryDescriptor)ad;
                    Class binding = ad.getType().getBinding();
                    String propertyName = ad.getName().getLocalPart();
                 
                    //create a spatial index
                    int epsg = -1;
                    try {
                        CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem();
                        if (crs != null) {
                            Integer code = CRS.lookupEpsgCode(crs, true);
                            epsg = code != null ? code : -1;
                        }
                        else {
                            LOGGER.warning("Column " + gd.getLocalName() + " has no crs");
                        }
                    }
                    catch (FactoryException e) {
                        LOGGER.log(Level.FINER, "Unable to look epsg code", e);
                    }

                    StringBuffer sql = new StringBuffer();
                    sql.append("CALL AddGeometryColumn(");
                    sql.append("'").append(schemaName).append("'");

                    sql.append(", '").append(tableName).append("'");
                    sql.append(", '").append(gd.getLocalName()).append("'");
                    sql.append(", ").append(epsg);
                    sql.append(", '").append(Geometries.getForBinding(binding).getName()).append("'");
                    sql.append(", ").append(2); //TODO: dimension
                    sql.append(")");
                   
View Full Code Here

        assertNotNull( resultType );
        assertNotSame( resultType, origionalType );

        assertEquals( world, resultType.getCoordinateReferenceSystem() );

        GeometryDescriptor geometryDescriptor = resultType.getGeometryDescriptor();       
    }
View Full Code Here

            for (AttributeDescriptor att : zones.getSchema().getAttributeDescriptors()) {
                tb.minOccurs(att.getMinOccurs());
                tb.maxOccurs(att.getMaxOccurs());
                tb.restrictions(att.getType().getRestrictions());
                if (att instanceof GeometryDescriptor) {
                    GeometryDescriptor gatt = (GeometryDescriptor) att;
                    tb.crs(gatt.getCoordinateReferenceSystem());
                }
                tb.add("z_" + att.getLocalName(), att.getType().getBinding());
            }
            if(classification != null) {
                tb.add("classification", Integer.class);
View Full Code Here

    @Override
    protected SimpleFeatureType getTargetSchema(SimpleFeatureType sourceSchema, Map<String, Object> input) {
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        for (AttributeDescriptor ad : sourceSchema.getAttributeDescriptors()) {
            GeometryDescriptor defaultGeometry = sourceSchema.getGeometryDescriptor();
            if(ad == defaultGeometry) {
                tb.add(ad.getName().getLocalPart(), MultiPolygon.class, defaultGeometry.getCoordinateReferenceSystem());
            } else {
                tb.add(ad);
            }
        }
        tb.setName(sourceSchema.getName());
View Full Code Here

// docs start set geometry
    /**
     * Retrieve information about the feature geometry
     */
    private void setGeometry() {
        GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
        geometryAttributeName = geomDesc.getLocalName();

        Class<?> clazz = geomDesc.getType().getBinding();

        if (Polygon.class.isAssignableFrom(clazz) ||
                MultiPolygon.class.isAssignableFrom(clazz)) {
            geometryType = GeomType.POLYGON;

View Full Code Here

                    "Filter Function problem for test buffer argument #0 - expected type Double");
        }
       
        // compute the output schema
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        GeometryDescriptor gd = fc.getSchema().getGeometryDescriptor();
        tb.add(gd.getName().getLocalPart(), Polygon.class, gd.getCoordinateReferenceSystem());
        tb.setName("bufferedCollection");
        SimpleFeatureType schema = tb.buildFeatureType();
       
        // compute the output features
        SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema);
View Full Code Here

    }
   
    public void testGeometryMetadataTable() throws Exception {
        testSetup.setupGeometryColumns(dataStore);
       
        GeometryDescriptor gd = dataStore.getFeatureSource("GTMETA").getSchema().getGeometryDescriptor();
        assertEquals(Point.class, gd.getType().getBinding());
        assertEquals(4269, (int) CRS.lookupEpsgCode(gd.getCoordinateReferenceSystem(), false));
    }
View Full Code Here

TOP

Related Classes of org.opengis.feature.type.GeometryDescriptor

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.