这个方法应该用我传递给它的新特性替换数据库中的特性。
private static void replaceBoundaryShape(FeatureCollection<SimpleFeatureType, SimpleFeature> dbFeatures) throws IOException, CQLException{
FeatureStore<SimpleFeatureType, SimpleFeature> fs = null;
FeatureSchemaFactory factory = FeatureSchemaFactory.init();
DataStore geoStore = initDataStore();
try{
fs = (FeatureStore) geoStore.getFeatureSource(factory.getFieldFeatureSchema().getTypeName());
fs.setTransaction(new DefaultTransaction());
for(FeatureIterator<SimpleFeature> iterator = dbFeatures.features(); iterator.hasNext();){
SimpleFeature simpleFeature = iterator.next();
Number fieldId = (Number) simpleFeature.getAttribute(FeatureSchemaFactory.FIELD_ID);
Filter filter = createSearchByIdFilter(fieldId.longValue());
fs.removeFeatures(filter);
}
fs.addFeatures(dbFeatures);
fs.getTransaction().commit();
}catch(CQLException ex){
throw new CQLException(ex.getMessage());
}
}
这是我创建传递以替换边界形状的特征集合的地方
private static FeatureCollection<SimpleFeatureType, SimpleFeature> createBoundaryFeatures(SimpleFeatureType dbSchema, Collection<FieldFeature> fields){
List<SimpleFeature> result = new ArrayList<SimpleFeature>(fields.size());
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(dbSchema);
for(FieldFeature f: fields){
builder.set("BNDRS", f.getGeometries());
builder.set("FIELD", f.getField());
builder.set("FID", f.getFid());
builder.set("GROWER", f.getGrower());
builder.set("SIMPLIFIED_BNDRS", f.getSimplifiedGeometries());
result.add(builder.buildFeature(null));
}
return DataUtilities.collection(result);
}
这是我从文件路径和指定字段获取字段特征的地方:
private static Collection<FieldFeature> convertShpFile(String filePath, Field field) throws MalformedURLException, IOException{
@SuppressWarnings("deprecation")
ShapefileDataStore source = new ShapefileDataStore(new File(filePath).toURL());
Collection<FieldFeature> result = new LinkedList<FieldFeature>();
DefaultQuery query = new DefaultQuery();
query.setCoordinateSystemReproject(DefaultGeographicCRS.WGS84);
FeatureCollection queryResult = source.getFeatureSource().getFeatures(query);
FeatureIterator<SimpleFeature> fi = queryResult.features();
while(fi.hasNext()){
SimpleFeature feature = fi.next();
FieldFeature fieldFeature = new FieldFeature();
Object defaultGeometry = feature.getDefaultGeometry();
if(defaultGeometry instanceof Polygon){
Polygon polygon = (Polygon) defaultGeometry;
Polygon[] polygons = {polygon};
defaultGeometry = geometryFactory.createMultiPolygon(polygons);
}
fieldFeature.setField(field.getId());
fieldFeature.setGeometries(defaultGeometry);
fieldFeature.setSimplifiedGeometries(GeoHelper.simplifyGeometry((Geometry) defaultGeometry));
result.add(fieldFeature);
}
fi.close();
source.dispose();
return result;
}
错误发生在 replaceBoundaryShape 方法的 fs.addFeatures(dbFeatures) 行。
删除功能不会引发错误,但是当我调用 addFeatures 函数时,我收到此 AbstractMethodError: java.lang.AbstractMethodError: org.geotools.jdbc.PreparedStatementSQLDialect.setGeometryValue(Lcom/vividsolutions/jts/geom/Geometry;IILjava/lang/类;Ljava/sql/PreparedStatement;I)V
将功能插入 JDBCDataStore 时似乎会引发错误
编辑:这是完整的堆栈跟踪
java.lang.AbstractMethodError: org.geotools.jdbc.PreparedStatementSQLDialect.setGeometryValue(Lcom/vividsolutions/jts/geom/Geometry;IILjava/lang/Class;Ljava/sql/PreparedStatement;I)V
at org.geotools.jdbc.JDBCDataStore.insertSQLPS(JDBCDataStore.java:4005)
at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1582)
at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1545)
at org.geotools.jdbc.JDBCInsertFeatureWriter.write(JDBCInsertFeatureWriter.java:76)
at org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:337)
at org.geotools.data.store.ContentFeatureStore.addFeature(ContentFeatureStore.java:309)
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:263)
at com.conserviscorp.shape.upload.FieldDAO.replaceBoundaryShape(FieldDAO.java:146)
at com.conserviscorp.shape.upload.FieldDAO.updateFieldData(FieldDAO.java:116)
at com.conserviscorp.ui.MatchedFieldFrame$2.actionPerformed(MatchedFieldFrame.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)