-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
212 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "extrude", | ||
"type": "function", | ||
"description": "Returns an extruded version of the input (Multi-)Curve or (Multi-)Linestring geometry with an extension specified by x and y.", | ||
"arguments": [ | ||
{"arg":"geom","description":"a polygon geometry"}, | ||
{"arg":"x","description":"x extension, numeric value"}, | ||
{"arg":"y","description":"y extension, numeric value"} | ||
], | ||
"examples": [ | ||
{ | ||
"expression":"extrude(geom_from_wkt('LineString(1 2, 3 2, 4 3)'), 1, 2)", | ||
"returns":"Polygon ((1 2, 3 2, 4 3, 5 5, 4 4, 2 4, 1 2))" | ||
}, | ||
{ | ||
"expression":"extrude(geom_from_wkt('MultiLineString((1 2, 3 2), (4 3, 8 3)'), 1, 2)", | ||
"returns":"MultiPolygon (((1 2, 3 2, 4 4, 2 4, 1 2)),((4 3, 8 3, 9 5, 5 5, 4 3)))" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*************************************************************************** | ||
qgsinternalgeometryengine.cpp - QgsInternalGeometryEngine | ||
--------------------- | ||
begin : 13.1.2016 | ||
copyright : (C) 2016 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsinternalgeometryengine.h" | ||
|
||
#include "qgslinestringv2.h" | ||
#include "qgsmultipolygonv2.h" | ||
#include "qgspolygonv2.h" | ||
#include "qgsmulticurvev2.h" | ||
|
||
#include <QTransform> | ||
|
||
QgsInternalGeometryEngine::QgsInternalGeometryEngine( const QgsGeometry& geometry ) | ||
: mGeometry( geometry.geometry() ) | ||
{ | ||
|
||
} | ||
|
||
/*************************************************************************** | ||
* This class is considered CRITICAL and any change MUST be accompanied with | ||
* full unit tests. | ||
* See details in QEP #17 | ||
****************************************************************************/ | ||
|
||
QgsGeometry QgsInternalGeometryEngine::extrude( double x, double y ) | ||
{ | ||
QList<QgsLineStringV2*> linesToProcess; | ||
|
||
const QgsMultiCurveV2* multiCurve = dynamic_cast< const QgsMultiCurveV2* >( mGeometry ); | ||
if ( multiCurve ) | ||
{ | ||
for ( int i = 0; i < multiCurve->partCount(); ++i ) | ||
{ | ||
linesToProcess << static_cast<QgsLineStringV2*>( multiCurve->geometryN( i )->clone() ); | ||
} | ||
} | ||
|
||
const QgsCurveV2* curve = dynamic_cast< const QgsCurveV2* >( mGeometry ); | ||
if ( curve ) | ||
{ | ||
linesToProcess << static_cast<QgsLineStringV2*>( curve->segmentize() ); | ||
} | ||
|
||
QgsMultiPolygonV2* multipolygon = linesToProcess.size() > 1 ? new QgsMultiPolygonV2() : nullptr; | ||
QgsPolygonV2* polygon; | ||
|
||
if ( !linesToProcess.empty() ) | ||
{ | ||
Q_FOREACH ( QgsLineStringV2* line, linesToProcess ) | ||
{ | ||
QTransform transform = QTransform::fromTranslate( x, y ); | ||
|
||
QgsLineStringV2* secondline = line->reversed(); | ||
secondline->transform( transform ); | ||
|
||
line->append( secondline ); | ||
line->addVertex( line->pointN( 0 ) ); | ||
|
||
polygon = new QgsPolygonV2(); | ||
polygon->setExteriorRing( line ); | ||
|
||
if ( multipolygon ) | ||
multipolygon->addGeometry( polygon ); | ||
|
||
delete secondline; | ||
} | ||
|
||
if ( multipolygon ) | ||
return QgsGeometry( multipolygon ); | ||
else | ||
return QgsGeometry( polygon ); | ||
} | ||
|
||
return QgsGeometry(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgsinternalgeometryengine.h - QgsInternalGeometryEngine | ||
--------------------- | ||
begin : 13.1.2016 | ||
copyright : (C) 2016 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSINTERNALGEOMETRYENGINE_H | ||
#define QGSINTERNALGEOMETRYENGINE_H | ||
|
||
#include "qgsgeometry.h" | ||
|
||
/** | ||
* This class offers geometry processing methods. | ||
* | ||
* The methods are available via QgsGeometry::[geometryfunction] | ||
* and therefore this does not need to be accessed directly. | ||
* | ||
* @note not available in Python bindings | ||
*/ | ||
|
||
class QgsInternalGeometryEngine | ||
{ | ||
public: | ||
/** | ||
* The caller is responsible that the geometry is available and unchanged | ||
* for the whole lifetime of this object. | ||
* @param geometry | ||
*/ | ||
QgsInternalGeometryEngine( const QgsGeometry& geometry ); | ||
|
||
/** | ||
* Will extrude a line or (segmentized) curve by a given offset and return a polygon | ||
* representation of it. | ||
* | ||
* @param x offset in x direction | ||
* @param y offset in y direction | ||
* @return an extruded polygon | ||
*/ | ||
QgsGeometry extrude( double x, double y ); | ||
|
||
private: | ||
const QgsAbstractGeometryV2* mGeometry; | ||
}; | ||
|
||
#endif // QGSINTERNALGEOMETRYENGINE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters