当前位置: 首页>>代码示例>>Java>>正文


Java SimpleFeatureTypeBuilder.addAll方法代码示例

本文整理汇总了Java中org.geotools.feature.simple.SimpleFeatureTypeBuilder.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeatureTypeBuilder.addAll方法的具体用法?Java SimpleFeatureTypeBuilder.addAll怎么用?Java SimpleFeatureTypeBuilder.addAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.geotools.feature.simple.SimpleFeatureTypeBuilder的用法示例。


在下文中一共展示了SimpleFeatureTypeBuilder.addAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FeatureGeometrySubstitutor

import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
 * @param oldFeatureType the {@link FeatureType} of the existing features.
 * @throws FactoryRegistryException 
 * @throws SchemaException
 */
public FeatureGeometrySubstitutor( SimpleFeatureType oldFeatureType, Class< ? > newGeometryType ) throws Exception {

    List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType.getAttributeDescriptors();

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(oldFeatureType.getName());
    b.setCRS(oldFeatureType.getCoordinateReferenceSystem());

    if (newGeometryType == null) {
        b.addAll(oldAttributeDescriptors);
    } else {
        for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) {
            if (attributeDescriptor instanceof GeometryDescriptor) {
                b.add("the_geom", newGeometryType);
            } else {
                b.add(attributeDescriptor);
            }
        }
    }
    newFeatureType = b.buildFeatureType();
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:28,代码来源:FeatureGeometrySubstitutor.java

示例2: FeatureExtender

import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
 * @param oldFeatureType the {@link FeatureType} of the existing features.
 * @param fieldArray the list of the names of new fields. 
 * @param classesArray the list of classes of the new fields.
 * @throws FactoryRegistryException 
 * @throws SchemaException
 */
public FeatureExtender( SimpleFeatureType oldFeatureType, String[] fieldArray,
        Class<?>[] classesArray ) throws FactoryRegistryException, SchemaException {

    List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType
            .getAttributeDescriptors();
    List<AttributeDescriptor> addedAttributeDescriptors = new ArrayList<AttributeDescriptor>();
    for( int i = 0; i < fieldArray.length; i++ ) {
        AttributeTypeBuilder build = new AttributeTypeBuilder();
        build.setNillable(true);
        build.setBinding(classesArray[i]);
        AttributeDescriptor descriptor = build.buildDescriptor(fieldArray[i]);
        addedAttributeDescriptors.add(descriptor);
    }

    List<AttributeDescriptor> newAttributesTypesList = new ArrayList<AttributeDescriptor>();
    for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) {
        newAttributesTypesList.add(attributeDescriptor);
    }
    newAttributesTypesList.addAll(addedAttributeDescriptors);

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(oldFeatureType.getName());
    b.setCRS(oldFeatureType.getCoordinateReferenceSystem());
    b.addAll(newAttributesTypesList);
    newFeatureType = b.buildFeatureType();
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:35,代码来源:FeatureExtender.java

示例3: alter

import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
SimpleFeatureSource alter(SimpleFeatureCollection collection, String typename,
        SimpleFeatureType featureType, final List<AttributeDescriptor> newTypes) {
    
    try {
        
        // Create target schema
        SimpleFeatureTypeBuilder buildType = new SimpleFeatureTypeBuilder();
        buildType.init(featureType);
        buildType.setName(typename);
        buildType.addAll(newTypes);
        
        final SimpleFeatureType schema = buildType.buildFeatureType();
        // Configure memory datastore
        final MemoryDataStore memory = new MemoryDataStore();
        memory.createSchema(schema);
        
        collection.accepts(new FeatureVisitor() {
            public void visit(Feature feature) {
                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
                
                builder.init((SimpleFeature) feature);
                for (AttributeDescriptor descriptor : newTypes) {
                    builder.add(DataUtilities.defaultValue(descriptor));
                }
                
                SimpleFeature newFeature = builder.buildFeature(feature.getIdentifier().getID());
                memory.addFeature(newFeature);
            }
        }, null);
        
        return memory.getFeatureSource(typename);
        
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:38,代码来源:DataExamples.java

示例4: mergeShapeFile

import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
 *
 * @param layer
 * @param shpInput
 * @param transform
 * @return
 * @throws Exception
 */
public static GeometryImage mergeShapeFile(SimpleFeatureCollection collectionsLayer, File shpInput,GeoTransform transform,Polygon bbox)throws Exception {
	Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", shpInput.toURI().toURL());

    //create a DataStore object to connect to the physical source
    DataStore dataStore = DataStoreFinder.getDataStore(params);

    SimpleFeatureSource shape2 = (SimpleFeatureSource) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

    SimpleFeatureCollection collectionsShape2=shape2.getFeatures();
    SimpleFeatureType schemaShape2=shape2.getSchema();

    ClipProcess clip=new ClipProcess();
    SimpleFeatureCollection fc=clip.execute(collectionsShape2, bbox,true);

    SimpleFeatureType schemaLayer=collectionsLayer.getSchema();

    //merge the schema and the types
    SimpleFeatureTypeBuilder stb = new SimpleFeatureTypeBuilder();
    stb.setName("merged_geom");
    stb.setCRS(schemaLayer.getCoordinateReferenceSystem());
    stb.addAll(schemaShape2.getAttributeDescriptors());
    stb.addAll(schemaLayer.getAttributeDescriptors());
    SimpleFeatureType newFeatureType = stb.buildFeatureType();

    //create new datastore to save the new shapefile
    FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
    File tmp=new File(SumoPlatform.getApplication().getCachePath()+"\\tmpshape_"+System.currentTimeMillis()+".shp");
    Map<String, Serializable> params2 = new HashMap<String, Serializable>();
    params2.put("url", tmp.toURI().toURL());
    ShapefileDataStore newds=(ShapefileDataStore)factory.createNewDataStore(params2);
    GeometryImage out=null;
    try{
     newds.createSchema(newFeatureType);

     //merge the feaures
     SimpleFeatureStore mergeFeat=(SimpleFeatureStore)newds.getFeatureSource();
     mergeFeat.addFeatures(collectionsLayer);
     mergeFeat.addFeatures(fc);
     //save the new shape file
     exportToShapefile(newds, mergeFeat.getFeatures());//,newds.getSchema());

     //from here create the new GeometricLayer
     Collection<PropertyDescriptor>descriptorsMerge=new ArrayList<>();
     descriptorsMerge.addAll(schemaShape2.getDescriptors());
     descriptorsMerge.addAll(schemaLayer.getDescriptors());

     String[] schema = createSchema(descriptorsMerge);
     String[] types = createTypes(descriptorsMerge);


     String geoName = schemaLayer.getGeometryDescriptor().getType().getName().toString();
     out=GeometryImage.createLayerFromFeatures(geoName, newds, mergeFeat.getFeatures(), schema, types,true,transform);
     //out = GeometricLayer.createImageProjectedLayer(out, transform,null);
     out.setName("merge_"+shpInput.getName()+"_"+LayerManager.getIstanceManager().getCurrentImageLayer().getName());
    }finally{
    	if(newds!=null)
    		newds.dispose();
    }
    return out;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:70,代码来源:SimpleShapefile.java


注:本文中的org.geotools.feature.simple.SimpleFeatureTypeBuilder.addAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。