我正在尝试使用GeoTools及其OGR Plugin在Java语言中读取MapInfo映射文件。我想以特定的排序顺序遍历这些特征。为此,我尝试使用GeoTool的查询和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"我做错了什么吗?
发布于 2017-05-17 15:41:47
它看起来像一个bug here,如果你能写一个简单的测试用例并归档一个bug report,它应该很容易修复。
https://stackoverflow.com/questions/44003075
复制相似问题