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


Java SimpleFeatureSource类代码示例

本文整理汇总了Java中org.geotools.data.simple.SimpleFeatureSource的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeatureSource类的具体用法?Java SimpleFeatureSource怎么用?Java SimpleFeatureSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: exportUAZ

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Export uaz.
 * 
 * @param project
 *          the project
 * @param userId
 *          the user id
 * @return the string
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 * @throws DataStoreCreationException
 *           the data store creation exception
 * @throws MiddlewarePersistentException
 */
public String exportUAZ(final WifProject project, final String userId)
    throws IOException, DataStoreCreationException,
    MiddlewarePersistentException {
  LOGGER.info("Entering exportUAZ/share in my aurin");
  LOGGER.info("using the following server: {} for database/schema: {}",
      postgisDataStoreConfig.getDataStoreParams().get(HOST.key),
      postgisDataStoreConfig.getDataStoreParams().get(DATABASE.key) + "/"
          + postgisDataStoreConfig.getDataStoreParams().get(SCHEMA.key));
  final String tableName = project.getSuitabilityConfig()
      .getUnifiedAreaZone();
  final DataStore dataStore = DataStoreFinder
      .getDataStore(postgisDataStoreConfig.getDataStoreParams());
  final SimpleFeatureSource featureSource = dataStore
      .getFeatureSource(tableName);
  final SimpleFeatureCollection features = featureSource.getFeatures();

  final String result = shareUAZSnapshot(features, userId, project);
  LOGGER
      .info("exporting finished, information sent to AURIN/middleware persistence!");
  return result;
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:36,代码来源:PostgisToDataStoreExporter.java

示例2: getWifUAZfromShpFile

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Gets the wif ua zfrom shp file.
 *
 * @param uAZShpURL
 *          the u az shp url
 * @return the wif ua zfrom shp file
 */
public SimpleFeatureCollection getWifUAZfromShpFile(final URL uAZShpURL) {

  LOGGER.info("uAZShpURL FilePath: {} ", uAZShpURL.getFile());
  SimpleFeatureCollection uazFeatureCollection = FeatureCollections
      .newCollection();
  FileDataStore storeUD;
  try {
    storeUD = openFileDataStore(uAZShpURL.getFile());
    final SimpleFeatureSource featureSourceUD = storeUD.getFeatureSource();
    uazFeatureCollection = featureSourceUD.getFeatures();
    LOGGER.debug("featureCollection size : {} ", uazFeatureCollection.size());
  } catch (final IOException e) {
    LOGGER.error("getWifUAZfromShpFile ", e.getMessage());
  }

  return uazFeatureCollection;
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:25,代码来源:GeodataFinder.java

示例3: getWifUAZfromDB

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Gets the wif ua zfrom db.
 *
 * @param uazTbl
 *          the uaz tbl
 * @return the wif ua zfrom db
 */
public SimpleFeatureCollection getWifUAZfromDB(final String uazTbl) {

  LOGGER.info("getWifUAZfromDB for table : {}", uazTbl);
  SimpleFeatureCollection uazFeatureCollection = FeatureCollections
      .newCollection();
  DataStore wifDataStore;

  try {
    wifDataStore = openPostgisDataStore();
    final SimpleFeatureSource featureSourceUD = wifDataStore
        .getFeatureSource(uazTbl);
    uazFeatureCollection = featureSourceUD.getFeatures();
    LOGGER.info("UAZ featureCollection size : {} ",
        uazFeatureCollection.size());
  } catch (final IOException e) {
    LOGGER.error("could not access table {} ", uazTbl);
  }

  return uazFeatureCollection;
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:28,代码来源:GeodataFinder.java

示例4: updateUAZArea

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Update uaz area.
 *
 * @param uazTbl
 *          the uaz tbl
 */
public void updateUAZArea(final String uazTbl) {

  LOGGER.info("updateUAZArea for table : {}", uazTbl);

  DataStore wifDataStore;
  try {
    wifDataStore = openPostgisDataStore();
    final SimpleFeatureSource featureSourceUD = wifDataStore
        .getFeatureSource(uazTbl);
    final SimpleFeatureType schema = featureSourceUD.getSchema();
    final String geomColumnName = schema.getGeometryDescriptor()
        .getLocalName();

    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    final String queryTxt = "UPDATE "
        + postgisDataStoreConfig.getDataStoreParams().get(SCHEMA.key) + "."
        + uazTbl + " SET \"" + WifKeys.DEFAULT_AREA_COLUMN_NAME + "\" = "
        + " (ST_Area( " + geomColumnName + " )) ";
    LOGGER.debug("updateUAZArea: {}", queryTxt);
    jdbcTemplate.execute(queryTxt);
  } catch (final IOException e) {
    LOGGER.error("could not access table {} ", uazTbl);
  }
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:31,代码来源:GeodataFinder.java

示例5: getFeatureSourcefromDB

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Gets the feature sourcefrom db.
 *
 * @param uazTbl
 *          the uaz tbl
 * @return the feature sourcefrom db
 * @throws WifInvalidInputException
 *           the wif invalid input exception
 */
public SimpleFeatureSource getFeatureSourcefromDB(final String uazTbl)
    throws WifInvalidInputException {

  LOGGER.info("getFeatureSourcefromDB for table : {}", uazTbl);
  DataStore wifDataStore;
  SimpleFeatureSource featureSourceUD;
  try {
    wifDataStore = openPostgisDataStore();
    featureSourceUD = wifDataStore.getFeatureSource(uazTbl);

    LOGGER.info("UAZ featureSource Name: {} ", featureSourceUD.getName());
    return featureSourceUD;
  }

  catch (final IOException e) {
    LOGGER.error("could not access table {} ", uazTbl);
    throw new WifInvalidInputException("could not access table" + uazTbl);
  }
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:29,代码来源:GeodataFinder.java

示例6: getFeatureStorefromDB

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Gets the feature storefrom db.
 *
 * @param uazTbl
 *          the uaz tbl
 * @return the feature storefrom db
 * @throws WifInvalidInputException
 *           the wif invalid input exception
 */
public SimpleFeatureStore getFeatureStorefromDB(final String uazTbl)
    throws WifInvalidInputException {

  LOGGER.info("getFeatureStorefromDB for table : {}", uazTbl);

  SimpleFeatureSource featureSourceUD;

  featureSourceUD = getFeatureSourcefromDB(uazTbl);

  if (featureSourceUD instanceof SimpleFeatureStore) {

    LOGGER.info("UAZ featureSource Name: {} ", featureSourceUD.getName());
    return (SimpleFeatureStore) featureSourceUD;
  } else {
    throw new WifInvalidInputException(
        "table doesn't have write priviledges " + uazTbl);
  }
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:28,代码来源:GeodataFinder.java

示例7: zipFileToPostGIS

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Zip file to post gis.
 * 
 * @param shpFile
 *          the shp file
 * @return the simple feature collection
 * @throws ShapeFile2PostGISCreationException
 *           the shape file2 post gis creation exception
 */
public SimpleFeatureCollection zipFileToPostGIS(final File shpFile)
    throws ShapeFile2PostGISCreationException {
  final String msg = "Converting shape file operation failed...";

  try {

    final FileDataStore store = FileDataStoreFinder.getDataStore(shpFile);
    final SimpleFeatureSource featureSource = store.getFeatureSource();
    final SimpleFeatureCollection features = featureSource.getFeatures();
    LOGGER.info("Shape filename = {}", featureSource.getSchema()
        .getTypeName());
    final CoordinateReferenceSystem crs = featureSource.getSchema()
        .getCoordinateReferenceSystem();
    validatorCRS.validateSimple(crs, msg);
    return features;
  } catch (final Exception e) {
    LOGGER.error(msg, e.getMessage());
    throw new ShapeFile2PostGISCreationException(msg, e);
  }
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:30,代码来源:FileToPostgisExporter.java

示例8: run

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
@Override
public void run() {
	final Display display = WorkbenchHelper.getDisplay();
	final Shell shell = new Shell(display);
	final File openFile = JFileDataStoreChooser.showOpenFile(new String[] { "*.shp" }, shell); //$NON-NLS-1$

	try {
		if (openFile != null && openFile.exists()) {
			final MapContent mapContent = mapPane.getMapContent();
			final FileDataStore store = FileDataStoreFinder.getDataStore(openFile);
			final SimpleFeatureSource featureSource = store.getFeatureSource();
			final Style style = Utils.createStyle(openFile, featureSource);
			final FeatureLayer featureLayer = new FeatureLayer(featureSource, style);
			mapContent.addLayer(featureLayer);
			mapPane.redraw();
		}
	} catch (final IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:21,代码来源:OpenShapefileAction.java

示例9: OSMInfo

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
public OSMInfo(final URL url, final long modificationStamp) {
	super(modificationStamp);
	CoordinateReferenceSystem crs = null;
	ReferencedEnvelope env2 = new ReferencedEnvelope();

	int number = 0;
	try {
		final File f = new File(url.toURI());
		final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath());
		attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope()));

		final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString");
		final ArrayList<SimpleFeature> list = new ArrayList<SimpleFeature>();
		for (final IShape shape : osmfile.iterable(null)) {
			list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null));
		}
		final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list);
		final SimpleFeatureSource featureSource = DataUtilities.source(collection);

		env2 = featureSource.getBounds();
		number = osmfile.nbObjects;
		crs = osmfile.getOwnCRS(null);
	} catch (final Exception e) {
		System.out.println("Error in reading metadata of " + url);
		hasFailed = true;

	} finally {

		// approximation of the width and height in meters.
		width = env2 != null ? env2.getWidth() * (FastMath.PI / 180) * 6378137 : 0;
		height = env2 != null ? env2.getHeight() * (FastMath.PI / 180) * 6378137 : 0;
		itemNumber = number;
		this.crs = crs;
	}

}
 
开发者ID:gama-platform,项目名称:gama,代码行数:37,代码来源:GamaOsmFile.java

示例10: simpleTest

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
@Test
public void simpleTest() throws WorkflowException, IOException {
	chain.execute(ctx);
	assertTrue(ctx.getStatusElements().containsKey(WRITER_ID));
	
	assertEquals(WorkflowStatus.Status.COMPLETED, 
			ctx.getStatusElements().get(WRITER_ID).getCurrentStatus());
	
	SimpleFeatureSource featureSource = store.getFeatureSource(TestUtils.SAMPLE_FEATURE_NAME);
	FeatureCollection fc = featureSource.getFeatures();
	assertEquals(1, fc.size());
	SimpleFeature readFeature = (SimpleFeature) fc.features().next();
	assertEquals(TestUtils.SAMPLE_FEATURE_NAME, readFeature.getName().getLocalPart());
	assertEquals("value0", readFeature.getAttribute("prop0"));
	assertEquals(100.0, readFeature.getAttribute("prop1"));
	assertTrue(readFeature.getAttribute("geometry") instanceof Point);
}
 
开发者ID:geosolutions-it,项目名称:OpenSDI-Manager2,代码行数:18,代码来源:ChainTest.java

示例11: stripFeatureIDTest

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * Test a chain of Actions to:
 * 
 * - Read a GeoJSON
 * - Manipulate the FeatureID stripping out the prefix, leaving only the ID
 * - Store the modified Feature
 * 
 * @throws WorkflowException
 * @throws IOException
 */
@Test
public void stripFeatureIDTest() throws WorkflowException, IOException {
	sequence_wo_email.execute(ctx);
	assertTrue(ctx.getStatusElements().containsKey(WRITER_ID));
	
	assertEquals(WorkflowStatus.Status.COMPLETED, 
			ctx.getStatusElements().get(WRITER_ID).getCurrentStatus());
	
	SimpleFeatureSource featureSource = store.getFeatureSource(TestUtils.SAMPLE_FEATURE_NAME);
	FeatureCollection fc = featureSource.getFeatures();
	assertEquals(1, fc.size());
	SimpleFeature readFeature = (SimpleFeature) fc.features().next();
	assertEquals(TestUtils.SAMPLE_FEATURE_NAME, readFeature.getName().getLocalPart());
	
	assertEquals("noto ", readFeature.getAttribute("RESPONSABILE_ABBANDONO"));
	assertEquals("08/ott/2014", readFeature.getAttribute("DATA_AGG"));
	assertEquals("42", readFeature.getAttribute("CIVICO"));
	// the feature ID cannot be specified before the insert into the featureStore
	// the feature ID is ignored and another one is created
	//assertEquals("46", readFeature.getID());
	assertTrue(readFeature.getAttribute("geometry") instanceof Point);
}
 
开发者ID:geosolutions-it,项目名称:OpenSDI-Manager2,代码行数:33,代码来源:FeatureIDChangeChainTest.java

示例12: createCoastlineLayer

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
private static Layer createCoastlineLayer() {
    try {
        // File file = new File(
        // "/home/dxm/Downloads/shapefile-australia-coastline-polygon/cstauscd_r.shp");
        File file = new File("src/main/resources/shapes/countries.shp");
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        // Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Style style = SLD.createPolygonStyle(Color.black, new Color(242, 237, 206), 1);
        Layer layer = new FeatureLayer(featureSource, style);
        return layer;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:amsa-code,项目名称:risky,代码行数:17,代码来源:Map.java

示例13: readFeatureCollection

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
@Execute
public void readFeatureCollection() throws IOException {
    if (!concatOr(geodata == null, doReset)) {
        return;
    }

    try {
        File shapeFile = new File(file);
        pm.beginTask("Reading features from shapefile: " + shapeFile.getName(), -1);
        FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
        SimpleFeatureSource featureSource = store.getFeatureSource();
        geodata = featureSource.getFeatures();
        store.dispose();
    } finally {
        pm.done();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:18,代码来源:OmsShapefileFeatureReader.java

示例14: writeShapefile

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的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

示例15: main

import org.geotools.data.simple.SimpleFeatureSource; //导入依赖的package包/类
/**
 * This method demonstrates using a memory-based cache to speed up the display (e.g. when
 * zooming in and out).
 * 
 * There is just one line extra compared to the main method, where we create an instance of
 * CachingFeatureStore.
 */
public static void main(String[] args) throws Exception {
    // display a data store file chooser dialog for shapefiles
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
    if (file == null) {
        return;
    }

    FileDataStore store = FileDataStoreFinder.getDataStore(file);
    SimpleFeatureSource featureSource = store.getFeatureSource();

    CachingFeatureSource cache = new CachingFeatureSource(featureSource);

    // Create a map content and add our shapefile to it
    MapContent map = new MapContent();
    map.setTitle("Using cached features");
    Style style = SLD.createSimpleStyle(featureSource.getSchema());
    Layer layer = new FeatureLayer(cache, style);
    map.addLayer(layer);

    // Now display the map
    JMapFrame.showMap(map);
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:30,代码来源:QuickstartCache.java


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