这个 GeoTools FeatureId 有什么问题吗?

发布于 2024-11-07 10:11:13 字数 651 浏览 8 评论 0原文

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

newmy_database:my_table.9223372036854775807

除了单词“new”位于“my_database”的开头令人惊讶,该数字绝不反映新行的主键(在本例中为“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 有问题,要么是我使用方式不正确。任何人都可以阐明吗?

Using the GeoTools WFS-T plugin, I have created a new row, and after a commit, I have a FeatureId whos .getId() returns an ugly string that looks something like this:

newmy_database:my_table.9223372036854775807

Aside from the fact that the word "new" at the beginning of "my_database" is a surprise, the number in no way reflects the primary key of the new row (which in this case is "23"). Fair enough, I thought this may be some internal numbering system. However, now I want a foreign key in another table to get the primary key of the new row in this one, and I'm not sure how to get the value from this FID. Some places suggest that you can use an FID in a query like this:

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

But this fails at parsing the FID, at the underscore of all places! That underscore was there when the row was created (I had to pass "my_database:my_table" as the table to add the row to).

I'm sure that either there is something wrong with the id, or I'm using it incorrectly somehow. Can anyone shed any light?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2024-11-14 10:11:13

似乎有几件事出了问题——也许需要一份错误报告。

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

有多种方法可以了解这一点:

1)您可以侦听 BatchFeatureEvent;这提供了有关“临时 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();
}         

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

It appears as if a couple things are going wrong - and perhaps a bug report is needed.

The FeatureId with "new" at the beginning is a temporary id; that should be replaced with the real result once commit has been called.

There are a number of way to be aware of this:

1) You can listen for a BatchFeatureEvent; this offers the information on "temp id" -> "wfs id"

2) Internally this information is parsed from the Transaction Result returned from your WFS. The result is saved in the WFSTransactionState for you to access. This was before BatchFeatureEvent was invented.

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();
}         

I have updated the documentation with the above example:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文