geomUtil.h

00001 /**********************************************************************
00002  * $Id: geomUtil.h,v 1.3 2004/07/19 13:19:31 strk Exp $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************
00015  * $Log: geomUtil.h,v $
00016  * Revision 1.3  2004/07/19 13:19:31  strk
00017  * Documentation fixes
00018  *
00019  * Revision 1.2  2004/07/08 19:34:49  strk
00020  * Mirrored JTS interface of CoordinateSequence, factory and
00021  * default implementations.
00022  * Added DefaultCoordinateSequenceFactory::instance() function.
00023  *
00024  * Revision 1.1  2004/07/02 13:20:42  strk
00025  * Header files moved under geos/ dir.
00026  *
00027  * Revision 1.4  2004/05/14 14:45:28  strk
00028  * Fixed bogus inheritance of LinearComponentExtracter
00029  *
00030  * Revision 1.3  2004/05/14 13:42:46  strk
00031  * DistanceOp bug removed, cascading errors fixed.
00032  *
00033  * Revision 1.2  2004/04/20 08:52:01  strk
00034  * GeometryFactory and Geometry const correctness.
00035  * Memory leaks removed from SimpleGeometryPrecisionReducer
00036  * and GeometryFactory.
00037  *
00038  * Revision 1.1  2004/04/04 06:29:11  ybychkov
00039  * "planargraph" and "geom/utill" upgraded to JTS 1.4
00040  *
00041  *
00042  */
00043 #ifndef GEOS_GEOMUTIL_H
00044 #define GEOS_GEOMUTIL_H
00045 
00046 #include <geos/geom.h>
00047 #include <geos/platform.h>
00048 #include <vector>
00049 
00050 using namespace std;
00051 
00052 namespace geos {
00053 
00054 /*
00055  * Extracts all the 2-dimensional (Polygon) components from a Geometry.
00056  */
00057 class PolygonExtracter: public GeometryFilter {
00058 public:
00065         static vector<Geometry*>* getPolygons(const Geometry *geom);
00069         PolygonExtracter(vector<Geometry*>* newComps);
00070         void filter_rw(Geometry *geom);
00071         void filter_ro(const Geometry *geom);
00072 private:
00073         vector<Geometry*>* comps;
00074 };
00075 
00076 /*
00077  * Extracts all the 0-dimensional (Point) components from a Geometry.
00078  */
00079 class PointExtracter: public GeometryFilter {
00080 public:
00087         static vector<Geometry*>* getPoints(const Geometry *geom);
00091         PointExtracter(vector<Geometry*>* newComps);
00092         void filter_rw(Geometry *geom);
00093         void filter_ro(const Geometry *geom);
00094 private:
00095         vector<Geometry*>* comps;
00096 };
00097 
00098 /*
00099  * Extracts all the 1-dimensional (LineString) components from a Geometry.
00100  */
00101 class LinearComponentExtracter: public GeometryComponentFilter {
00102 public:
00109         static vector<Geometry*>* getLines(const Geometry *geom);
00113         LinearComponentExtracter(vector<Geometry*>* newComps);
00114         void filter_rw(Geometry *geom);
00115         void filter_ro(const Geometry *geom);
00116 private:
00117         vector<Geometry*>* comps;
00118 };
00119 
00120 /*
00121  * A interface which specifies an edit operation for Geometries.
00122  */
00123 class GeometryEditorOperation {
00124 public:
00134         virtual Geometry* edit(const Geometry *geometry, const GeometryFactory *factory)=0;
00135 };
00136 
00137 /*
00138  * A GeometryEditorOperation which modifies the coordinate list of a
00139  * Geometry.
00140  * Operates on Geometry subclasses which contains a single coordinate list.
00141  */
00142 class CoordinateOperation: public GeometryEditorOperation {
00143 public:
00144         virtual Geometry* edit(const Geometry *geometry, const GeometryFactory *factory);
00152         virtual CoordinateSequence* edit(const CoordinateSequence* coordinates, const Geometry *geometry)=0;
00153 };
00154 
00155 class gfCoordinateOperation: public CoordinateOperation {
00156 public:
00157         virtual CoordinateSequence* edit(const CoordinateSequence *coordinates, const Geometry *geometry);
00158 };
00159 
00160 
00161 /*
00162  * Supports creating a new Geometry which is a modification of an existing one.
00163  * Geometry objects are intended to be treated as immutable.
00164  * This class allows you to "modify" a Geometry
00165  * by traversing it and creating a new Geometry with the same overall
00166  * structure but possibly modified components.
00167  *
00168  * The following kinds of modifications can be made:
00169  *
00170  * - the values of the coordinates may be changed.
00171  *   Changing coordinate values may make the result Geometry invalid;
00172  *   this is not checked by the GeometryEditor
00173  * - the coordinate lists may be changed
00174  *   (e.g. by adding or deleting coordinates).
00175  * The modifed coordinate lists must be consistent with their original parent component
00176  * (e.g. a LinearRing must always have at least 4 coordinates, and the first and last
00177  * coordinate must be equal)
00178  * <li>components of the original geometry may be deleted
00179  * (e.g. holes may be removed from a Polygon, or LineStrings removed from a MultiLineString).
00180  * Deletions will be propagated up the component tree appropriately.
00181  * </ul>
00182  * Note that all changes must be consistent with the original Geometry's structure
00183  * (e.g. a Polygon cannot be collapsed into a LineString).
00184  * <p>
00185  * The resulting Geometry is not checked for validity.
00186  * If validity needs to be enforced, the new Geometry's #isValid should be checked.
00187  *
00188  * @see Geometry#isValid
00189  *
00190  */
00191 class GeometryEditor {
00192 private:
00196         const GeometryFactory* factory;
00197         Polygon* editPolygon(const Polygon *polygon, GeometryEditorOperation *operation);
00198         GeometryCollection* editGeometryCollection(const GeometryCollection *collection,GeometryEditorOperation *operation);
00199 public:
00204         GeometryEditor();
00211         GeometryEditor(const GeometryFactory *newFactory);
00221         Geometry* edit(const Geometry *geometry, GeometryEditorOperation *operation);
00222 };
00223 
00224 
00225 }
00226 #endif

Generated on Mon Aug 6 22:04:47 2007 for GEOS by  doxygen 1.4.7