Package org.geotools.feature.simple

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder


            }
        }

        SimpleFeatureType sft = (SimpleFeatureType) oldRevFeatureType.type();
        List<AttributeDescriptor> descriptors = (sft).getAttributeDescriptors();
        SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
        featureTypeBuilder.setCRS(sft.getCoordinateReferenceSystem());
        featureTypeBuilder.setDefaultGeometry(sft.getGeometryDescriptor().getLocalName());
        featureTypeBuilder.setName(sft.getName());
        for (int i = 0; i < descriptors.size(); i++) {
            AttributeDescriptor descriptor = descriptors.get(i);
            if (!removed.contains(descriptor.getName().getLocalPart())) {
                featureTypeBuilder.add(descriptor);
            }
        }
        for (AttributeDescriptor descriptor : added) {
            featureTypeBuilder.add(descriptor);
        }
        SimpleFeatureType featureType = featureTypeBuilder.buildFeatureType();

        return RevFeatureTypeImpl.build(featureType);
    }
View Full Code Here


        if (geomName == null) {
            return featureType;
        }

        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        List<AttributeDescriptor> newAttributes = Lists.newArrayList();

        String oldGeomName = featureType.getGeometryDescriptor().getName().getLocalPart();
        Collection<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors();

        for (AttributeDescriptor descriptor : descriptors) {
            String name = descriptor.getName().getLocalPart();
            Preconditions.checkArgument(!name.equals(geomName),
                    "The provided geom name is already in use by another attribute");
            if (name.equals(oldGeomName)) {
                AttributeDescriptorImpl newDescriptor = new AttributeDescriptorImpl(
                        descriptor.getType(), new NameImpl(geomName), descriptor.getMinOccurs(),
                        descriptor.getMaxOccurs(), descriptor.isNillable(),
                        descriptor.getDefaultValue());
                newAttributes.add(newDescriptor);
            } else {
                newAttributes.add(descriptor);
            }
        }

        builder.setAttributes(newAttributes);
        builder.setName(featureType.getName());
        builder.setCRS(featureType.getCoordinateReferenceSystem());
        featureType = builder.buildFeatureType();
        return featureType;

    }
View Full Code Here

        return featureType;

    }

    private SimpleFeatureType forceFeatureTypeName(SimpleFeatureType featureType, String path) {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setAttributes(featureType.getAttributeDescriptors());
        builder.setName(new NameImpl(featureType.getName().getNamespaceURI(), path));
        builder.setCRS(featureType.getCoordinateReferenceSystem());

        featureType = builder.buildFeatureType();
        return featureType;
    }
View Full Code Here

                serializedFeatureType.getCoordinateReferenceSystem());
    }

    @Test
    public void testSerializationWGS84() throws Exception {
        SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
        ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84);
        ftb.setName("type");
        SimpleFeatureType ftype = ftb.buildFeatureType();
        RevFeatureType revFeatureType = RevFeatureTypeImpl.build(ftype);
        ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        writer.write(revFeatureType, output);
View Full Code Here

     *
     * @return
     */
    public SimpleFeatureType getFeatureType() {
        if (featureType == null) {
            SimpleFeatureTypeBuilder fb = new SimpleFeatureTypeBuilder();
            fb.setName(name);
            fb.add("id", Long.class);
            if (defaultFields != null) {
                for (DefaultField df : defaultFields) {
                    fb.add(df.name().toLowerCase(), df.getFieldClass());
                }
            }
            Set<String> keys = this.fields.keySet();
            for (String key : keys) {
                AttributeDefinition field = fields.get(key);
                Class<?> clazz = field.getType().getBinding();
                if (Geometry.class.isAssignableFrom(clazz)) {
                    Preconditions.checkArgument(geometryType == null,
                            "The mapping has more than one geometry attribute");
                    CoordinateReferenceSystem epsg4326;
                    try {
                        epsg4326 = CRS.decode("EPSG:4326", true);
                        fb.add(field.getName(), clazz, epsg4326);
                    } catch (NoSuchAuthorityCodeException e) {
                    } catch (FactoryException e) {
                    }
                    geometryType = clazz;
                } else {
                    fb.add(field.getName(), clazz);
                }
            }
            Preconditions.checkNotNull(geometryType,
                    "The mapping rule does not define a geometry field");
            if (!geometryType.equals(Point.class)) {
                fb.add("nodes", String.class);
            }
            featureType = fb.buildFeatureType();

            featureBuilder = new SimpleFeatureBuilder(featureType);

        }
        return featureType;
View Full Code Here

        insertAndAdd(modifiedFeature, points2);
        final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();

        Feature[] points = new Feature[] { modifiedFeature, points2 };

        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(pointsType.getName());
        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
View Full Code Here

                "changedProp", new Integer(1500));
        insertAndAdd(modifiedFeature, points2);
        final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();

        Feature[] points = new Feature[] { points1 };
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(pointsType.getName());
        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
View Full Code Here

        return filterNulls;
    }

    private static SimpleFeatureType addFidAttribute(RevFeatureType revFType) {
        SimpleFeatureType featureType = (SimpleFeatureType) revFType.type();
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(featureType.getName());
        builder.setCRS(featureType.getCoordinateReferenceSystem());
        featureType = builder.buildFeatureType();
        return featureType;
    }
View Full Code Here

        final Name name = featureType.getName();
        final Name assignedName = getEntry().getName();

        if (assignedName.getNamespaceURI() != null && !assignedName.equals(name)) {
            SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
            builder.init(featureType);
            builder.setName(assignedName);
            featureType = builder.buildFeatureType();
        }
        return featureType;
    }
View Full Code Here

        }
    }

    @Test
    public void testImportAllWithDifferentFeatureTypesAndDestPathAndAdd() throws Exception {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setCRS(CRS.decode("EPSG:4326"));
        builder.add("geom", Point.class);
        builder.add("label", String.class);
        builder.setName("dest");
        SimpleFeatureType type = builder.buildFeatureType();
        GeometryFactory gf = new GeometryFactory();
        SimpleFeature feature = SimpleFeatureBuilder.build(type,
                new Object[] { gf.createPoint(new Coordinate(0, 0)), "feature0" }, "feature");
        geogig.getRepository().workingTree().insert("dest", feature);
        ImportOp importOp = geogig.command(ImportOp.class);
View Full Code Here

TOP

Related Classes of org.geotools.feature.simple.SimpleFeatureTypeBuilder

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.