[Qgis-developer] QgsGeometry
Marco Hugentobler
marco.hugentobler at karto.baug.ethz.ch
Wed Sep 12 03:01:20 EDT 2007
On Tuesday 11 September 2007 14:36:07 Martin Dobias wrote:
> > There could e.g. be a class that splits a geometry into two parts by a
> > line (just to get the code for geometry splitting out of QgsGeometry):
> >
> > class QgsSplitGeometry
> > {
> > public:
> > int splitGeometry(QList<points> splitLine, QgsGeometry**
> > newGeometry); private:
> > QgsGeometry* mGeometry
> > }
>
> Now I'm starting to think that we should rather start to use a scheme
> as e.g. OGR and GEOS use. They have a base Geometry class and derived
> classes which can do operations with the specific type of geometry
> (point, polyline, ...). What leads me to this: when you look to
> QgsGeometry source, it's full of long switches for different types of
> geometry. In a book about refactoring I've read that long switches are
> a "bad smell" which should be better implemented with virtual
> functions with different implementations in derived classes. Does this
> make a sense to you?
> In this approach, splitGeometry() would be also just another virtual
> function in QgsGeometry which would be implemented properly in child
> classes.
Yes, true. It may make sense to switch to such a scheme in the middle term
(maybe after merging of advanced editing branch).
There could be several possibilities to do so:
-The qgis classes could be derived from geos classes and from QgsGeometry
interface class.
-Or an approache similar to OGR which has their own representation of geometry
and does geos conversion when needed for topological operations.
And there are surely other approaches. At first glance I prefer the first
approach as it seems to me that we could reuse more code like this. But I
have to look closer at the geos implementation.
Regards,
Marco
--
Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
Technical Advisor QGIS Project Steering Committee
marco.hugentobler at karto.baug.ethz.ch
More information about the Qgis-developer
mailing list