Geometry Management

From gvSIG CE Wiki

Jump to: navigation, search

Geometry API has been refactored recently and we reached a stable, consistent state.

We:

  • Removed FShape interface and Shape.getInternalShape method from IGeometry. IGeometry already extended AWT Shape class, so there was no need for that method (which almost always returned this).
  • Added the extra methods in FShape to IGeometry and made all implementations (FPoint2D, FPoint3D, ...) implement IGeometry instead of FShape.
  • Refactored FGeometry (which contained common operations to all geometries) to an abstract class (Abstract Geometry).
  • Removed IGeometryM and IGeometry3D interfaces. Instead I added hasZ/M getZs/Ms methods to IGeometry so there's no need for castings or instanceof instructions. Also, the hasZ/M methods simplify a lot some checks: geom.hasZ() instead of (geom.getType() & IGeometry.Z) > 0.
  • Renamed some methods, extracted code that was used in just a couple of places and added some utility methods (getCoordinate(), getCoordinates()).

With this, the IGeometry hierarchy is much more simple: IGeometry -> AbstractGeometry -> implementations.

The main problem with the current implementation is that internally geometries store AWT shapes (which are 2D) and extra values (zs, ms) and then transform them to JTS geometries for obtaining coordinates and/or make calculations. I think the next big step would be to refactor implementations to store JTS internally and transform to AWT shapes for drawing. It would be much simpler and we'll get rid of some code that is already implemented in JTS.

Also, we improved some tools for 3D support:

  • 3D layer creation is now supported for Shapefile, PostGIS, SQLite and DXF.
  • The attribute table has read/write support for x/y/z coordinates for point layers. The columns are at the beginning and with a darker gray.
  • The field calculator handles x/y/z columns for point layers when present. Thus, now it is possible to change coordinates for point layers using a function.

(Link to main SVN commit: https://sourceforge.net/p/gvsigce/code/2236/)