本文整理汇总了Java中org.geotools.data.FeatureWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java FeatureWriter.close方法的具体用法?Java FeatureWriter.close怎么用?Java FeatureWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.data.FeatureWriter
的用法示例。
在下文中一共展示了FeatureWriter.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportToShapefile
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
/**
* Export features to a new shapefile using the map projection in which
* they are currently displayed
*/
public static void exportToShapefile(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
// carefully open an iterator and writer to process the results
Transaction transaction = new DefaultTransaction();
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0], transaction);
FeatureIterator<SimpleFeature> iterator = featureCollection.features();
try {
while( iterator.hasNext() ){
SimpleFeature feature = iterator.next();
SimpleFeature copy = writer.next();
//copy.setAttributes( feature.getAttributes() );
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if(geometry!=null){
copy.setDefaultGeometry( geometry.buffer(0));
writer.write();
}else{
logger.warn("Warning:geometry null");
}
}
transaction.commit();
logger.info("Export to shapefile complete" );
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
logger.error("Export to shapefile failed",problem );
} finally {
writer.close();
iterator.close();
transaction.close();
}
}
示例2: testRemoveFeature
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Test
public void testRemoveFeature() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
final Query query = new Query(
"GeoWaveFeatureReaderTest",
ECQL.toFilter("pid like '" + pids.get(
0).substring(
0,
1) + "%'"),
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertEquals(1, count);
// Remove
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
dataStore.getFeatureWriter(type.getTypeName(), Transaction.AUTO_COMMIT);
try {
while (writer.hasNext()) {
writer.next();
writer.remove();
}
} finally {
writer.close();
}
// Re-query
final FeatureReader<SimpleFeatureType, SimpleFeature> reader2 =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int recount = 0;
while (reader2.hasNext()) {
reader2.next();
recount++;
}
assertEquals(0, recount);
}
示例3: build
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
public void build() throws IOException, ParseException
{
// Build the test shapefile
SimpleFeatureTypeBuilder schemaBuilder = new SimpleFeatureTypeBuilder();
schemaBuilder.setName("Flag");
schemaBuilder.setNamespaceURI("http://localhost/");
schemaBuilder.setCRS(DefaultGeographicCRS.WGS84);
// add attributes in order
this.addSchemaAttributes(schemaBuilder);
SimpleFeatureType schema = schemaBuilder.buildFeatureType();
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", url);
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
store.createSchema(schema);
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = store.getFeatureWriter(Transaction.AUTO_COMMIT);
try
{
for (int i = 0; i < 100; i++)
{
SimpleFeature feature = writer.next();
populateFeature(feature, i);
writer.write();
}
}
finally
{
writer.close();
}
}
示例4: exportGeometriesToShapeFile
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
/**
*
* @param geoms
* @param fileOutput
* @param geomType
* @param transform
* @throws IOException
* @throws SchemaException
*/
public static void exportGeometriesToShapeFile(final List<Geometry> geoms,
File fileOutput,String geomType,GeoTransform transform,
SimpleFeatureType featureType) throws IOException, SchemaException{
FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
//Map map = Collections.singletonMap( "url", fileOutput.toURI().toURL() );
DataStore data = factory.createDataStore( fileOutput.toURI().toURL() );
boolean addAttr=true;
if(featureType==null){
featureType=DataUtilities.createType( "the_geom", "geom:"+geomType+",name:String,age:Integer,description:String" );
addAttr=false;
}
data.createSchema( featureType );
Transaction transaction = new DefaultTransaction();
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriterAppend(data.getTypeNames()[0], transaction);
SimpleFeatureBuilder featureBuilder=new SimpleFeatureBuilder(featureType);
GeometryFactory gb=new GeometryFactory();
try {
int fid=0;
for(final Geometry g:geoms){
Geometry clone=gb.createGeometry(g);
if(transform!=null)
clone=transform.transformGeometryGeoFromPixel(clone);
featureBuilder.add("the_geom");
featureBuilder.add(clone);
SimpleFeature sf=featureBuilder.buildFeature(""+fid++);
SimpleFeature sfout=writer.next();
sfout.setAttributes( sf.getAttributes() );
//setting attributes geometry
AttributesGeometry att=(AttributesGeometry) g.getUserData();
try{
if(att!=null&&addAttr){
String sch[]=att.getSchema();
for(int i=0;i<sch.length;i++){
Object val=att.get(sch[i]);
if(val.getClass().isArray()){
Object o=ArrayUtils.toString(val);
sfout.setAttribute(sch[i], o);
}else{
sfout.setAttribute(sch[i], val);
}
}
}
}catch(Exception e ){
logger.warn("Error adding attributes to geometry:"+e.getMessage());
}
sfout.setDefaultGeometry( clone);
writer.write();
}
transaction.commit();
logger.info("Export to shapefile complete:"+ fileOutput.getAbsolutePath());
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
logger.error("Export to shapefile failed",problem );
} finally {
writer.close();
transaction.close();
data.dispose();
}
}
示例5: exportToShapefileForceWGS84
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
public static void exportToShapefileForceWGS84(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
// carefully open an iterator and writer to process the results
Transaction transaction = new DefaultTransaction();
//CoordinateReferenceSystem crsOrig=featureCollection.getSchema().getCoordinateReferenceSystem();
//set wgs84 coordinates ref sys
SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), DefaultGeographicCRS.WGS84);
newDataStore.createSchema(featureType);
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0], transaction);
//create the transformation
MathTransform trans=CRS.findMathTransform(CRS.parseWKT(WKTString.WKT3995_ESRI),DefaultGeographicCRS.WGS84);
FeatureIterator<SimpleFeature> iterator = featureCollection.features();
try {
while( iterator.hasNext() ){
SimpleFeature feature = iterator.next();
SimpleFeature copy = writer.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
geometry=JTS.transform(geometry,trans);
if(geometry!=null){
copy.setDefaultGeometry( geometry.buffer(0));
writer.write();
}else{
logger.warn("Warning:geometry null");
}
}
transaction.commit();
logger.info("Export to shapefile complete" );
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
logger.error("Export to shapefile failed",problem );
} finally {
writer.close();
iterator.close();
transaction.close();
}
}
示例6: setup
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Before
public void setup() throws SchemaException, CQLException, Exception {
setupConf();
try (final GeoWaveGeoIndexer indexer = new GeoWaveGeoIndexer()) {
indexer.setConf(conf);
dataStore = indexer.getGeoToolsDataStore();
// Clear old data
indexer.purge(conf);
type = DataUtilities.createType(
"GeoWaveFeatureReaderTest",
"geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
dataStore.createSchema(type);
stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
etime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
"a" + UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
stime);
newFeature.setAttribute(
"end",
etime);
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(27.25, 41.25)));
fids.add(newFeature.getID());
pids.add(newFeature.getAttribute("pid").toString());
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(101));
newFeature.setAttribute(
"pid",
"b" + UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
etime);
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(28.25, 41.25)));
fids.add(newFeature.getID());
pids.add(newFeature.getAttribute("pid").toString());
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
query = new Query(
"GeoWaveFeatureReaderTest",
ECQL.toFilter("IN ('" + fids.get(0) + "')"),
new String[] {
"geometry",
"pid"
});
}
}
示例7: exportToShapefile
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
/**
* Export features to a new shapefile using the map projection in which they are currently
* displayed
*/
// docs start export
private void exportToShapefile() throws Exception {
SimpleFeatureType schema = featureSource.getSchema();
JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
chooser.setDialogTitle("Save reprojected shapefile");
chooser.setSaveFile(sourceFile);
int returnVal = chooser.showSaveDialog(null);
if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) {
return;
}
File file = chooser.getSelectedFile();
if (file.equals(sourceFile)) {
JOptionPane.showMessageDialog(null, "Cannot replace " + file);
return;
}
// set up the math transform used to process the data
CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);
// grab all features
SimpleFeatureCollection featureCollection = featureSource.getFeatures();
// And create a new Shapefile with a slight modified schema
DataStoreFactorySpi factory = new ShapefileDataStoreFactory();
Map<String, Serializable> create = new HashMap<String, Serializable>();
create.put("url", file.toURI().toURL());
create.put("create spatial index", Boolean.TRUE);
DataStore dataStore = factory.createNewDataStore(create);
SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(schema, worldCRS);
dataStore.createSchema(featureType);
// carefully open an iterator and writer to process the results
Transaction transaction = new DefaultTransaction("Reproject");
FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
dataStore.getFeatureWriterAppend(featureType.getTypeName(), transaction);
SimpleFeatureIterator iterator = featureCollection.features();
try {
while (iterator.hasNext()) {
// copy the contents of each feature and transform the geometry
SimpleFeature feature = iterator.next();
SimpleFeature copy = writer.next();
copy.setAttributes(feature.getAttributes());
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Geometry geometry2 = JTS.transform(geometry, transform);
copy.setDefaultGeometry(geometry2);
writer.write();
}
transaction.commit();
JOptionPane.showMessageDialog(null, "Export to shapefile complete");
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
JOptionPane.showMessageDialog(null, "Export to shapefile failed");
} finally {
writer.close();
iterator.close();
transaction.close();
}
}
示例8: populate
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
public void populate()
throws IOException,
CQLException,
ParseException {
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-19T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-18T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
27.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-17T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
}
示例9: setup
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Before
public void setup()
throws SchemaException,
CQLException,
Exception {
dataStore = createDataStore();
type = DataUtilities.createType(
"GeoWaveFeatureReaderTest",
"geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
dataStore.createSchema(type);
stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
etime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
"a" + UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
stime);
newFeature.setAttribute(
"end",
etime);
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
27.25,
41.25)));
fids.add(newFeature.getID());
pids.add(newFeature.getAttribute(
"pid").toString());
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(101));
newFeature.setAttribute(
"pid",
"b" + UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
etime);
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
28.25,
41.25)));
fids.add(newFeature.getID());
pids.add(newFeature.getAttribute(
"pid").toString());
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
// System.out.println(fids);
query = new Query(
"GeoWaveFeatureReaderTest",
ECQL.toFilter("IN ('" + fids.get(0) + "')"),
new String[] {
"geometry",
"pid"
});
}
示例10: test
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Test
public void test()
throws IOException,
CQLException,
ParseException {
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-19T18:33:55Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
27.25,
41.25)));
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-19T20:33:55Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
27.25,
41.25)));
writer.write();
writer.close();
final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
query,
transaction1);
assertTrue(reader.hasNext());
final SimpleFeature priorFeature = reader.next();
assertEquals(
newFeature.getAttribute("pid"),
priorFeature.getAttribute("pid"));
assertFalse(reader.hasNext());
reader.close();
transaction1.commit();
transaction1.close();
}
示例11: populate
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
public void populate(
final SimpleFeatureType type,
final DataStore dataStore )
throws IOException,
CQLException,
ParseException {
dataStore.createSchema(type);
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(77));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-19T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(66));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-18T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
27.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-17T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.242)));
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
}
示例12: setup
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Before
public void setup()
throws IOException,
GeoWavePluginException,
SchemaException {
geotoolsDataStore = createDataStore();
type = DataUtilities.createType(
typeName,
typeSpec);
geotoolsDataStore.createSchema(type);
final Transaction transaction = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = geotoolsDataStore.getFeatureWriter(
type.getTypeName(),
transaction);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
geometry_attribute,
GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(
41.25,
41.25)));
newFeature.setAttribute(
long_attribute,
1l);
newFeature.setAttribute(
string_attribute,
"string1");
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
geometry_attribute,
GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(
41.5,
41.5)));
newFeature.setAttribute(
long_attribute,
2l);
newFeature.setAttribute(
string_attribute,
"string2");
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
geometry_attribute,
GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(
41.75,
41.75)));
newFeature.setAttribute(
long_attribute,
3l);
newFeature.setAttribute(
string_attribute,
"string3");
writer.write();
writer.close();
transaction.commit();
transaction.close();
}
示例13: testInsertIsolation
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
@Test
public void testInsertIsolation()
throws IOException,
CQLException {
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
final SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
27.25,
41.25)));
writer.write();
writer.close();
FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(
query,
transaction1);
assertTrue(reader.hasNext());
final SimpleFeature priorFeature = reader.next();
assertEquals(
newFeature.getAttribute("pid"),
priorFeature.getAttribute("pid"));
reader.close();
// uncommitted at this point, so this next transaction should not see
// it.
final Transaction transaction2 = new DefaultTransaction();
reader = dataStore.getFeatureReader(
query,
transaction2);
assertFalse(reader.hasNext());
reader.close();
transaction1.commit();
reader = dataStore.getFeatureReader(
query,
transaction1);
assertTrue(reader.hasNext());
reader.next();
assertFalse(reader.hasNext());
reader.close();
transaction1.close();
// since this implementation does not support serializable, transaction2
// can see the changes even though
// it started after transaction1 and before the commit.
reader = dataStore.getFeatureReader(
query,
transaction2);
assertTrue(reader.hasNext());
reader.next();
assertFalse(reader.hasNext());
reader.close();
transaction2.commit();
transaction2.close();
// stats check
final Transaction transaction3 = new DefaultTransaction();
reader = ((GeoWaveFeatureSource) ((GeoWaveGTDataStore) dataStore).getFeatureSource(
"geostuff",
transaction3)).getReaderInternal(query);
Map<ByteArrayId, DataStatistics<SimpleFeature>> transStats = ((GeoWaveFeatureReader) reader)
.getTransaction()
.getDataStatistics();
assertNotNull(transStats.get(FeatureNumericRangeStatistics.composeId("pop")));
transaction3.close();
}
示例14: populate
import org.geotools.data.FeatureWriter; //导入方法依赖的package包/类
public void populate()
throws IOException,
CQLException,
ParseException {
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
DateUtilities.parseISO("2005-05-17T20:32:56Z"));
newFeature.setAttribute(
"end",
DateUtilities.parseISO("2005-05-19T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
DateUtilities.parseISO("2005-05-18T20:32:56Z"));
newFeature.setAttribute(
"end",
DateUtilities.parseISO("2005-05-20T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
27.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"start",
DateUtilities.parseISO("2005-05-21T20:32:56Z"));
newFeature.setAttribute(
"end",
DateUtilities.parseISO("2005-05-22T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
}