GEOS: opDistance.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# opDistance.h

    00001 /**********************************************************************
    00002  * $Id: opDistance.h,v 1.4 2004/07/20 08:34:18 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: opDistance.h,v $
    00016  * Revision 1.4  2004/07/20 08:34:18  strk
    00017  * Fixed a bug in opDistance.h.
    00018  * Removed doxygen tags from obsoleted CoordinateList.cpp.
    00019  * Got doxygen to run with no warnings.
    00020  *
    00021  * Revision 1.3  2004/07/19 13:19:31  strk
    00022  * Documentation fixes
    00023  *
    00024  * Revision 1.2  2004/07/08 19:34:49  strk
    00025  * Mirrored JTS interface of CoordinateSequence, factory and
    00026  * default implementations.
    00027  * Added DefaultCoordinateSequenceFactory::instance() function.
    00028  *
    00029  * Revision 1.1  2004/07/02 13:20:42  strk
    00030  * Header files moved under geos/ dir.
    00031  *
    00032  * Revision 1.10  2004/05/14 13:42:46  strk
    00033  * DistanceOp bug removed, cascading errors fixed.
    00034  *
    00035  * Revision 1.9  2004/04/13 12:29:21  strk
    00036  * GeometryLocation const-correctness.
    00037  *
    00038  * Revision 1.8  2004/04/13 10:05:51  strk
    00039  * GeometryLocation constructor made const-correct.
    00040  * Fixed erroneus down-casting in DistanceOp::computeMinDistancePoints.
    00041  *
    00042  * Revision 1.7  2004/04/05 06:35:14  ybychkov
    00043  * "operation/distance" upgraded to JTS 1.4
    00044  *
    00045  * Revision 1.6  2003/11/07 01:23:42  pramsey
    00046  * Add standard CVS headers licence notices and copyrights to all cpp and h
    00047  * files.
    00048  *
    00049  *
    00050  **********************************************************************/
    00051
    00052
    00053 #ifndef GEOS_OPDISTANCE_H
    00054 #define GEOS_OPDISTANCE_H
    00055
    00056 #include <memory>
    00057 #include <geos/platform.h>
    00058 #include <geos/operation.h>
    00059 #include <geos/geom.h>
    00060 #include <vector>
    00061
    00062 namespace geos {
    00063
    00064
    00065 /*
    00066  * Represents the location of a point on a Geometry.
    00067  * Maintains both the actual point location (which of course
    00068  * may not be exact) as well as information about the component
    00069  * and segment index where the point occurs.
    00070  * Locations inside area Geometrys will not have an associated segment index,
    00071  * so in this case the segment index will have the sentinel value of
    00072  * INSIDE_AREA.
    00073  */
    00074 class GeometryLocation {
    00075 private:
    00076         const Geometry *component;
    00077         int segIndex;
    00078         Coordinate pt;
    00079 public:
    00084         static const int INSIDE_AREA = -1;
    00089         GeometryLocation(const Geometry *newComponent, int newSegIndex, const Coordinate &newPt);
    00093         GeometryLocation(const Geometry *newComponent, const Coordinate &newPt);
    00097         const Geometry* getGeometryComponent();
    00104         int getSegmentIndex();
    00108         Coordinate& getCoordinate();
    00112         bool isInsideArea();
    00113 };
    00114
    00115
    00116 /*
    00117  * Extracts a single point
    00118  * from each connected element in a Geometry
    00119  * (e.g. a polygon, linestring or point)
    00120  * and returns them in a list
    00121  */
    00122 class ConnectedElementPointFilter: public GeometryFilter {
    00123 public:
    00129         static vector<const Coordinate*>* getCoordinates(const Geometry *geom);
    00130         ConnectedElementPointFilter(vector<const Coordinate*> *newPts);
    00131         void filter_ro(const Geometry *geom);
    00132         void filter_rw(Geometry *geom) {};
    00133 private:
    00134         vector<const Coordinate*> *pts;
    00135 };
    00136
    00137 /*
    00138  * A ConnectedElementPointFilter extracts a single point
    00139  * from each connected element in a Geometry
    00140  * (e.g. a polygon, linestring or point)
    00141  * and returns them in a list. The elements of the list are
    00142  * DistanceOp::GeometryLocation.
    00143  */
    00144 class ConnectedElementLocationFilter: public GeometryFilter {
    00145 private:
    00146         vector<GeometryLocation*> *locations;
    00147 public:
    00154         static vector<GeometryLocation*>* getLocations(const Geometry *geom);
    00155         ConnectedElementLocationFilter(vector<GeometryLocation*> *newLocations);
    00156         void filter_ro(const Geometry *geom);
    00157         void filter_rw(Geometry *geom);
    00158 };
    00159
    00160
    00161 /*
    00162  * Computes the distance and
    00163  * closest points between two {@link Geometry}s.
    00164  * <p>
    00165  * The distance computation finds a pair of points in the input geometries
    00166  * which have minimum distance between them.  These points may
    00167  * not be vertices of the geometries, but may lie in the interior of
    00168  * a line segment. In this case the coordinate computed is a close
    00169  * approximation to the exact point.
    00170  * <p>
    00171  * The algorithms used are straightforward O(n^2)
    00172  * comparisons.  This worst-case performance could be improved on
    00173  * by using Voronoi techniques.
    00174  *
    00175  */
    00176 class DistanceOp {
    00177 public:
    00184         static double distance(const Geometry *g0, const Geometry *g1);
    00193         static CoordinateSequence* closestPoints(Geometry *g0,Geometry *g1);
    00198         DistanceOp(const Geometry *g0, const Geometry *g1);
    00199         ~DistanceOp();
    00205         double distance();
    00212         CoordinateSequence* closestPoints();
    00219         vector<GeometryLocation*>* closestLocations();
    00220 private:
    00221         PointLocator ptLocator;
    00222         vector<Geometry const*> geom;
    00223         vector<Coordinate *> newCoords;
    00224         vector<GeometryLocation*> *minDistanceLocation;
    00225         double minDistance;
    00226         void updateMinDistance(double dist);
    00227         void updateMinDistance(vector<GeometryLocation*> *locGeom, bool flip);
    00228         void computeMinDistance();
    00229         void computeContainmentDistance();
    00230         void computeInside(vector<GeometryLocation*> *locs,vector<Geometry*> *polys,vector<GeometryLocation*> *locPtPoly);
    00231         void computeInside(GeometryLocation *ptLoc,Polygon *poly,vector<GeometryLocation*> *locPtPoly);
    00232         void computeLineDistance();
    00233         void computeMinDistanceLines(vector<Geometry*> *lines0,vector<Geometry*> *lines1,vector<GeometryLocation*> *locGeom);
    00234         void computeMinDistancePoints(vector<Geometry*> *points0,vector<Geometry*> *points1,vector<GeometryLocation*> *locGeom);
    00235         void computeMinDistanceLinesPoints(vector<Geometry*> *lines,vector<Geometry*> *points,vector<GeometryLocation*> *locGeom);
    00236         void computeMinDistance(const LineString *line0, const LineString *line1,vector<GeometryLocation*> *locGeom);
    00237         void computeMinDistance(const LineString *line, const Point *pt,vector<GeometryLocation*> *locGeom);
    00238 };
    00239 }
    00240 #endif