⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geometry.cpp

📁 一个很好的vc底层代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if (DefaultCoordinateSequenceFactory::instance()==factory->getCoordinateSequenceFactory()) {		return (Geometry*)g;	}	return getFactory()->createGeometry(g);}/***  Returns a buffer region around this <code>Geometry</code> having the given*  width and with a specified number of segments used to approximate curves.* The buffer of a Geometry is the Minkowski sum of the Geometry with* a disc of radius <code>distance</code>.  Curves in the buffer polygon are* approximated with line segments.  This method allows specifying the* accuracy of that approximation.**@param  distance  the width of the buffer, interpreted according to the*      <code>PrecisionModel</code> of the <code>Geometry</code>*@param quadrantSegments the number of segments to use to approximate a quadrant of a circle*@return           all points whose distance from this <code>Geometry</code>*      are less than or equal to <code>distance</code>*/Geometry* Geometry::buffer(double distance,int quadrantSegments) const {	Geometry *in = toInternalGeometry(this);	Geometry *out = BufferOp::bufferOp(in, distance, quadrantSegments);	if ( in != this )
		delete(in);	Geometry *ret = fromInternalGeometry(out);	if ( out != ret ) 
		delete(out);	return ret;}Geometry*Geometry::convexHull() const{	Geometry *in = toInternalGeometry(this);	ConvexHull *ch = new ConvexHull(in);	Geometry *out=ch->getConvexHull();
	delete ch;	if ( in != this ) 
		delete(in);	Geometry *ret = fromInternalGeometry(out);	if ( out != ret ) 
		delete(out);	return ret;}Geometry* Geometry::intersection(const Geometry *other) const {	checkNotGeometryCollection(this);	checkNotGeometryCollection(other);	Geometry *in1 = toInternalGeometry(this);	Geometry *in2 = toInternalGeometry(other);	Geometry *out = NULL;	try {		out = OverlayOp::overlayOp(in1,in2,OverlayOp::INTERSECTION);	}	catch (...) {		if ( in1 != this )
			delete (in1);		if ( in2 != other ) 
			delete (in2);		throw;	}	if ( in1 != this ) 
		delete (in1);	if ( in2 != other )
		delete (in2);	Geometry *ret = fromInternalGeometry(out);	if ( ret != out )
		delete (out);	return ret;}Geometry*Geometry::Union(const Geometry *other)const	//throw(TopologyException *, IllegalArgumentException *){	checkNotGeometryCollection(this);	checkNotGeometryCollection(other);	Geometry *out = NULL;#ifdef SHORTCIRCUIT_PREDICATES	// if envelopes are disjoint return a MULTI geom or	// a geometrycollection	if ( ! getEnvelopeInternal()->intersects(other->getEnvelopeInternal()) )	{//cerr<<"SHORTCIRCUITED-UNION engaged"<<endl;		const GeometryCollection *coll;		int ngeoms, i;		vector<Geometry *> *v = new vector<Geometry *>();		if ( coll = dynamic_cast<const GeometryCollection *>(this) )		{			ngeoms = coll->getNumGeometries();			for (i=0; i<ngeoms; i++)				v->push_back(coll->getGeometryN(i)->clone());		} 
		else {			v->push_back(this->clone());		}		if ( coll = dynamic_cast<const GeometryCollection *>(other) )		{			ngeoms = coll->getNumGeometries();			for (i=0; i<ngeoms; i++)				v->push_back(coll->getGeometryN(i)->clone());		} 
		else {			v->push_back(other->clone());		}		out = factory->buildGeometry(v);		return out;	}#endif	Geometry *in1 = toInternalGeometry(this);	Geometry *in2 = toInternalGeometry(other);	try {		out = OverlayOp::overlayOp(in1,in2,OverlayOp::UNION);	}	catch (...) {		if ( in1 != this ) delete (in1);		if ( in2 != other ) delete (in2);		throw;	}	if ( in1 != this ) delete (in1);	if ( in2 != other ) delete (in2);	Geometry *ret = fromInternalGeometry(out);	if ( ret != out )
		delete (out);	return ret;}Geometry*Geometry::difference(const Geometry *other) const	//throw(IllegalArgumentException *){	checkNotGeometryCollection(this);	checkNotGeometryCollection(other);	Geometry *in1 = toInternalGeometry(this);	Geometry *in2 = toInternalGeometry(other);	Geometry *out = NULL;	try {		out = OverlayOp::overlayOp(in1,in2,OverlayOp::DIFFERENCE);	}	catch (...) {		if ( in1 != this ) 
			delete (in1);		if ( in2 != other ) 
			delete (in2);		throw;	}	if ( in1 != this )
		delete (in1);	if ( in2 != other )
		delete (in2);	Geometry *ret = fromInternalGeometry(out);	if ( ret != out ) 
		delete (out);	return ret;}Geometry* Geometry::symDifference(const Geometry *other) const {	checkNotGeometryCollection(this);	checkNotGeometryCollection(other);	Geometry *in1 = toInternalGeometry(this);	Geometry *in2 = toInternalGeometry(other);	Geometry *out = NULL;	try {		out = OverlayOp::overlayOp(in1,in2,OverlayOp::SYMDIFFERENCE);	}	catch (...) {		if ( in1 != this ) delete (in1);		if ( in2 != other ) delete (in2);		throw;	}	if ( in1 != this ) delete (in1);	if ( in2 != other ) delete (in2);	Geometry *ret = fromInternalGeometry(out);	if ( ret != out ) delete (out);	return ret;}int Geometry::compareTo(const Geometry *geom) const {	if (getClassSortIndex()!=geom->getClassSortIndex()) {		return getClassSortIndex()-geom->getClassSortIndex();	}	if (isEmpty() && geom->isEmpty()) {		return 0;	}	if (isEmpty()) {		return -1;	}	if (geom->isEmpty()) {		return 1;	}	return compareToSameClass(geom);}bool Geometry::isEquivalentClass(const Geometry *other) const {	if (typeid(*this)==typeid(*other))		return true;	else		return false;}voidGeometry::checkNotGeometryCollection(const Geometry *g)	//throw(IllegalArgumentException *){	if ((typeid(*g)==typeid(GeometryCollection))) {		throw new IllegalArgumentException("This method does not support GeometryCollection arguments\n");	}}int Geometry::getClassSortIndex() const {	//const type_info &t=typeid(*this);	     if ( typeid(*this) == typeid(Point)              ) return 0;	else if ( typeid(*this) == typeid(MultiPoint)         ) return 1;	else if ( typeid(*this) == typeid(LineString)         ) return 2;	else if ( typeid(*this) == typeid(LinearRing)         ) return 3;	else if ( typeid(*this) == typeid(MultiLineString)    ) return 4;	else if ( typeid(*this) == typeid(Polygon)            ) return 5;	else if ( typeid(*this) == typeid(MultiPolygon)       ) return 6;	else if ( typeid(*this) == typeid(GeometryCollection) ) return 7;	string str="Class not supported: ";	str.append(typeid(*this).name());	str.append("");	Assert::shouldNeverReachHere(str);	return -1;}int Geometry::compare(vector<Coordinate> a, vector<Coordinate> b) const {	unsigned int i=0;	unsigned int j=0;	while (i<a.size() && j<b.size()) {		Coordinate& aCoord=a[i];		Coordinate& bCoord=b[j];		int comparison=aCoord.compareTo(bCoord);		if (comparison!=0) {			return comparison;		}		i++;		j++;	}	if (i<a.size()) {		return 1;	}	if (j<b.size()) {		return -1;	}	return 0;}int Geometry::compare(vector<Geometry *> a, vector<Geometry *> b) const {	unsigned int i=0;	unsigned int j=0;	while (i<a.size() && j<b.size()) {		Geometry *aGeom=a[i];		Geometry *bGeom=b[j];		int comparison=aGeom->compareTo(bGeom);		if (comparison!=0) {			return comparison;		}		i++;		j++;	}	if (i<a.size()) {		return 1;	}	if (j<b.size()) {		return -1;	}	return 0;}/** *  Returns the minimum distance between this Geometry *  and the other Geometry  * * @param  other  the Geometry from which to compute the distance */double Geometry::distance(const Geometry *other) const {	Geometry *in1 = toInternalGeometry(this);	Geometry *in2 = toInternalGeometry(other);	double ret;	try {		ret = DistanceOp::distance(in1,in2);	}	catch (...) {		if ( in1 != this )
			delete (in1);		if ( in2 != other )
			delete (in2);		throw;	}	if ( in1 != this ) 
		delete (in1);	if ( in2 != other )
		delete (in2);	return ret;}/***  Returns the area of this <code>Geometry</code>.*  Areal Geometries have a non-zero area.*  They override this function to compute the area.*  Others return 0.0** @return the area of the Geometry*/double Geometry::getArea() const {	return 0.0;}/***  Returns the length of this <code>Geometry</code>.*  Linear geometries return their length.*  Areal geometries return their perimeter.*  They override this function to compute the area.*  Others return 0.0**@return the length of the Geometry*/double Geometry::getLength() const {	return 0.0;}Geometry::~Geometry(){	//delete factory;	delete envelope;	//delete userData; /* TODO: make this a Template type (not void*) */}bool lessThen(Coordinate& a, Coordinate& b) {	if (a.compareTo(b)<=0)		return true;	else		return false;}bool greaterThen(Geometry *first, Geometry *second) {	if (first->compareTo(second)>=0)		return true;	else		return false;}boolGeometry::equal(const Coordinate& a, const Coordinate& b,double tolerance) const{	if (tolerance==0) {
		return a==b;
	}	return a.distance(b)<=tolerance;}void Geometry::apply_ro(GeometryFilter *filter) const {	filter->filter_ro(this);}void Geometry::apply_rw(GeometryFilter *filter) {	filter->filter_rw(this);}void Geometry::apply_ro(GeometryComponentFilter *filter) const {	filter->filter_ro(this);}void Geometry::apply_rw(GeometryComponentFilter *filter) {	filter->filter_rw(this);}Point* Geometry::createPointFromInternalCoord(const Coordinate* coord,const Geometry *exemplar) const{	Coordinate newcoord = *coord;	exemplar->getPrecisionModel()->makePrecise(&newcoord);	return exemplar->getFactory()->createPoint(newcoord);}} // namespace geos/********************************************************************** * $Log: Geometry.cpp,v $ * Revision 1.72.2.2  2005/06/22 00:46:53  strk * Shortcircuit tests for Union * * Revision 1.72.2.1  2005/05/24 07:26:40  strk * back-ported segfault fix in EMPTYGEOM::getCentroid() * * Revision 1.72  2004/11/17 08:13:16  strk * Indentation changes. * Some Z_COMPUTATION activated by default. * * Revision 1.71  2004/09/16 09:48:40  strk * Finer short-circuit tests for equals, within, contains. * * Revision 1.70  2004/09/16 07:32:15  strk * Added short-circuit tests. Can be disabled at compile-time * * Revision 1.69  2004/07/27 16:35:46  strk * Geometry::getEnvelopeInternal() changed to return a const Envelope *. * This should reduce object copies as once computed the envelope of a * geometry remains the same. * * Revision 1.68  2004/07/22 16:58:01  strk * runtime version extractor functions split. geos::version() is now * geos::geosversion() and geos::jtsport() * * Revision 1.67  2004/07/21 09:55:24  strk * CoordinateSequence::atLeastNCoordinatesOrNothing definition fix. * Documentation fixes. * * Revision 1.66  2004/07/20 08:34:18  strk * Fixed a bug in opDistance.h. * Removed doxygen tags from obsoleted CoordinateList.cpp. * Got doxygen to run with no warnings. * * Revision 1.65  2004/07/19 13:19:30  strk * Documentation fixes * * Revision 1.64  2004/07/17 10:48:04  strk * fixed typo in documentation * * Revision 1.63  2004/07/17 09:18:54  strk * Added geos::version() * * Revision 1.62  2004/07/14 21:20:58  strk * Added GeometricShapeFactory note on doxygen mainpage * * Revision 1.61  2004/07/08 19:34:49  strk * Mirrored JTS interface of CoordinateSequence, factory and * default implementations. * Added DefaultCoordinateSequenceFactory::instance() function. * * Revision 1.60  2004/07/07 09:38:12  strk * Dropped WKTWriter::stringOfChars (implemented by std::string). * Dropped WKTWriter default constructor (internally created GeometryFactory). * Updated XMLTester to respect the changes. * Main documentation page made nicer. * * Revision 1.59  2004/07/06 17:58:21  strk * Removed deprecated Geometry constructors based on PrecisionModel and * SRID specification. Removed SimpleGeometryPrecisionReducer capability * of changing Geometry's factory. Reverted Geometry::factory member * to be a reference to external factory. * * Revision 1.58  2004/07/05 19:40:48  strk * Added GeometryFactory::destroyGeometry(Geometry *) * * Revision 1.57  2004/07/05 15:20:18  strk * Documentation again. * * Revision 1.56  2004/07/05 10:50:20  strk * deep-dopy construction taken out of Geometry and implemented only * in GeometryFactory. * Deep-copy geometry construction takes care of cleaning up copies * on exception. * Implemented clone() method for CoordinateSequence * Changed createMultiPoint(CoordinateSequence) signature to reflect * copy semantic (by-ref instead of by-pointer). * Cleaned up documentation. * * Revision 1.55  2004/07/03 12:51:37  strk * Documentation cleanups for DoxyGen. * * Revision 1.54  2004/07/02 13:28:26  strk * Fixed all #include lines to reflect headers layout change. * Added client application build tips in README. * * Revision 1.53  2004/07/01 17:34:07  strk * GeometryFactory argument in Geometry constructor reverted * to its copy-and-destroy semantic. * * Revision 1.52  2004/07/01 14:12:44  strk * * Geometry constructors come now in two flavors: * 	- deep-copy args (pass-by-reference) * 	- take-ownership of args (pass-by-pointer) * Same functionality is available through GeometryFactory, * including buildGeometry(). * * Revision 1.51  2004/06/30 20:59:12  strk * Removed GeoemtryFactory copy from geometry constructors. * Enforced const-correctness on GeometryFactory arguments. * * Revision 1.50  2004/05/21 13:58:47  strk * ::intersection missed to invalidate geometryCollection inputs * * Revision 1.49  2004/05/17 07:23:05  strk * ::getCeontroid(): reduced dynamic allocations, added missing check for isEmpty * * Revision 1.48  2004/05/14 12:14:08  strk * const correctness * * Revision 1.47  2004/05/07 09:05:13  strk * Some const correctness added. Fixed bug in GeometryFactory::createMultiPoint * to handle NULL CoordinateSequence. * * Revision 1.46  2004/05/05 16:51:29  strk * avoided copy constructor in Geometry::geometryChangedFilter initializzazion * * Revision 1.45  2004/05/05 10:54:48  strk * Removed some private static heap explicit allocation, less cleanup done by * the unloader. * * Revision 1.44  2004/04/30 09:15:28  strk * Enlarged exception specifications to allow for AssertionFailedException. * Added missing initializers. * * Revision 1.43  2004/04/20 10:14:20  strk * Memory leaks removed. * * Revision 1.42  2004/04/14 13:56:26  strk * All geometries returned by {from,to}InternalGeometry calls are * now deleted after use (unless NOT new). * Some 'commented' throw specifications in geom.h * * Revision 1.41  2004/04/14 07:29:43  strk * Fixed GeometryFactory constructors to copy given PrecisionModel. Added GeometryFactory copy constructor. Fixed Geometry constructors to copy GeometryFactory. * * Revision 1.40  2004/04/01 10:44:33  ybychkov * All "geom" classes from JTS 1.3 upgraded to JTS 1.4 * * Revision 1.39  2004/03/17 02:00:33  ybychkov * "Algorithm" upgraded to JTS 1.4 * * Revision 1.38  2004/03/01 22:04:59  strk * applied const correctness changes by Manuel Prieto Villegas <ManuelPrietoVillegas@telefonica.net> * * Revision 1.37  2003/11/07 01:23:42  pramsey * Add standard CVS headers licence notices and copyrights to all cpp and h * files. * * Revision 1.36  2003/10/20 15:41:34  strk * Geometry::checkNotGeometryCollection made static and non-distructive. * * Revision 1.35  2003/10/13 12:51:28  strk * removed sortedClasses strings array from all geometries. * **********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -