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


Java ShapefileDataStore.getFeatureSource方法代码示例

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


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

示例1: open

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void open() throws KettleException{
	try {			
		// try closing first
		close();
		 			
	// TODO: Don't use a memory-mapped file reader (3rd arg) because this
		// causes out of memory errors with large files (~500mb).
		
		gtDataStore = new ShapefileDataStore(gisURL, null, false, Charset.forName(Const.isEmpty(this.charset)?"ISO-8859-1":this.charset));
	featSrc = gtDataStore.getFeatureSource(gtDataStore.getTypeNames()[0]);
	featColl = featSrc.getFeatures();
          featIter = featColl.features(); 
}catch(Exception e) {
	throw new KettleException("Error opening GIS file at URL: "+gisURL, e);
}
  }
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:17,代码来源:GeotoolsReader.java

示例2: makeLineLayer

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private void makeLineLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", LineString.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例3: writeShapefile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private void writeShapefile(MemoryDataStore memoryDataStore, File outputFile) throws Exception {

		SimpleFeatureSource featureSource = memoryDataStore.getFeatureSource(memoryDataStore.getTypeNames()[0]);
		SimpleFeatureType featureType = featureSource.getSchema();

		Map<String, java.io.Serializable> creationParams = new HashMap<String, java.io.Serializable>();
		creationParams.put("url", DataUtilities.fileToURL(outputFile));

		ShapefileDataStoreFactory factory = (ShapefileDataStoreFactory) FileDataStoreFinder.getDataStoreFactory("shp");
		ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(creationParams);
		dataStore.setCharset(Charset.forName("UTF-8"));
		dataStore.createSchema(featureType);

		SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

		Transaction transaction = new DefaultTransaction();
		try {
			SimpleFeatureCollection collection = featureSource.getFeatures();
			featureStore.addFeatures(collection);
			transaction.commit();
		} catch (IOException e) {
			try {
				transaction.rollback();
				throw new Exception("Failed to commit data to feature store", e);
			} catch (IOException e2 ) {
				logger.error("Failed to commit data to feature store", e);
				throw new Exception("Transaction rollback failed", e2);
			}
		} finally {
			transaction.close();
		}
	}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:33,代码来源:ShapefileCreator.java

示例4: ShapefileIterator

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public ShapefileIterator(File file, boolean forceUTF8) {
    try {
        this.forceUTF8 = forceUTF8;
        datastore = new ShapefileDataStore(file.toURI().toURL());
        FeatureSource<SimpleFeatureType, SimpleFeature> source = datastore
                .getFeatureSource(datastore.getTypeNames()[0]);
        FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(INCLUDE);
        features = collection.features();
    }
    catch (IOException e) {
        throw propagate(e);
    }
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:14,代码来源:ShapefileIterator.java

示例5: 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

示例6: openInputShapefile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
/**
 * Open the input shape file and load it into memory.
 */
public void openInputShapefile(String inputShapefile) throws IOException {
  File file = new File(inputShapefile);

  ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
  Map<String, Serializable> params = new HashMap<>();
  params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
  params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
  params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX.key, Boolean.TRUE);
  params.put(ShapefileDataStoreFactory.MEMORY_MAPPED.key, Boolean.TRUE);
  params.put(ShapefileDataStoreFactory.CACHE_MEMORY_MAPS.key, Boolean.TRUE);

  ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
  featureSource = store.getFeatureSource();
  // determine the correct case of the tz attribute because its case has been
  // changed from efele to evansiroky
  SimpleFeatureType schema = featureSource.getSchema();
  List<AttributeDescriptor> attributeDescriptorList = schema.getAttributeDescriptors();
  for (AttributeDescriptor attributeDescriptor : attributeDescriptorList) {
    if ("tzid".equalsIgnoreCase(attributeDescriptor.getLocalName())) {
      tzidAttr = attributeDescriptor.getLocalName();
    }
  }

  filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
  geometryFactory = JTSFactoryFinder.getGeometryFactory();
}
 
开发者ID:skaringa,项目名称:tzdataservice,代码行数:30,代码来源:TzDataShpFileReadAndLocate.java

示例7: init

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
	setSite(site);
	final FileEditorInput fi = (FileEditorInput) input;
	file = fi.getFile();
	final IPath path = fi.getPath();
	final File f = path.makeAbsolute().toFile();
	try {
		pathStr = f.getAbsolutePath();
		final ShapefileDataStore store = new ShapefileDataStore(f.toURI().toURL());
		content = new MapContent();
		featureSource = store.getFeatureSource();
		style = Utils.createStyle(f, featureSource);
		layer = new FeatureLayer(featureSource, style);
		mode = determineMode(featureSource.getSchema(), "Polygon");
		final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
		if (ftsList.size() > 0) {
			fts = ftsList.get(0);
		} else {
			fts = null;
		}
		if (fts != null) {
			this.setFillColor(PreferencesHelper.SHAPEFILE_VIEWER_FILL.getValue(), mode, fts);
			this.setStrokeColor(PreferencesHelper.SHAPEFILE_VIEWER_LINE_COLOR.getValue(), mode, fts);
			((StyleLayer) layer).setStyle(style);
		}
		content.addLayer(layer);
	} catch (final IOException e) {
		System.out.println("Unable to view file " + path);
	}
	this.setPartName(path.lastSegment());
	setInput(input);
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:34,代码来源:ShapeFileViewer.java

示例8: 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

示例9: 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

示例10: collectionToShapeFile

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
/**
 * <p>
 * The easy way to create a shapefile from attributes and geometries
 * </p>
 * <p>
 * <b>NOTE: this doesn't support date attributes</b>
 * </p>
 * 
 * @param shapeFilePath the shapefile name
 * @param crs the destination crs
 * @param fet the featurecollection
 * @throws IOException 
 */
public static boolean collectionToShapeFile( String shapeFilePath, CoordinateReferenceSystem crs,
        SimpleFeatureCollection fet ) throws IOException {

    // Create the file you want to write to
    File file = null;
    if (shapeFilePath.toLowerCase().endsWith(".shp")) { //$NON-NLS-1$
        file = new File(shapeFilePath);
    } else {
        file = new File(shapeFilePath + ".shp"); //$NON-NLS-1$
    }

    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();

    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);

    newDataStore.createSchema(fet.getSchema());
    if (crs != null)
        newDataStore.forceSchemaCRS(crs);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(fet);
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
    return true;
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:48,代码来源:FeatureUtilities.java

示例11: makePointLayer

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private void makePointLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", Point.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例12: 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

示例13: assignStateNameToEarthquakes

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
private static void assignStateNameToEarthquakes(Earthquakes quakes) throws MalformedURLException, IOException, CQLException {
    long recordCount = 0L;
    File shapeFile = new File(statesShapePath);
    if (shapeFile.exists()) {
        SimpleFeature simpleFeature;
        Geometry geometry;
        Point point;
        ShapefileDataStore dataStore = new ShapefileDataStore(shapeFile.toURI().toURL());
        SimpleFeatureSource featureSource = dataStore.getFeatureSource();
        SimpleFeatureCollection featureCollection;
        Filter filter = CQL.toFilter("STATE='" + stateNameFilter + "'");
        if (!stateNameFilter.equals("")) {
            featureCollection = featureSource.getFeatures(filter);
        }
        else {
            featureCollection = featureSource.getFeatures();
        }
        SimpleFeatureIterator featureIterator = featureCollection.features();
        try {
            while (featureIterator.hasNext()) {
                simpleFeature = featureIterator.next();
                geometry = (Geometry)simpleFeature.getDefaultGeometry();
                for (Earthquake earthquake : quakes) {
                    point = geometryFactory.createPoint(new Coordinate(earthquake.getDblLongitude(), earthquake.getDblLatitude())); 
                    if (geometry.contains(point)) {
                        recordCount++;
                        earthquake.setStateName(simpleFeature.getProperty("STATE").getValue().toString());
                        //System.out.println(earthquake.getUniqueId() + "," + earthquake.getStateName());
                        if (recordCount % 1000 == 0) {
                            System.out.println("StateName: " + recordCount);
                        }
                    }
                }
            }
        } finally {
            featureIterator.close();
        }
    }
}
 
开发者ID:FrackingAnalysis,项目名称:AnssGeoCoder,代码行数:40,代码来源:AnssGeoCoder.java

示例14: write

import org.geotools.data.shapefile.ShapefileDataStore; //导入方法依赖的package包/类
public void write(SimpleFeatureCollection obj, OutputStream output, SimpleFeatureType sft,
		String layerId) throws IOException {
	File shpFile = File.createTempFile("shpFile", ".shp");

	ShapefileDataStoreFactory fact = new ShapefileDataStoreFactory();

	Map<String, Serializable> params = new HashMap<String, Serializable>();
	params.put(ShapefileDataStoreFactory.URLP.key, shpFile.toURI().toURL());
	params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);

	ShapefileDataStore shpDataStore = (ShapefileDataStore) fact.createNewDataStore(params);

	shpDataStore.createSchema(sft);

	SimpleFeatureStore store = (SimpleFeatureStore) shpDataStore.getFeatureSource(shpDataStore.getTypeNames()[0]);

	Transaction transaction = new DefaultTransaction("create");
	store.setTransaction(transaction);
	store.addFeatures(obj);
	transaction.commit();

	ZipOutputStream os = new ZipOutputStream(output);

	final String fileName = shpFile.getName().substring(0, shpFile.getName().lastIndexOf("."));
	File[] shpFiles = new File(shpFile.getParent()).listFiles(new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.contains(fileName);
		}
	});

	for (File file : shpFiles) {
		os.putNextEntry(new ZipEntry(layerId + file.getName().substring(file.getName().lastIndexOf("."))));
		IOUtils.copy(new FileInputStream(file), os);
		file.delete();
	}
	os.close();
	output.flush();
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:40,代码来源:ShpParser.java

示例15: 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


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