Skip to content

Commit

Permalink
[FEATURE][processing] Native c++ snap to grid algorithm
Browse files Browse the repository at this point in the history
With support for snapping Z/M values, keeping curves
  • Loading branch information
nyalldawson committed Oct 27, 2017
1 parent c67e398 commit 4372ac2
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 245 deletions.
11 changes: 11 additions & 0 deletions python/core/geometry/qgsabstractgeometry.sip
Expand Up @@ -514,6 +514,17 @@ Returns the centroid of the geometry

protected:

virtual QgsAbstractGeometry *createEmptyWithSameType() const = 0 /Factory/;
%Docstring
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
To create it, the geometry is default constructed and then the WKB is changed.
.. seealso:: clone()
.. versionadded:: 3.0
.. note::

Not available in Python bindings
:rtype: QgsAbstractGeometry
%End

virtual bool hasChildGeometries() const;
%Docstring
Expand Down
15 changes: 15 additions & 0 deletions python/core/geometry/qgsgeometry.sip
Expand Up @@ -665,6 +665,21 @@ Returns true if WKB of the geometry is of WKBMulti* type
:rtype: QgsGeometry
%End

QgsGeometry snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const;
%Docstring
Returns a new geometry with all points or vertices snapped to the closest point of the grid.

If the gridified geometry could not be calculated (or was totally collapsed) an empty geometry will be returned.
Note that snapping to grid may generate an invalid geometry in some corner cases.
It can also be thought as rounding the edges and it may be useful for removing errors.
\param hSpacing Horizontal spacing of the grid (x axis). 0 to disable.
\param vSpacing Vertical spacing of the grid (y axis). 0 to disable.
\param dSpacing Depth spacing of the grid (z axis). 0 (default) to disable.
\param mSpacing Custom dimension spacing of the grid (m axis). 0 (default) to disable.
.. versionadded:: 3.0
:rtype: QgsGeometry
%End

bool intersects( const QgsRectangle &r ) const;
%Docstring
Tests for intersection with a rectangle (uses GEOS)
Expand Down
3 changes: 0 additions & 3 deletions python/plugins/processing/algs/help/qgis.yaml
Expand Up @@ -510,9 +510,6 @@ qgis:snapgeometries: >

Vertices will be inserted or removed as required to make the geometries match the reference geometries.

qgis:snappointstogrid: >
This algorithm modifies the position of points in a vector layer, so they fall in the coordinates of a grid.

qgis:splitwithlines: >
This algorithm splits the lines or polygons in one layer using the lines in another layer to define the breaking points. Intersection between geometries in both layers are considered as split points.

Expand Down
174 changes: 0 additions & 174 deletions python/plugins/processing/algs/qgis/Gridify.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -73,7 +73,6 @@
from .FixedDistanceBuffer import FixedDistanceBuffer
from .GeometryConvert import GeometryConvert
from .GeometryByExpression import GeometryByExpression
from .Gridify import Gridify
from .GridLine import GridLine
from .GridPolygon import GridPolygon
from .Heatmap import Heatmap
Expand Down Expand Up @@ -200,7 +199,6 @@ def getAlgs(self):
FixedDistanceBuffer(),
GeometryByExpression(),
GeometryConvert(),
Gridify(),
GridLine(),
GridPolygon(),
Heatmap(),
Expand Down

This file was deleted.

@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xsi:schemaLocation="http://ogr.maptools.org/ gridify_lines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>2</gml:X><gml:Y>-4</gml:Y></gml:coord>
<gml:coord><gml:X>12</gml:X><gml:Y>4</gml:Y></gml:coord>
<gml:coord><gml:X>-2</gml:X><gml:Y>-4</gml:Y></gml:coord>
<gml:coord><gml:X>12</gml:X><gml:Y>6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:gridify_lines fid="lines.0">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 8,2 8,4 12,4</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 10,2 10,4 12,6</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:gridify_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_lines fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-2,-2 2,-2</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:gridify_lines>
</gml:featureMember>
<gml:featureMember>
Expand All @@ -27,6 +28,7 @@
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_lines fid="lines.3">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>4,2 6,2</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:gridify_lines>
</gml:featureMember>
<gml:featureMember>
Expand All @@ -36,7 +38,7 @@
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_lines fid="lines.5">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,-4 10,0</gml:coordinates></gml:LineString></ogr:geometryProperty>
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,-4 10,2</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:gridify_lines>
</gml:featureMember>
<gml:featureMember>
Expand Down

This file was deleted.

@@ -1,41 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xsi:schemaLocation="http://ogr.maptools.org/ gridify_polys.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0</gml:X><gml:Y>-4</gml:Y></gml:coord>
<gml:coord><gml:X>-2</gml:X><gml:Y>-4</gml:Y></gml:coord>
<gml:coord><gml:X>10</gml:X><gml:Y>6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:gridify_polys fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,0 0,4 4,4 4,2 2,2 2,0 0,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-2,-2 -2,4 4,4 4,2 2,2 2,-2 -2,-2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>aaaaa</ogr:name>
<ogr:intval>33</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
</ogr:gridify_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_polys fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,6 6,4 4,4 6,6</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>Aaaaa</ogr:name>
<ogr:intval>-33</ogr:intval>
<ogr:floatval>0</ogr:floatval>
</ogr:gridify_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_polys fid="polys.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,4 2,6 4,6 4,4 2,4</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>bbaaa</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
</ogr:gridify_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_polys fid="polys.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,0 10,0 10,-4 6,-4 6,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,2 10,2 10,-4 6,-4 6,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>8,0 8,-2 10,-2 10,0 8,0</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
</ogr:gridify_polys>
Expand All @@ -48,7 +48,7 @@
</gml:featureMember>
<gml:featureMember>
<ogr:gridify_polys fid="polys.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,2 6,0 6,-4 2,0 2,2 4,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>4,2 6,2 6,-4 2,-2 2,2 4,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>elim</ogr:name>
<ogr:intval>2</ogr:intval>
<ogr:floatval>3.33</ogr:floatval>
Expand Down

0 comments on commit 4372ac2

Please sign in to comment.