2

使用 GeoTools WFS-T 插件,我创建了一个新行,提交后,我有一个 FeatureId whos .getId() 返回一个看起来像这样的丑陋字符串:

newmy_database:my_table.9223372036854775807

除了“my_database”开头的“new”一词令人惊讶之外,该数字绝不反映新行的主键(在本例中为“23”)。很公平,我认为这可能是一些内部编号系统。但是,现在我想要另一个表中的外键来获取该表中新行的主键,并且我不确定如何从该 FID 中获取值。有些地方建议您可以在这样的查询中使用 FID:

Filter filter = filterFactory.id(Collections.singleton(fid));
Query query = new Query(tableName, filter);
SimpleFeatureCollection features = simpleFeatureSource.getFeatures(query);

但这在解析 FID 时失败了,在所有地方的下划线处!该下划线在创建行时存在(我必须将“my_database:my_table”作为表传递给添加行)。

我确定 id 有问题,或者我以某种方式错误地使用它。任何人都可以解释一下吗?

4

1 回答 1

2

看起来好像有几件事出了问题——也许需要一份错误报告。

以“new”开头的FeatureId是临时id;一旦调用了提交,就应该将其替换为实际结果。

有很多方法可以意识到这一点:

1) 你可以监听一个 BatchFeatureEvent;这提供了关于“temp id”->“wfs id”的信息

2) 在内部,此信息是从您的 WFS 返回的事务结果中解析的。结果保存在 WFSTransactionState 中供您访问。这是在发明 BatchFeatureEvent 之前。

Transaction transaction = new transaction("insert");
try {
     SimpleFeatureStore featureStore =
           (SimpleFeatureStore) wfs.getFeatureSource( typeName );
     featureStore.setTransaction( transaction );
     featureStore.addFeatures( DataUtilities.collection( feature ) );

     transaction.commit();

     // get the final feature id
     WFSTransactionState wfsts = (WFSTransactionState) transaction.getState(wfs);

     // In this example there is only one fid. Get it.
     String result = wfsts.getFids( typeName )[0];
}
finally {
     transaction.close();
}         

我已经用上面的例子更新了文档:

于 2011-05-24T23:43:21.523 回答