【发布时间】: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