Jessie,

I've been optimizing the PostGIS driver, and I speeded up the reading of a set of coordinates. I use the ObjectInputStream.bytesToDoubles() NATIVE function which takes a byte[] and writes to a double[]. You can probably do the same thing with the shapefile driver. On my test of 100,000 lines (average 83 points/line) this was about 15% faster than the pure java version, and I bet it will be even faster for geometries with larger number of coordinates.

If you want, I can send you a shapefile with lots of points in each geometry.

dave



static Method bytesToDoublesMethod = null;
 static Object[] bytesToDoublesMethodArgs = new Object[5];
 static
 {
     try{
bytesToDoublesMethod = ObjectInputStream.class.getDeclaredMethod("bytesToDoubles",new Class[] {byte[].class,int.class,double[].class,int.class,int.class} );
         bytesToDoublesMethod.setAccessible(true);
         }
     catch(Exception e)
     {
         bytesToDoublesMethod=null;
     }
 }

private final CoordinateSequence readCoordinateSequence(int size) throws IOException
 {
        // problem?
     if (bytesToDoublesMethod == null)
         return readCoordinateSequencePureJava(size);
try{
            double[] ords = new double[size*2];
            bytesToDoublesMethodArgs[0] = bytes; // can be done once
            bytesToDoublesMethodArgs[1] = new Integer(index);
            bytesToDoublesMethodArgs[2] =ords;
bytesToDoublesMethodArgs[3] = new Integer(0); // can be done once
            bytesToDoublesMethodArgs[4] = new Integer(size*2);
            bytesToDoublesMethod.invoke(null,bytesToDoublesMethodArgs);
            index += 8*2*size;
            return coordFactory.create(ords);
     }
     catch(Exception e)
     {
         e.printStackTrace();
         return readCoordinateSequencePureJava(size);
     }
 }

private final CoordinateSequence readCoordinateSequencePureJava(int size) throws IOException
 {
LiteCoordinateSequence seq = (LiteCoordinateSequence)coordFactory.create(size, 2);
   double[] ords = seq.getArray();
   for (int i = 0; i < size; i++)
   {
       long longvalue  = (long) (bytes[index] & 0xff) << 56
       | (long) (bytes[index+1] & 0xff) << 48
       | (long) (bytes[index+2] & 0xff) << 40
       | (long) (bytes[index+3] & 0xff) << 32
       | (long) (bytes[index+4] & 0xff) << 24
       | (long) (bytes[index+5] & 0xff) << 16
       | (long) (bytes[index+6] & 0xff) <<  8
       | (long) (bytes[index+7] & 0xff);
       index +=8;
       ords[i*2]= Double.longBitsToDouble(longvalue);
       longvalue  = (long) (bytes[index] & 0xff) << 56
       | (long) (bytes[index+1] & 0xff) << 48
       | (long) (bytes[index+2] & 0xff) << 40
       | (long) (bytes[index+3] & 0xff) << 32
       | (long) (bytes[index+4] & 0xff) << 24
       | (long) (bytes[index+5] & 0xff) << 16
       | (long) (bytes[index+6] & 0xff) <<  8
       | (long) (bytes[index+7] & 0xff);
       index +=8;
       ords[i*2+1]= Double.longBitsToDouble(longvalue);
     }



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to