[gdal-dev] GDAL/OGR Java bindings very slow in reading point coordinates of feature geometries

Even Rouault even.rouault at mines-paris.org
Fri Mar 25 19:45:21 EDT 2011


Le samedi 26 mars 2011 00:14:35, MarvinCO a écrit :
> I have noticed that copying all points of a polygon (of a polygon
> feature) can be very costly in my implementation. This must be due to
> the fact that there is only one method for doing this:
> 
> org.gdal.ogr.Geometry.GetPoint()
> 
> This means that at every invocation of GetPoint, Java has to make a
> single access to the native GDAL/OGR library, only to get a single
> point.

Yes, if you must get many points, I can imagine that the penalty to go through 
JNI for each point can be quite high.

> 
> I cannot imagine that the original C++ version of GDAL/OGR does not
> provide methods for reading points much faster, e.g. something like
> GetPoints() to read all points of the polygon in one single command
> into an array of doubles.

In C++, there's indeed a OGRLineString::getPoints() method that returns the 
coordinate array.

> 
> I mean, why else are the points read much faster if I read them, e.g.
> with Quantum GIS, which uses the original C++ GDAL/OGR?

Reviewing quickly the OGR provider of QGIS, I can see that they get the 
geometry as WKB, and I imagine that they have a wkb decoder somewhere else 

> 
> Are such methods simply missing in the Java bindings?

Yes, getPoints() hasn't yet been mapped to the SWIG bindings, but that would 
certainly be a valuable addition. Could you file an enhancement request ticket 
in GDAL Trac ?

> Or what else
> could one do to speed this up?

Well, in the meantime you could use Geometry.ExportToWkb() method to get the 
Wkb representation of the geometry and parse it on Java side. You could for 
example the WKBReader  from the JTS to do that... or do it at hand if you 
don't want to add a new dependency, but that's a bit more involved.

> 
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/GDAL-OGR-Java-bindings-very-slow-in
> -reading-point-coordinates-of-feature-geometries-tp6209461p6209461.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list