Skip to content

Commit

Permalink
[FEATURE][processing] Add native affine transform algorithm for vectors
Browse files Browse the repository at this point in the history
Offers the following benefits over the GRASS/SAGA versions:
- Full support for z/m values and handling curved geometries without loss
of curves
- Works with all native data types, no need for format transformation
- Supports dynamic (data defined, per feature) translate/scale/rotate parameters
- Allows transformation and scaling of both Z and M values (if present)
- Supports in-place edit mode

Fixes #33550
  • Loading branch information
nyalldawson committed Dec 31, 2019
1 parent bc5275a commit 2433ee5
Show file tree
Hide file tree
Showing 8 changed files with 513 additions and 0 deletions.
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ affine_transform.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0.7878679656440366</gml:X><gml:Y>-2.242640687119285</gml:Y><gml:Z>9.5</gml:Z></gml:coord>
<gml:coord><gml:X>8.071067811865476</gml:X><gml:Y>7.586143571373726</gml:Y><gml:Z>9.5</gml:Z></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:affine_transform fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.929289321881345,3.62634559672906,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.787867965644037,6.87903679018718,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.858578643762691,5.25269119345812,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.1920310216783,7.58614357137373,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.26274169979695,5.95979797464467,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.24264068711928,-2.24264068711928,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8.07106781186548,7.37401153701776,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.29325035256027,6.59619407771256,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
<gml:featureMember>
<ogr:affine_transform fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1.84852813742386,1.15147186257614,9.5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:affine_transform>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="affine_transform" type="ogr:affine_transform_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="affine_transform_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:long">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:long">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Expand Up @@ -2305,4 +2305,25 @@ tests:
name: expected/split_by_char_regex.gml
type: vector

- algorithm: native:affinetransform
name: Affine transform
params:
DELTA_M: 4.0
DELTA_X: 1.0
DELTA_Y: 2.0
DELTA_Z: 3.0
INPUT:
name: custom/pointszm.shp
type: vector
ROTATION_Z: 45.0
SCALE_M: 1.4
SCALE_X: 1.1
SCALE_Y: 1.2
SCALE_Z: 1.3
results:
OUTPUT:
name: expected/affine_transform.gml
type: vector


# See ../README.md for a description of the file format
1 change: 1 addition & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -24,6 +24,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmaddincrementalfield.cpp
processing/qgsalgorithmaddtablefield.cpp
processing/qgsalgorithmaddxyfields.cpp
processing/qgsalgorithmaffinetransform.cpp
processing/qgsalgorithmapplylayerstyle.cpp
processing/qgsalgorithmarraytranslatedfeatures.cpp
processing/qgsalgorithmaspect.cpp
Expand Down

0 comments on commit 2433ee5

Please sign in to comment.