私は Geotools を初めて使用し、この問題に直面しています。PostGis に約 2MB のシェープファイル情報 (約 5800 エントリ) を注入していますが、驚くべきことに、完了までに多かれ少なかれ 6 分かかります! 私の「実際の」データセットは、シェープファイルグループ(shp、dbf ...)ごとに最大25MBになる可能性があり、100グループが必要になるため、非常に面倒です。
Postgre は各 INSERT でテーブルのインデックスを更新するため、インデックスの問題である可能性があると言われました。一括 INSERT 中にこれらのインデックスを「無効」にして、最後にすべてのインデックスを作成するようにデータベースに指示する方法はありますか? または、それを行うより良い方法はありますか?
ここに私のコードスニペットがあります:
Map<String, Object> shpparams = new HashMap<String, Object>();
shpparams.put("url", "file://" + path);
FileDataStore shpStore = (FileDataStore) shpFactory.createDataStore(shpparams);
SimpleFeatureCollection features = shpStore.getFeatureSource().getFeatures();
if (schema == null) {
// Copy schema and change name in order to refer to the same
// global schema for all files
SimpleFeatureType originalSchema = shpStore.getSchema();
Name originalName = originalSchema.getName();
NameImpl theName = new NameImpl(originalName.getNamespaceURI(), originalName.getSeparator(), POSTGIS_TABLENAME);
schema = factory.createSimpleFeatureType(theName, originalSchema.getAttributeDescriptors(), originalSchema.getGeometryDescriptor(),
originalSchema.isAbstract(), originalSchema.getRestrictions(), originalSchema.getSuper(), originalSchema.getDescription());
pgStore.createSchema(schema);
}
// String typeName = shpStore.getTypeNames()[0];
SimpleFeatureStore featureStore = (SimpleFeatureStore) pgStore.getFeatureSource(POSTGIS_TABLENAME);
// Ajout des objets du shapefile dans la table PostGIS
DefaultTransaction transaction = new DefaultTransaction("create");
featureStore.setTransaction(transaction);
try {
featureStore.addFeatures(features);
transaction.commit();
} catch (Exception problem) {
LOGGER.error(problem.getMessage(), problem);
transaction.rollback();
} finally {
transaction.close();
}
shpStore.dispose();
ご協力ありがとうございました!
だから私はあなたの解決策をテストしましたが、何も助けてくれませんでした...完了時間は同じです。これが私のテーブル定義です:
- fid シリアル 10
- the_geom ジオメトリ 2147483647
- xxx varchar 10
- xxx int4 10
- xxx varchar 3
- xxx varchar 2
- xxx float8 17
- xxx float8 17
- xxx float8 17
したがって、問題が私のコードやデータベースに直接関係しているとは思いません。おそらくシステムの制限 (RAM、バッファーなど) が原因である可能性があります。これについては、今後数日のうちに見ていきます。
もっとアイデアはありますか?