當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleFeatureSource.getSchema方法代碼示例

本文整理匯總了Java中org.geotools.data.simple.SimpleFeatureSource.getSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFeatureSource.getSchema方法的具體用法?Java SimpleFeatureSource.getSchema怎麽用?Java SimpleFeatureSource.getSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.geotools.data.simple.SimpleFeatureSource的用法示例。


在下文中一共展示了SimpleFeatureSource.getSchema方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

示例3: TwoAttributes

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
public TwoAttributes(String[] args) throws IOException {
	File file = new File(args[0]);
	FileDataStore store = FileDataStoreFinder.getDataStore(file);
	SimpleFeatureSource featureSource = store.getFeatureSource();
	SimpleFeatureType schema = featureSource.getSchema();
	System.out.println(schema);
	// Create a map content and add our shapefile to it
	MapContent mapContent = new MapContent();
	mapContent.setTitle("GeoTools Mapping");
	Style style = SLD.createSimpleStyle(featureSource.getSchema());
	Layer layer = new FeatureLayer(featureSource, style);
	mapContent.addLayer(layer);
	frame = new JMapFrame(mapContent);
	frame.enableStatusBar(true);
	frame.enableToolBar(true);
	JToolBar toolBar = frame.getToolBar();
	toolBar.addSeparator();
	SaveAction save = new SaveAction("Save");
	toolBar.add(save);
	frame.initComponents();
	frame.setSize(1000, 500);
	frame.setVisible(true);
}
 
開發者ID:ianturton,項目名稱:geotools-cookbook,代碼行數:24,代碼來源:TwoAttributes.java

示例4: joinFeaures

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 *
 * @param shapes
 * @param shapes2
 * @throws Exception
 */
private static SimpleFeatureCollection joinFeaures(SimpleFeatureSource shapes, SimpleFeatureSource shapes2) throws Exception {
	SimpleFeatureCollection join =null;

    SimpleFeatureType schema = shapes.getSchema();
    String typeName = schema.getTypeName();
    String geomName = schema.getGeometryDescriptor().getLocalName();

    SimpleFeatureType schema2 = shapes2.getSchema();
    String typeName2 = schema2.getTypeName();
    String geomName2 = schema2.getGeometryDescriptor().getLocalName();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
    SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
    SimpleFeatureIterator iterator = outerFeatures.features();
    int max = 0;
    try {
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            try {
                Geometry geometry = (Geometry) feature.getDefaultGeometry();
                if (!geometry.isValid()) {
                    // skip bad data
                    continue;
                }
                Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
                Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
                join = shapes2.getFeatures(innerQuery);
                int size = join.size();
                max = Math.max(max, size);
            } catch (Exception skipBadData) {
            }
        }
    } finally {
        iterator.close();
    }
    return join;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:45,代碼來源:SimpleShapefile.java

示例5: testGetFeatures

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatures()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatures() {
    URL url = SLDEditorFile.class.getClassLoader()
            .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getFeatures());
        dsInfo.setSchema(schema);

        assertNull(dsInfo.getFeatures());
        dsInfo.setDataStore(dataStore);

        assertTrue(dsInfo.getFeatures() != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:35,代碼來源:DataSourceInfoTest.java

示例6: testGetFeatureCollection

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureCollection()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatureCollection() {
    URL url = SLDEditorFile.class.getClassLoader()
            .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);

        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:32,代碼來源:DataSourceInfoTest.java

示例7: testGetFeatureStore

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureStore()}. Test
 * method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#setSchema(org.opengis.feature.type.FeatureType)}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetFeatureStore() {
    URL url = SLDEditorFile.class.getClassLoader()
            .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        dsInfo.setSchema(schema);

        assertNull(dsInfo.getFeatureStore());
        dsInfo.setDataStore(dataStore);

        FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = dsInfo.getFeatureStore();

        assertTrue(featureStore != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:37,代碼來源:DataSourceInfoTest.java

示例8: testGetPropertyDescriptorList

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Test method for
 * {@link com.sldeditor.datasource.impl.DataSourceInfo#getPropertyDescriptorList()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetPropertyDescriptorList() {
    URL url = SLDEditorFile.class.getClassLoader()
            .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getPropertyDescriptorList());
        dsInfo.setSchema(schema);

        Collection<PropertyDescriptor> fieldList = dsInfo.getPropertyDescriptorList();

        assertTrue(fieldList.size() == 3);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:35,代碼來源:DataSourceInfoTest.java

示例9: testGetGeometryFieldName

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getGeometryFieldName()}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetGeometryFieldName() {
    URL url = SLDEditorFile.class.getClassLoader()
            .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);

        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:32,代碼來源:DataSourceInfoTest.java

示例10: getUAZAttributes

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Gets the uAZ attributes.
 *
 * @param uazTbl
 *          the uaz tbl
 * @return the uAZ attributes
 */
public List<String> getUAZAttributes(final String uazTbl) {

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

  final List<String> attrs = new ArrayList<String>();
  DataStore wifDataStore;
  try {
    wifDataStore = openPostgisDataStore();
    final SimpleFeatureSource featureSourceUD = wifDataStore
        .getFeatureSource(uazTbl);
    final SimpleFeatureType schema = featureSourceUD.getSchema();

    // let's also take note of the geometry column so that we don't
    // add it to the returned list
    final String geomColumnName = schema.getGeometryDescriptor()
        .getLocalName();

    for (final AttributeDescriptor attr : schema.getAttributeDescriptors()) {
      if (!geomColumnName.equals(attr.getLocalName())) {
        attrs.add(attr.getLocalName());
      }
    }
  } catch (final IOException e) {
    LOGGER.error("could not access table {} ", uazTbl);
  }
  return attrs;
}
 
開發者ID:AURIN,項目名稱:online-whatif,代碼行數:35,代碼來源:GeodataFinder.java

示例11: createStyle2

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
/**
 * Create a default {@link Style} ofr the featureSource.
 *
 * @param featureSource
 *            the source on which to create the style.
 * @return the style created.
 */
public static Style createStyle2(final SimpleFeatureSource featureSource) {
	final SimpleFeatureType schema = featureSource.getSchema();
	final Class<?> geomType = schema.getGeometryDescriptor().getType().getBinding();

	if (Polygon.class.isAssignableFrom(geomType) || MultiPolygon.class.isAssignableFrom(geomType)) {
		return createPolygonStyle();

	} else if (LineString.class.isAssignableFrom(geomType) || MultiLineString.class.isAssignableFrom(geomType)) {
		return createLineStyle();

	} else {
		return createPointStyle();
	}
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:22,代碼來源:Utils.java

示例12: joinExample

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
private static void joinExample(SimpleFeatureSource shapes, SimpleFeatureSource shapes2)
        throws Exception {
    SimpleFeatureType schema = shapes.getSchema();
    String typeName = schema.getTypeName();
    String geomName = schema.getGeometryDescriptor().getLocalName();
    
    SimpleFeatureType schema2 = shapes2.getSchema();
    String typeName2 = schema2.getTypeName();
    String geomName2 = schema2.getGeometryDescriptor().getLocalName();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    
    Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
    SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
    SimpleFeatureIterator iterator = outerFeatures.features();
    int max = 0;
    try {
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            try {
                Geometry geometry = (Geometry) feature.getDefaultGeometry();
                if (!geometry.isValid()) {
                    // skip bad data
                    continue;
                }
                Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
                Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
                SimpleFeatureCollection join = shapes2.getFeatures(innerQuery);
                int size = join.size();
                max = Math.max(max, size);
            } catch (Exception skipBadData) {
            }
        }
    } finally {
        iterator.close();
    }
    System.out.println("At most " + max + " " + typeName2 + " features in a single " + typeName
            + " feature");
}
 
開發者ID:ianturton,項目名稱:geotools-cookbook,代碼行數:39,代碼來源:JoinExample.java

示例13: exportToShapefile

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
DataStore exportToShapefile(MemoryDataStore memory, String typeName, File directory)
        throws IOException {
    // existing feature source from MemoryDataStore
    SimpleFeatureSource featureSource = memory.getFeatureSource(typeName);
    SimpleFeatureType ft = featureSource.getSchema();
    
    String fileName = ft.getTypeName();
    File file = new File(directory, fileName + ".shp");
    
    Map<String, java.io.Serializable> creationParams = new HashMap<String, java.io.Serializable>();
    creationParams.put("url", DataUtilities.fileToURL(file));
    
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
    DataStore dataStore = factory.createNewDataStore(creationParams);
    
    dataStore.createSchema(ft);
    
    // The following workaround to write out the prj is no longer needed
    // ((ShapefileDataStore)dataStore).forceSchemaCRS(ft.getCoordinateReferenceSystem());
    
    SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(typeName);
    
    Transaction t = new DefaultTransaction();
    try {
        SimpleFeatureCollection collection = featureSource.getFeatures(); // grab all features
        featureStore.addFeatures(collection);
        t.commit(); // write it out
    } catch (IOException eek) {
        eek.printStackTrace();
        try {
            t.rollback();
        } catch (IOException doubleEeek) {
            // rollback failed?
        }
    } finally {
        t.close();
    }
    return dataStore;
}
 
開發者ID:ianturton,項目名稱:geotools-cookbook,代碼行數:40,代碼來源:DataExamples.java

示例14: centerFeatures

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的package包/類
private void centerFeatures() throws Exception {
    String typeName = (String) featureTypeCBox.getSelectedItem();
    SimpleFeatureSource source = dataStore.getFeatureSource(typeName);

    Filter filter = CQL.toFilter(text.getText());

    FeatureType schema = source.getSchema();
    String name = schema.getGeometryDescriptor().getLocalName();
    Query query = new Query(typeName, filter, new String[] { name });

    SimpleFeatureCollection features = source.getFeatures(filter);

    double totalX = 0.0;
    double totalY = 0.0;
    long count = 0;
    SimpleFeatureIterator iterator = features.features();
    try {
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            Geometry geom = (Geometry) feature.getDefaultGeometry();
            Point centroid = geom.getCentroid();
            totalX += centroid.getX();
            totalY += centroid.getY();
            count++;
        }
    } finally {
        iterator.close(); // IMPORTANT
    }
    double averageX = totalX / (double) count;
    double averageY = totalY / (double) count;
    Coordinate center = new Coordinate(averageX, averageY);

    JOptionPane.showMessageDialog(text, "Center of selected features:" + center);
}
 
開發者ID:ianturton,項目名稱:geotools-cookbook,代碼行數:35,代碼來源:QueryLab.java

示例15: mergeShapeFile

import org.geotools.data.simple.SimpleFeatureSource; //導入方法依賴的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.data.simple.SimpleFeatureSource.getSchema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。