我有一个非常大的shapefile,里面有近14,000个多边形。大约350mb。我试图用SimpleFeatureIterator读取它,但它似乎不尊重我指定的起始索引。它确实尊重最大功能,所以我认为我非常接近这样做。
public static void main(String[] args)
{
try
{
File file = new File("G:\\shapefiles_basins\\WBD_10_Missouri_Region_HU2\\Shape\\WBDHU12.shp");
FileDataStore myData = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource source = myData.getFeatureSource();
Query query = new Query();
query.setMaxFeatures(5);
query.setStartIndex(3);
//query.setSortBy(new SortBy[]{SortBy.NATURAL_ORDER});
//query.setSortBy(SortBy.UNSORTED);
SimpleFeatureIterator features = source.getFeatures(query).features();
while(features.hasNext())
{
SimpleFeature feature = features.next();
System.out.println(feature.getID() + ": ");
boolean firstProp = true;
for(Property attribute : feature.getProperties())
{
// skip printing the geometry
if(firstProp)
{
firstProp = false;
continue;
}
System.out.println("\t" + attribute.getName() + ":" + attribute.getValue());
}
}
}
catch(Exception ex)
{
int xx = 10;
}
}
这是它生成的缩写输出(我取出了它打印的属性,但它们对于记录ID是正确的):
WBDHU12.1000: ...
WBDHU12.10000: ......
WBDHU12.10001: ...
WBDHU12.10002: ...
WBDHU12.10003: ...
因此它会打印出我请求的正确数量的记录,但不会从记录#3开始,并始终一致地检索记录1000,10000,10001,10002和10003.
如果有人知道我做错了什么,如果你能告诉我,我将非常感激。
感谢。