1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
/**********************************************************************
* $Id: Point.cpp 1921 2006-11-23 20:17:43Z strk $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2001-2002 Vivid Solutions Inc.
* Copyright (C) 2005 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#include <geos/util/UnsupportedOperationException.h>
#include <geos/util/IllegalArgumentException.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Point.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/GeometryFilter.h>
#include <geos/geom/GeometryComponentFilter.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Dimension.h>
#include <geos/geom/Envelope.h>
#include <geos/geom/GeometryCollection.h>
#include <geos/geom/GeometryFactory.h>
#include <string>
#include <memory>
using namespace std;
namespace geos {
namespace geom { // geos::geom
/*protected*/
Point::Point(CoordinateSequence *newCoords, const GeometryFactory *factory)
:
Geometry(factory),
coordinates(newCoords)
{
if (coordinates.get()==NULL) {
coordinates.reset(factory->getCoordinateSequenceFactory()->create(NULL));
return;
}
if (coordinates->getSize() != 1)
{
throw util::IllegalArgumentException("Point coordinate list must contain a single element");
}
}
/*protected*/
Point::Point(const Point &p)
:
Geometry(p.getFactory()),
coordinates(p.coordinates->clone())
{
}
CoordinateSequence *
Point::getCoordinates() const
{
return coordinates->clone();
}
size_t
Point::getNumPoints() const
{
return isEmpty() ? 0 : 1;
}
bool
Point::isEmpty() const
{
return coordinates->isEmpty();
}
bool
Point::isSimple() const
{
return true;
}
//bool Point::isValid() const {return true;}
Dimension::DimensionType
Point::getDimension() const
{
return Dimension::P; // point
}
int
Point::getBoundaryDimension() const
{
return Dimension::False;
}
double
Point::getX() const
{
if (isEmpty()) {
throw util::UnsupportedOperationException("getX called on empty Point\n");
}
return getCoordinate()->x;
}
double
Point::getY() const
{
if (isEmpty()) {
throw util::UnsupportedOperationException("getY called on empty Point\n");
}
return getCoordinate()->y;
}
const Coordinate *
Point::getCoordinate() const
{
return coordinates->getSize()!=0 ? &(coordinates->getAt(0)) : NULL;
}
string
Point::getGeometryType() const
{
return "Point";
}
Geometry *
Point::getBoundary() const
{
return getFactory()->createGeometryCollection(NULL);
}
Envelope::AutoPtr
Point::computeEnvelopeInternal() const
{
if (isEmpty()) {
return Envelope::AutoPtr(new Envelope());
}
return Envelope::AutoPtr(new Envelope(getCoordinate()->x,
getCoordinate()->x, getCoordinate()->y,
getCoordinate()->y));
}
void
Point::apply_ro(CoordinateFilter *filter) const
{
if (isEmpty()) {return;}
filter->filter_ro(getCoordinate());
}
void
Point::apply_rw(const CoordinateFilter *filter)
{
if (isEmpty()) {return;}
Coordinate newcoord = coordinates->getAt(0);
filter->filter_rw(&newcoord);
coordinates->setAt(newcoord, 0);
}
void
Point::apply_rw(GeometryFilter *filter)
{
filter->filter_rw(this);
}
void
Point::apply_ro(GeometryFilter *filter) const
{
filter->filter_ro(this);
}
void
Point::apply_rw(GeometryComponentFilter *filter)
{
filter->filter_rw(this);
}
void
Point::apply_ro(GeometryComponentFilter *filter) const
{
filter->filter_ro(this);
}
bool
Point::equalsExact(const Geometry *other, double tolerance) const
{
if (!isEquivalentClass(other)) {
return false;
}
// assume the isEquivalentClass would return false
// if other is not a point
assert(dynamic_cast<const Point*>(other));
if ( isEmpty() ) return other->isEmpty();
else if ( other->isEmpty() ) return false;
const Coordinate* this_coord = getCoordinate();
const Coordinate* other_coord = other->getCoordinate();
// assume the isEmpty checks above worked :)
assert(this_coord && other_coord);
return equal(*this_coord, *other_coord, tolerance);
}
int
Point::compareToSameClass(const Geometry *point) const
{
return getCoordinate()->compareTo(*(((Point*)point)->getCoordinate()));
}
Point::~Point()
{
//delete coordinates;
}
GeometryTypeId
Point::getGeometryTypeId() const
{
return GEOS_POINT;
}
/*public*/
const CoordinateSequence*
Point::getCoordinatesRO() const
{
return coordinates.get();
}
} // namespace geos::geom
} // namesapce geos
/**********************************************************************
*
* $Log$
* Revision 1.46 2006/05/04 15:49:39 strk
* updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93)
*
* Revision 1.45 2006/04/28 10:55:39 strk
* Geometry constructors made protected, to ensure all constructions use GeometryFactory,
* which has been made friend of all Geometry derivates. getNumPoints() changed to return
* size_t.
*
* Revision 1.44 2006/04/10 18:15:09 strk
* Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
* Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
*
* Revision 1.43 2006/04/10 17:35:44 strk
* Changed LineString::points and Point::coordinates to be wrapped
* in an auto_ptr<>. This should close bugs #86 and #89
*
* Revision 1.42 2006/03/22 16:58:34 strk
* Removed (almost) all inclusions of geom.h.
* Removed obsoleted .cpp files.
* Fixed a bug in WKTReader not using the provided CoordinateSequence
* implementation, optimized out some memory allocations.
*
* Revision 1.41 2006/03/09 16:46:47 strk
* geos::geom namespace definition, first pass at headers split
*
* Revision 1.40 2006/03/06 19:40:46 strk
* geos::util namespace. New GeometryCollection::iterator interface, many cleanups.
*
* Revision 1.39 2006/03/03 10:46:21 strk
* Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
*
* Revision 1.38 2006/02/09 15:52:47 strk
* GEOSException derived from std::exception; always thrown and cought by const ref.
*
* Revision 1.37 2006/01/31 19:07:33 strk
* - Renamed DefaultCoordinateSequence to CoordinateArraySequence.
* - Moved GetNumGeometries() and GetGeometryN() interfaces
* from GeometryCollection to Geometry class.
* - Added getAt(int pos, Coordinate &to) funtion to CoordinateSequence class.
* - Reworked automake scripts to produce a static lib for each subdir and
* then link all subsystem's libs togheter
* - Moved C-API in it's own top-level dir capi/
* - Moved source/bigtest and source/test to tests/bigtest and test/xmltester
* - Fixed PointLocator handling of LinearRings
* - Changed CoordinateArrayFilter to reduce memory copies
* - Changed UniqueCoordinateArrayFilter to reduce memory copies
* - Added CGAlgorithms::isPointInRing() version working with
* Coordinate::ConstVect type (faster!)
* - Ported JTS-1.7 version of ConvexHull with big attention to
* memory usage optimizations.
* - Improved XMLTester output and user interface
* - geos::geom::util namespace used for geom/util stuff
* - Improved memory use in geos::geom::util::PolygonExtractor
* - New ShortCircuitedGeometryVisitor class
* - New operation/predicate package
*
* Revision 1.36 2005/12/08 14:14:07 strk
* ElevationMatrixFilter used for both elevation and Matrix fill,
* thus removing CoordinateSequence copy in ElevetaionMatrix::add(Geometry *).
* Changed CoordinateFilter::filter_rw to be a const method: updated
* all apply_rw() methods to take a const CoordinateFilter.
*
* Revision 1.35 2005/06/23 14:22:33 strk
* Inlined and added missing ::clone() for Geometry subclasses
*
* Revision 1.34 2005/05/23 16:42:43 strk
* Added Refractions copyright
*
* Revision 1.33 2005/05/13 17:15:34 strk
* cleanups and indentations
*
* Revision 1.32 2005/04/19 11:49:26 strk
* Fixed segfault in ::isEmpty
*
* Revision 1.31 2004/11/23 16:22:49 strk
* Added ElevationMatrix class and components to do post-processing draping of overlayed geometries.
*
* Revision 1.30 2004/09/13 12:39:14 strk
* Made Point and MultiPoint subject to Validity tests.
*
* Revision 1.29 2004/07/08 19:34:49 strk
* Mirrored JTS interface of CoordinateSequence, factory and
* default implementations.
* Added CoordinateArraySequenceFactory::instance() function.
*
**********************************************************************/
|