Andrea,
I believe it should.
However, on my machine this code tooks about 797 ms.
But this code (which get record count from dbf) tooks about 0 ms:
public static int getCount(String shapefilePath) {
try {
String dbfPath = new File(shapefilePath).getParent() + "/" +
FilenameUtils.getBaseName(shapefilePath) + ".dbf";
RandomAccessFile in = new RandomAccessFile(dbfPath, "r");
in.seek(4L);
return little2big(in.readInt());
} catch (IOException e) {
return -1;
}
}
private static int little2big(int i) {
return((i&0xff)<<24)+((i&0xff00)<<8)+((i&0xff0000)>>8)+((i>>24)&0xff);
}
Thanks,
Sergey
On 29.08.2012 22:06, Andrea Aime wrote:
On Wed, Aug 29, 2012 at 3:07 PM, LSA <[email protected]
<mailto:[email protected]>> wrote:
Hi all,
I am using the following code to find out the number of features
in the
shapefile:
public static int getFeatureCount(String shapefilePath)
{
ShapefileDataStore shapefileDataStore = ...;
FeatureSource featureSource =
shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
return featureSource.getCount(Query.ALL);
}
But it is very slow.
Err... all that code should be doing is opening the shx file, reading
the header,
get the declared count out of it, and return back the result.
Unless your shapefile either have no .shx file or the header of it is
broken
(e.g., contains a negative number)
Cheers
Andrea
--
==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for
more information.
==
Ing. Andrea Aime
@geowolf
Technical Lead
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 962313
mob: +39 339 8844549
http://www.geo-solutions.it
http://twitter.com/geosolutions_it
-------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users