geometryfactory.cpp

来自「一个很好的vc底层代码」· C++ 代码 · 共 848 行 · 第 1/2 页

CPP
848
字号
/********************************************************************** * $Id: GeometryFactory.cpp,v 1.50.2.3 2005/06/22 00:46:34 strk Exp $ * * GEOS - Geometry Engine Open Source * http://geos.refractions.net * * Copyright (C) 2001-2002 Vivid Solutions Inc. * Copyright (C) 2005 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/geom.h>#include <geos/geomUtil.h>#include <geos/util.h>#include <typeinfo>namespace geos {/** * Constructs a GeometryFactory that generates Geometries having a floating * PrecisionModel and a spatial-reference ID of 0. */GeometryFactory::GeometryFactory() {	precisionModel=new PrecisionModel();	SRID=0;	coordinateListFactory=DefaultCoordinateSequenceFactory::instance();}/** * Constructs a GeometryFactory that generates Geometries having the given * PrecisionModel, spatial-reference ID, and CoordinateSequence implementation. */GeometryFactory::GeometryFactory(const PrecisionModel *pm, int newSRID,CoordinateSequenceFactory *nCoordinateSequenceFactory) {	precisionModel=new PrecisionModel(*pm);	coordinateListFactory=nCoordinateSequenceFactory;	SRID=newSRID;}/** * Constructs a GeometryFactory that generates Geometries having the given * CoordinateSequence implementation, a double-precision floating * PrecisionModel and a spatial-reference ID of 0. */GeometryFactory::GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory) {	precisionModel=new PrecisionModel();	SRID=0;	coordinateListFactory=nCoordinateSequenceFactory;}/*** Constructs a GeometryFactory that generates Geometries having the given* {@link PrecisionModel} and the default CoordinateSequence* implementation.** @param precisionModel the PrecisionModel to use*/GeometryFactory::GeometryFactory(const PrecisionModel *pm) {	precisionModel=new PrecisionModel(*pm);	SRID=0;	coordinateListFactory=DefaultCoordinateSequenceFactory::instance();}/** * Constructs a GeometryFactory that generates Geometries having the given * PrecisionModel and spatial-reference ID, and the default * CoordinateSequence implementation. * * @param precisionModel the PrecisionModel to use * @param SRID the SRID to use */GeometryFactory::GeometryFactory(const PrecisionModel* pm, int newSRID){    precisionModel=new PrecisionModel(*pm);    SRID=newSRID;	coordinateListFactory=DefaultCoordinateSequenceFactory::instance();}GeometryFactory::GeometryFactory(const GeometryFactory &gf){    precisionModel=new PrecisionModel(*(gf.precisionModel));    SRID=gf.SRID;    coordinateListFactory=gf.coordinateListFactory;}GeometryFactory::~GeometryFactory(){	delete precisionModel;}  Point*GeometryFactory::createPointFromInternalCoord(const Coordinate* coord,		const Geometry *exemplar) const {	Coordinate newcoord = *coord;	exemplar->getPrecisionModel()->makePrecise(&newcoord);	return exemplar->getFactory()->createPoint(newcoord);}/** * Converts an Envelope to a Geometry. * Returned Geometry can be a Point, a Polygon or an EMPTY geom. */Geometry*GeometryFactory::toGeometry(const Envelope* envelope) const{	Coordinate coord;	if (envelope->isNull()) {		return createPoint();	}	if (envelope->getMinX()==envelope->getMaxX() && envelope->getMinY()==envelope->getMaxY()) {		coord.x = envelope->getMinX();		coord.y = envelope->getMinY();		return createPoint(coord);	}	CoordinateSequence *cl=DefaultCoordinateSequenceFactory::instance()->create(NULL);	coord.x = envelope->getMinX();	coord.y = envelope->getMinY();	cl->add(coord);	coord.x = envelope->getMaxX();	coord.y = envelope->getMinY();	cl->add(coord);	coord.x = envelope->getMaxX();	coord.y = envelope->getMaxY();	cl->add(coord);	coord.x = envelope->getMinX();	coord.y = envelope->getMaxY();	cl->add(coord);	coord.x = envelope->getMinX();	coord.y = envelope->getMinY();	cl->add(coord);	Polygon *p = createPolygon(createLinearRing(cl), NULL);	return p;}/** * Returns the PrecisionModel that Geometries created by this factory * will be associated with. */const PrecisionModel* GeometryFactory::getPrecisionModel() const {	return precisionModel;}/** * Creates the EMPTY Point */Point*GeometryFactory::createPoint() const {	return new Point(NULL, this);}/*** Creates a Point using the given Coordinate; a null Coordinate will create* an empty Geometry.*/Point*GeometryFactory::createPoint(const Coordinate& coordinate) const {	if (coordinate==Coordinate::nullCoord) {		return createPoint();	} 
	else {		CoordinateSequence *cl=coordinateListFactory->create(new vector<Coordinate>(1, coordinate));		//cl->setAt(coordinate, 0);		Point *ret = createPoint(cl);		return ret;	}}/** * Creates a Point using the given CoordinateSequence (must have 1 element) * * @param  newCoords *	contains the single coordinate on which to base this *	<code>Point</code> or <code>null</code> to create *	the empty geometry. * *	If not null the created Point will take ownership of newCoords. */  Point*GeometryFactory::createPoint(CoordinateSequence *newCoords) const{	return new Point(newCoords,this);}/** * Creates a Point using the given CoordinateSequence (must have 1 element) * * @param  fromCoords *	contains the single coordinate on which to base this *	<code>Point</code>.  */Point*GeometryFactory::createPoint(const CoordinateSequence &fromCoords) const{	CoordinateSequence *newCoords = fromCoords.clone();	Point *g = NULL;	try {		g = new Point(newCoords,this); 	}
	catch (...) {		delete newCoords;		throw;	}	return g;}/** * Construct an EMPTY MultiLineString */MultiLineString*GeometryFactory::createMultiLineString() const{	return new MultiLineString(NULL,this);}/** * Constructs a <code>MultiLineString</code>. * * @param  newLines *	the <code>LineStrings</code>s for this *	<code>MultiLineString</code>, or <code>null</code> *	or an empty array to create the empty geometry. *	Elements may be empty <code>LineString</code>s, *	but not <code>null</code>s. * *	Constructed object will take ownership of *	the vector and its elements. */MultiLineString*GeometryFactory::createMultiLineString(vector<Geometry *> *newLines)	const{	return new MultiLineString(newLines,this);}/** * Constructs a <code>MultiLineString</code>. * * @param  fromLines *	the <code>LineStrings</code>s for this *	<code>MultiLineString</code>, or an empty array *	to create the empty geometry. *	Elements may be empty <code>LineString</code>s, *	but not <code>null</code>s. * *	Constructed object will copy  *	the vector and its elements. */MultiLineString*GeometryFactory::createMultiLineString(const vector<Geometry *> &fromLines)	const{	vector<Geometry *>*newGeoms = new vector<Geometry *>(fromLines.size());	for (unsigned int i=0; i<fromLines.size(); i++)	{		const LineString *line = dynamic_cast<const LineString *>(fromLines[i]);		if ( ! line ) 
			throw new IllegalArgumentException("createMultiLineString called with a vector containing non-LineStrings");		(*newGeoms)[i] = new LineString(*line);	}	MultiLineString *g = NULL;	try {		g = new MultiLineString(newGeoms,this);	}
	catch (...) {		for (unsigned int i=0; i<newGeoms->size(); i++) {			delete (*newGeoms)[i];		}		delete newGeoms;		throw;	}	return g;}/** * Constructs an EMPTY <code>GeometryCollection</code>. */GeometryCollection*GeometryFactory::createGeometryCollection() const{	return new GeometryCollection(NULL,this);}/** * Constructs a GeometryCollection. * * @param newGeoms *	The <code>Geometry</code>s for this *	<code>GeometryCollection</code>, *	or <code>null</code> or an empty array to *	create the empty geometry. *	Elements may be empty <code>Geometry</code>s, *	but not <code>null</code>s. * *	If construction succeed the created object will take *	ownership of newGeoms vector and elements. * *	If construction	fails "IllegalArgumentException *" *	is thrown and it is your responsibility to delete newGeoms *	vector and content. */GeometryCollection*GeometryFactory::createGeometryCollection(vector<Geometry *> *newGeoms) const{	return new GeometryCollection(newGeoms,this);}/** * @param fromGeoms *            the <code>Geometry</code>s for this *	     <code>GeometryCollection</code>, *	     Elements may be empty <code>Geometry</code>s, *            but not <code>null</code>s. *	      *            fromGeoms vector and elements will be copied.  */GeometryCollection*GeometryFactory::createGeometryCollection(const vector<Geometry *> &fromGeoms) const{	vector<Geometry *> *newGeoms = new vector<Geometry *>(fromGeoms.size());	for (unsigned int i=0; i<fromGeoms.size(); i++) {		(*newGeoms)[i] = fromGeoms[i]->clone();	}	GeometryCollection *g = NULL;	try {		g = new GeometryCollection(newGeoms,this);	} catch (...) {		for (unsigned int i=0; i<newGeoms->size(); i++) {			delete (*newGeoms)[i];		}		delete newGeoms;		throw;	}	return g;}/* * Create an EMPTY MultiPolygon */MultiPolygon*GeometryFactory::createMultiPolygon() const{	return new MultiPolygon(NULL,this);}/** * @param newPolys *	the <code>Polygon</code>s for this <code>MultiPolygon</code>, *	or <code>null</code> or an empty array to create the empty *	geometry. Elements may be empty <code>Polygon</code>s, but *	not <code>null</code>s. *	The polygons must conform to the assertions specified in the *	<A HREF="http://www.opengis.org/techno/specs.htm"> *	OpenGIS Simple Features Specification for SQL *	</A>. * *	Constructed object will take ownership of *	the vector and its elements. */MultiPolygon*GeometryFactory::createMultiPolygon(vector<Geometry *> *newPolys) const{	return new MultiPolygon(newPolys,this);}/** * @param fromPolys *	the <code>Polygon</code>s for this <code>MultiPolygon</code>, *	or an empty array to create the empty geometry. *	Elements may be empty <code>Polygon</code>s, but *	not <code>null</code>s. *	The polygons must conform to the assertions specified in the *	<A HREF="http://www.opengis.org/techno/specs.htm"> *	OpenGIS Simple Features Specification for SQL *	</A>. * *	Constructed object will copy  *	the vector and its elements. */MultiPolygon*GeometryFactory::createMultiPolygon(const vector<Geometry *> &fromPolys) const{	vector<Geometry *>*newGeoms = new vector<Geometry *>(fromPolys.size());	for (unsigned int i=0; i<fromPolys.size(); i++)	{		(*newGeoms)[i] = fromPolys[i]->clone();	}	MultiPolygon *g = NULL;	try {		g = new MultiPolygon(newGeoms,this);	} 
	catch (...) {		for (unsigned int i=0; i<newGeoms->size(); i++) {			delete (*newGeoms)[i];		}		delete newGeoms;		throw;	}	return g;} /** * Creates an EMPTY LinearRing  */LinearRing*GeometryFactory::createLinearRing() const{	return new LinearRing(NULL,this);}/** * Creates a LinearRing using the given CoordinateSequence; * a null or empty CoordinateSequence will * create an empty LinearRing. The points must form a closed and simple * linestring. Consecutive points must not be equal. * * @param newCoords a CoordinateSequence possibly empty, or null. * * LinearRing will take ownership of coordinates. *  */

⌨️ 快捷键说明

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