【问题标题】:GeoTools Query with SortBy: Wrong syntax of generated SQL使用 SortBy 的 GeoTools 查询:生成的 SQL 语法错误
【发布时间】:2017-05-16 13:36:46
【问题描述】:

我正在尝试使用 GeoTools 及其 OGR Plugin 读取 Java 中的 MapInfo MAP 文件。我想以某种排序顺序迭代功能。为此,我尝试使用 GeoTool 的 Query 和 SortBy,但生成的 SQL 查询有语法错误。

代码示例:

OGRDataStoreFactory factory = new JniOGRDataStoreFactory();
Map<String, String> connectionParams = new HashMap<String, String>();
connectionParams.put("DriverName", "MapInfo File");
connectionParams.put("DatasourceName", new File("MyTable.TAB").getAbsolutePath());
DataStore store = factory.createDataStore(connectionParams);
SimpleFeatureSource featureSource = store.getFeatureSource("MyTable");
Query query = new Query();
query.setSortBy(new SortBy[]{ new SortByImpl(new AttributeExpressionImpl("PED"), SortOrder.ASCENDING)});
SimpleFeatureIterator features = featureSource.getFeatures(query).features();
int count = 0;
while (features.hasNext() && count++ < 10) {
    Feature feature = features.next();
    System.out.println(feature);
}

这会导致此错误消息打印到 stderr:

ERROR 1: SQL Expression Parsing Error: syntax error, unexpected ORDER, expecting '.'. Occurred around :
SELECT FID, * FROM 'MyTable' ORDER BY PED
                                 ^

问题在于表名周围的单引号。

如果我删除 setSortBy() 行,则会返回特征。所以一般的数据访问是有效的。

如果我在带有双引号的命令行上使用 ogr2ogr 尝试相同的查询,它会按预期工作:

ogr2ogr -f "CSV" /vsistdout/ MyTable.TAB -lco GEOMETRY=AS_WKT -sql "SELECT FID, * FROM \"MyTable\" ORDER BY \"PED\" ASC"

我做错了吗?

【问题讨论】:

    标签: java sql geotools ogr mapinfo


    【解决方案1】:

    它看起来像bug here,如果您可以编写一个简单的测试用例并归档bug report,它应该很容易修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多