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


Java ShapefileDataStore.getTypeNames方法代码示例

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


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

示例1: write

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public static <T> void write(File file,
        Consumer<SimpleFeatureTypeBuilder> fun1,
        BiConsumer<SimpleFeatureBuilder, T> fun2,
        List<T> geometries) {
    try {
        SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("MyFeatureType");
        typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
        fun1.accept(typeBuilder);
        SimpleFeatureType type = typeBuilder.buildFeatureType();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
        AtomicInteger id = new AtomicInteger(0);
        List<SimpleFeature> geoms = geometries.stream().map(g -> {
            fun2.accept(featureBuilder, g);
            return featureBuilder.buildFeature(String.valueOf(id.getAndIncrement()));
        }).collect(toList());
        ShapefileDataStoreFactory datastoreFactory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = newHashMap();
        params.put("url", file.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore datastore = (ShapefileDataStore) datastoreFactory.createNewDataStore(params);
        datastore.createSchema(type);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = datastore.getTypeNames()[0];
        SimpleFeatureSource featureSource = datastore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(type, geoms);
        featureStore.setTransaction(transaction);
        featureStore.addFeatures(collection);
        transaction.commit();
        transaction.close();
        datastore.dispose();
    }
    catch (IOException e) {
        throw propagate(e);
    }
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:38,代码来源:ShapefileWriter.java

示例2: init

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
@Override
public void init() {
	LOGGER.info("Output as shapefile: " + outFile);
	file = new File(outFile);

	try {
		// Define Schema
		final SimpleFeatureType TYPE = createFeatureType();
		featureBuilder = new SimpleFeatureBuilder(TYPE);

		geomF = new GeometryFactory();
		ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

		// define parameter for ShapeFileDataStore object
		Map<String, Serializable> params = new HashMap<String, Serializable>();
		params.put("url", file.toURI().toURL());
		params.put("create spatial index", Boolean.TRUE);

		dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
		dataStore.createSchema(TYPE);

		// define transaction
		transaction = new DefaultTransaction("create");
		String typeName = dataStore.getTypeNames()[0];
		SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
		if (featureSource instanceof SimpleFeatureStore) {
			featureStore = (SimpleFeatureStore) featureSource;

			featureStore.setTransaction(transaction);
		}
	} catch (IOException e1) {
		e1.printStackTrace();
	}
}
 
开发者ID:GIScience,项目名称:osmgpxfilter,代码行数:35,代码来源:ShapeFileWriter.java

示例3: getFeatureCollection

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
/**
 * @param filename shp file to be opened
 * @param encoding encoding of opened shp file
 * @return a feature collection of opened shp file
 * @throws IOException
 * @throws FactoryException
 * @throws NoSuchAuthorityCodeException
 */
public static SimpleFeatureCollection getFeatureCollection(String filename, String encoding)
    throws IOException, NoSuchAuthorityCodeException, FactoryException {
  // Open file
  File infile = new File(filename);

  // Parameters of ShapefileDatastore
  Map<String, Serializable> params = new HashMap<String, Serializable>();
  params.put(ShapefileDataStoreFactory.URLP.key, infile.toURI().toURL());
  // params.put("create spatial index", Boolean.TRUE);
  params.put(ShapefileDataStoreFactory.DBFCHARSET.key, encoding);

  // -- Create ShapefileDatastore -- //
  ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
  ShapefileDataStore shapefile = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
  // shapefile.setStringCharset(Charset.forName("ISO8859-7"));
  // DataStore shapefile = new ShapefileDataStore( infile.toURI().toURL(), false);

  // Get feature collection
  String[] typeName = shapefile.getTypeNames();
  SimpleFeatureSource featureSource = shapefile.getFeatureSource(typeName[0]);
  // SimpleFeatureCollection collection;
  SimpleFeatureCollection featureCollection = featureSource.getFeatures();

  // SimpleFeatureIterator clcFeatureIterator =
  // clcFeatureCollection.features();
  return featureCollection;
}
 
开发者ID:esarbanis,项目名称:strabon,代码行数:36,代码来源:GeonamesParser.java

示例4: writeEsriShapefile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
static void writeEsriShapefile(Class<?> geomType, List<SimpleFeature> features, File file) throws IOException {
    String geomName = geomType.getSimpleName();
    String basename = file.getName();
    if (basename.endsWith(FILE_EXTENSION_SHAPEFILE)) {
        basename = basename.substring(0, basename.length() - 4);
    }
    File file1 = new File(file.getParentFile(), basename + "_" + geomName + FILE_EXTENSION_SHAPEFILE);

    SimpleFeature simpleFeature = features.get(0);
    SimpleFeatureType simpleFeatureType = changeGeometryType(simpleFeature.getType(), geomType);

    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    Map<String, Serializable> map = Collections.singletonMap("url", file1.toURI().toURL());
    ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(map);
    dataStore.createSchema(simpleFeatureType);
    String typeName = dataStore.getTypeNames()[0];
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
    DefaultTransaction transaction = new DefaultTransaction("X");
    if (featureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(simpleFeatureType, features);
        featureStore.setTransaction(transaction);
        // I'm not sure why the next line is necessary (mp/20170627)
        // Without it is not working, the wrong feature type is used for writing
        // But it is not mentioned in the tutorials
        dataStore.getEntry(featureSource.getName()).getState(transaction).setFeatureType(simpleFeatureType);
        try {
            featureStore.addFeatures(collection);
            transaction.commit();
        } catch (Exception problem) {
            transaction.rollback();
            throw new IOException(problem);
        } finally {
            transaction.close();
        }
    } else {
        throw new IOException(typeName + " does not support read/write access");
    }
}
 
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:40,代码来源:ExportGeometryAction.java

示例5: preparePointFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void preparePointFile(ArrayList<osmNode> osmNodes) throws IOException, SchemaException {
	uniquePointTagKeys = getUniquePointTagKeys(osmNodes);
    String passPointString = new String("location:Point:srid=4326,"+"id:Double");
    for(String attribute:uniquePointTagKeys){
    	int colon;
    	do{
     	colon = attribute.indexOf(":");
     	if(colon!=-1){
     		attribute = attribute.substring(0, colon)+"_"+attribute.substring(colon+1);
     	}
    	}while(colon!=-1);
    	passPointString=passPointString+","+attribute+":String";
    }
    
    pointType = DataUtilities.createType("Location", passPointString);
    
    pointCollection = FeatureCollections.newCollection();
    
    pointBuilder = new SimpleFeatureBuilder(pointType);
    
    pointFeature = pointBuilder.buildFeature(null);
    
    ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
    
    Map <String,Serializable> parameters = new HashMap<String, Serializable>();
    
    parameters.put("url",shpPointFile.toURI().toURL());
    parameters.put("create spatial index",Boolean.TRUE);
    
    ShapefileDataStore newdatastore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(parameters);
    newdatastore.createSchema(pointType);
    
    newdatastore.forceSchemaCRS(DefaultGeographicCRS.WGS84);  
    
    String typename = newdatastore.getTypeNames()[0];
    
    SimpleFeatureSource simpfeatsource = newdatastore.getFeatureSource(typename);
    
    pointFeatureStore = (SimpleFeatureStore)simpfeatsource;
}
 
开发者ID:banmedo,项目名称:Converter,代码行数:41,代码来源:shpMain.java

示例6: prepareLineFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void prepareLineFile(ArrayList<osmLine> osmLines) throws SchemaException, MalformedURLException, IOException {
	uniqueLineTagKeys = getUniqueTagKeys(osmLines,"lines");
    String passLineString = new String("location:LineString:srid=4326,"+"id:Double");
    for(String attribute:uniqueLineTagKeys){
    	int colon;
    	do{
     	colon = attribute.indexOf(":");
     	if(colon!=-1){
     		attribute = attribute.substring(0, colon)+"_"+attribute.substring(colon+1);
     	}
    	}while(colon!=-1);
    	passLineString=passLineString+","+attribute+":String";
    }
    
	lineType = DataUtilities.createType("Location", passLineString);
    
    lineCollection = FeatureCollections.newCollection();
    
    lineBuilder = new SimpleFeatureBuilder(lineType);
    
    lineFeature = lineBuilder.buildFeature(null);
    
    ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
    
    Map <String,Serializable> parameters = new HashMap<String, Serializable>();
    
    parameters.put("url",shpLineFile.toURI().toURL());
    parameters.put("create spatial index",Boolean.TRUE);
    
    ShapefileDataStore newdatastore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(parameters);
    newdatastore.createSchema(lineType);
    
    newdatastore.forceSchemaCRS(DefaultGeographicCRS.WGS84);  
    
    String typename = newdatastore.getTypeNames()[0];
    
    SimpleFeatureSource simpfeatsource = newdatastore.getFeatureSource(typename);
    
    lineFeatureStore = (SimpleFeatureStore)simpfeatsource;
}
 
开发者ID:banmedo,项目名称:Converter,代码行数:41,代码来源:shpMain.java

示例7: writeShapeFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
/**
 * Write a feature collection to a shape(.shp) file using the
 * standard GeoTools way of creating shape files. This function will
 * write the shape file using the Coordinate system WGS84.
 *
 * @param SimpleFeatureCollection collection The collection of features you wish to write to the shape file.
 * @param SimpleFeatureType TYPE The type object of the feature you wish to use.
 */
private static void writeShapeFile(SimpleFeatureCollection collection, SimpleFeatureType TYPE) throws IOException{

	//Prompt the user for a save location and filename.
	File newFile = getNewShapeFile();

	//Set up data store factory.
       ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

       //Set up maps and parameters.
       Map<String, Serializable> params = new HashMap<String, Serializable>();
       params.put("url", newFile.toURI().toURL());
       params.put("create spatial index", Boolean.TRUE);

       //Set up data store.
       ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
       dataStore.createSchema(TYPE);

       //Set CRS.
       dataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
	
       //Create transaction.
       Transaction transaction = new DefaultTransaction("create");

       //Set up type name and feature source.
       String typeName = dataStore.getTypeNames()[0];
       SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);

       if(featureSource instanceof SimpleFeatureStore) {
           
       	//Set up feature store and attempt the transaction.
       	SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
           featureStore.setTransaction(transaction);
           try{
               featureStore.addFeatures(collection);
               transaction.commit();
           }catch (Exception e) {
               e.printStackTrace();
               transaction.rollback();
           }finally{
               transaction.close();
           }
       
       //If the type does not support read/write access.
       }else{
           System.out.println(typeName + " does not support read/write access");
       }
	
}
 
开发者ID:Stefangemfind,项目名称:MapMatching,代码行数:57,代码来源:App.java

示例8: buildBlocks

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void buildBlocks(File shapeFile) throws IOException, FactoryException {
	ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
	
	SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName("Block");
    builder.setCRS(DefaultGeographicCRS.WGS84); 

    // add attributes in order
    builder.add("Block", Polygon.class);
    builder.length(16).add("id", String.class); 
    for(String attribute : attributes.attributeGroups.keySet()) {
    	builder.add(attribute, Long.class); 
    }

    Map<String, Serializable> params = new HashMap<String, Serializable>();
	params.put("url", shapeFile.toURI().toURL());
	params.put("create spatial index", Boolean.TRUE);
	
	ShapefileDataStore dataStore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
	dataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    
    // build the type
    final SimpleFeatureType BLOCKS_TYPE = builder.buildFeatureType();
    
    dataStore.createSchema(BLOCKS_TYPE);
    
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(BLOCKS_TYPE);
    
    for(String blockId : blocks.lodesBlocks.keySet()) {
    	if(blocks.lodesBlocks.get(blockId).percentLand < 0.5)
    		continue;
    	
    	featureBuilder.add(blocks.lodesBlocks.get(blockId).geom);
    	
    	featureBuilder.add(blockId);
    	
    	for(String attributeId : attributes.attributeGroups.keySet()) {
    		
    		HashMap<String, Long> lodesAttribute = attributes.lodesAttributes.get(blockId);
    		if(lodesAttribute != null) {
    			Long attributeValue = lodesAttribute.get(attributeId);
    			featureBuilder.add(attributeValue);
    		}
    		else {
    			//System.out.println("blockId: " + blockId + " is missing " + attributeId);
    		}
    	}
    	
        SimpleFeature feature = featureBuilder.buildFeature(null);
        featureCollection.add(feature);
        
    }
    
    Transaction transaction = new DefaultTransaction("create");

    String typeName = dataStore.getTypeNames()[0];
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);

    if (featureSource instanceof SimpleFeatureStore) 
    {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

        featureStore.setTransaction(transaction);
       
        featureStore.addFeatures(featureCollection);
        transaction.commit();

        transaction.close();
    } 
}
 
开发者ID:conveyal,项目名称:lodes-processor,代码行数:73,代码来源:LodesProcessor.java

示例9: buildHaltonPopulation

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void buildHaltonPopulation(File shapeFile) throws IOException, FactoryException {
	ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
	
	SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName("Block");
    builder.setCRS(DefaultGeographicCRS.WGS84); 

    // add attributes in order
    builder.add("Jobs", MultiPoint.class);
    builder.length(16).add("id", String.class); 
    builder.length(5).add("type", String.class);

    Map<String, Serializable> params = new HashMap<String, Serializable>();
	params.put("url", shapeFile.toURI().toURL());
	params.put("create spatial index", Boolean.TRUE);
	
	ShapefileDataStore dataStore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
	dataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
    
    // build the type
    final SimpleFeatureType BLOCKS_TYPE = builder.buildFeatureType();
    
    dataStore.createSchema(BLOCKS_TYPE);
    
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(BLOCKS_TYPE);
    
    for(String blockId : blocks.lodesBlocks.keySet()) {
    	
    	IndicatorItem block = blocks.lodesBlocks.get(blockId);
    	   	
    	
    	for(String attributeId : attributes.attributeGroups.keySet()) {
    		
    		HashMap<String, Long> lodesAttribute = attributes.lodesAttributes.get(blockId);
    		if(lodesAttribute != null) {
        		long attributeValue = lodesAttribute.get(attributeId);
        		
        		if (attributeValue < Integer.MIN_VALUE || attributeValue > Integer.MAX_VALUE) {
        	        System.out.println(blockId + " " + attributeId + " exceeds int val max: " + attributeValue);
        	    } 
        		else {
        			featureBuilder.add(block.haltonPoints((int)attributeValue));
            		featureBuilder.add(blockId);
            		featureBuilder.add(attributeId);
            		
            		SimpleFeature feature = featureBuilder.buildFeature(null);
                    featureCollection.add(feature);
        		}
    		}
    		else {
    			//System.out.println("blockId: " + blockId + " is missing " + attributeId);
    		}
    	}   
    }
    
    Transaction transaction = new DefaultTransaction("create");

    String typeName = dataStore.getTypeNames()[0];
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);

    if (featureSource instanceof SimpleFeatureStore) 
    {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

        featureStore.setTransaction(transaction);
       
        featureStore.addFeatures(featureCollection);
        transaction.commit();

        transaction.close();
    } 
}
 
开发者ID:conveyal,项目名称:lodes-processor,代码行数:75,代码来源:LodesProcessor.java

示例10: writeToShapefile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private static void writeToShapefile(String output_fn,
		HashMap<Feature, Double> dissMags) throws MalformedURLException,
		IOException {
	System.out.println( "printing to shapefile..." );
	ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
	
	Map<String, Serializable> params = new HashMap<String, Serializable>();
	params.put("url", new File(output_fn).toURI().toURL());
	params.put("create spatial index", Boolean.TRUE);
	
	ShapefileDataStore outputStore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
	outputStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
	
	// build the type
	SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
	builder.setName("diss");
	builder.setCRS(DefaultGeographicCRS.WGS84); 
	builder.add("the_geom", MultiPolygon.class);
	builder.length(16).add("mag", Float.class); 
	
	final SimpleFeatureType dissType = builder.buildFeatureType();
	outputStore.createSchema(dissType);
	
	DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
	SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dissType);
	
	int j=0;
	for(Entry<Feature, Double> entry : dissMags.entrySet()) {
		if(j%1000==0){
			System.out.println("writing feature "+j);
		}
		
		Feature diss = entry.getKey();
		Geometry dissGeom = (Geometry)diss.getDefaultGeometryProperty().getValue();
		double mag = entry.getValue();

		featureBuilder.add(dissGeom);
		featureBuilder.add(mag);
	
	    SimpleFeature feature = featureBuilder.buildFeature(null);
	    featureCollection.add(feature);
	    
	    j++;
	}
	
	Transaction transaction = new DefaultTransaction("create");
	String outputTypeName = outputStore.getTypeNames()[0];
	SimpleFeatureSource featureSource = outputStore.getFeatureSource(outputTypeName);
	if (featureSource instanceof SimpleFeatureStore) 
	{
		System.out.println("committing");
	    SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

	    featureStore.setTransaction(transaction);
	   
	    featureStore.addFeatures(featureCollection);
	    transaction.commit();

	    transaction.close();
	}
}
 
开发者ID:conveyal,项目名称:aggregate-disser,代码行数:62,代码来源:Disser.java

示例11: getFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private File getFile(
        final SimpleFeatureType featureType,
        final DefaultFeatureCollection collection) throws IOException
{
    final ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

    final File file = File.createTempFile("shapefile-", ".shp");
    file.deleteOnExit();

    final Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());

    final ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
    try
    {
        dataStore.createSchema(featureType);

        final String typeName = dataStore.getTypeNames()[0];
        final SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        if (featureSource instanceof SimpleFeatureStore)
        {
            SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
            final Transaction transaction = new DefaultTransaction("create");
            try
            {
                featureStore.setTransaction(transaction);
                featureStore.addFeatures(collection);
                transaction.commit();
            }
            catch (Exception e)
            {
                transaction.rollback();
            }
            finally
            {
                transaction.close();
            }
        }
    }
    finally
    {
        dataStore.dispose();
    }
    return file;
}
 
开发者ID:mraad,项目名称:GeoEnrichment,代码行数:46,代码来源:SearchShapefileTesting.java

示例12: createShapeFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private File createShapeFile(FeatureCollection<SimpleFeatureType, SimpleFeature> collection) throws IOException {

		String shapeFileSuffix = ".shp";

		File tempBaseFile = File.createTempFile("resolveDir", ".tmp");
		tempBaseFile.deleteOnExit();
		File parent = tempBaseFile.getParentFile();

		File shpBaseDirectory = new File(parent, UUID.randomUUID().toString());

		if (!shpBaseDirectory.mkdir()) {
			throw new IllegalStateException("Could not create temporary shp directory.");
		}

		File tempSHPfile = File.createTempFile("shp", shapeFileSuffix, shpBaseDirectory);
		tempSHPfile.deleteOnExit();
		DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
		Map<String, Serializable> params = new HashMap<String, Serializable>();
		params.put("url", tempSHPfile.toURI().toURL());
		params.put("create spatial index", Boolean.TRUE);

		ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory
				.createNewDataStore(params);

		newDataStore.createSchema(collection.getSchema());
		if(collection.getSchema().getCoordinateReferenceSystem()==null){
			newDataStore.forceSchemaCRS(getCRS_WGS84());
		}else{
			newDataStore.forceSchemaCRS(collection.getSchema()
				.getCoordinateReferenceSystem());
		}

		Transaction transaction = new DefaultTransaction("create");

		String typeName = newDataStore.getTypeNames()[0];
		@SuppressWarnings("unchecked")
		FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) newDataStore
				.getFeatureSource(typeName);
		featureStore.setTransaction(transaction);
		try {
			featureStore.addFeatures(collection);
			transaction.commit();
		} catch (Exception problem) {
			transaction.rollback();
		} finally {
			transaction.close();
		}

		// Get names of additional files
		String path = tempSHPfile.getAbsolutePath();
		String baseName = path.substring(0, path.length() - shapeFileSuffix.length());
		File shx = new File(baseName + ".shx");
		File dbf = new File(baseName + ".dbf");
		File prj = new File(baseName + ".prj");

		// mark created files for delete
		tempSHPfile.deleteOnExit();
		shx.deleteOnExit();
		dbf.deleteOnExit();
		prj.deleteOnExit();
		shpBaseDirectory.deleteOnExit();

		return shpBaseDirectory;
	}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:65,代码来源:TrackShapefileEncoder.java

示例13: preparePolygonFIle

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void preparePolygonFIle(ArrayList <osmLine> osmPolygons) throws SchemaException, IOException {
	uniquePolygonTagKeys = getUniqueTagKeys(osmPolygons,"polygons");
    Collections.sort(uniquePolygonTagKeys);
    String passPolygonString = new String("location:Polygon:srid=4326,"+"id:Double");
    for(String attribute:uniquePolygonTagKeys){
    	int colon;
    	do{
     	colon = attribute.indexOf(":");
     	if(colon!=-1){
     		attribute = attribute.substring(0, colon)+"_"+attribute.substring(colon+1);
     	}
    	}while(colon!=-1);
    	passPolygonString=passPolygonString+","+attribute+":String";
    }

    pointType = DataUtilities.createType("Location", passPolygonString);
    
    polygonCollection = FeatureCollections.newCollection();
    
    polygonBuilder = new SimpleFeatureBuilder(pointType);
    
    polygonFeature = polygonBuilder.buildFeature(null);
    
    ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
    
    Map <String,Serializable> parameters = new HashMap<String, Serializable>();
    
    parameters.put("url",shpPolygonFile.toURI().toURL());
    parameters.put("create spatial index",Boolean.TRUE);
    
    ShapefileDataStore newdatastore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(parameters);
    newdatastore.createSchema(pointType);
    
    newdatastore.forceSchemaCRS(DefaultGeographicCRS.WGS84);  
    
    String typename = newdatastore.getTypeNames()[0];
    
    SimpleFeatureSource simpfeatsource = newdatastore.getFeatureSource(typename);
    
    polygonFeatureStore = (SimpleFeatureStore)simpfeatsource;
}
 
开发者ID:banmedo,项目名称:Converter,代码行数:42,代码来源:shpMain.java


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