Added fromMultiPoint method to QgsGeometry

git-svn-id: http://svn.osgeo.org/qgis/trunk@8041 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2008-01-25 07:03:59 +00:00
parent 671a782505
commit c39d6a90ce
3 changed files with 38 additions and 0 deletions

View File

@ -39,6 +39,8 @@ class QgsGeometry
/** construct geometry from a point */
static QgsGeometry* fromPoint(const QgsPoint& point) /Factory/;
/** construct geometry from a multipoint */
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint) /Factory/;
/** construct geometry from a polyline */
static QgsGeometry* fromPolyline(const QgsPolyline& polyline) /Factory/;
/** construct geometry from a multipolyline*/

View File

@ -125,6 +125,40 @@ QgsGeometry* QgsGeometry::fromPoint(const QgsPoint& point)
return g;
}
QgsGeometry* QgsGeometry::fromMultiPoint(const QgsMultiPoint& multipoint)
{
std::vector<GEOS_GEOM::Geometry*>* pointVector = new std::vector<GEOS_GEOM::Geometry*>(multipoint.size());
GEOS_GEOM::Coordinate currentCoord;
for(int i = 0; i < multipoint.size(); ++i)
{
currentCoord.x = multipoint.at(i).x();
currentCoord.y = multipoint.at(i).y();
try
{
(*pointVector)[i] = geosGeometryFactory->createPoint(currentCoord);
}
catch(GEOS_UTIL::GEOSException* e)
{
delete e; delete pointVector; return 0;
}
}
GEOS_GEOM::Geometry* geom = 0;
try
{
geom = geosGeometryFactory->createMultiPoint(pointVector);
}
catch(GEOS_UTIL::GEOSException* e)
{
delete e; return 0;
}
QgsGeometry* g = new QgsGeometry;
g->setGeos(geom);
return g;
}
QgsGeometry* QgsGeometry::fromPolyline(const QgsPolyline& polyline)
{
const GEOS_GEOM::CoordinateSequenceFactory* seqFactory = GEOS_GEOM::COORD_SEQ_FACTORY::instance();

View File

@ -112,6 +112,8 @@ class CORE_EXPORT QgsGeometry {
/** construct geometry from a point */
static QgsGeometry* fromPoint(const QgsPoint& point);
/** construct geometry from a multipoint */
static QgsGeometry* fromMultiPoint(const QgsMultiPoint& multipoint);
/** construct geometry from a polyline */
static QgsGeometry* fromPolyline(const QgsPolyline& polyline);
/** construct geometry from a multipolyline*/