Skip to content

Commit cc19d0a

Browse files
committedOct 12, 2017
Port hub lines algorithm to c++
Also: - optimise a bit - retain z/m values - use point on surface for non-point layers, instead of center of geometry bounding box
1 parent cac171a commit cc19d0a

File tree

10 files changed

+422
-147
lines changed

10 files changed

+422
-147
lines changed
 

‎python/plugins/processing/algs/help/qgis.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,6 @@ qgis:generatepointspixelcentroidsalongline:
236236
qgis:generatepointspixelcentroidsinsidepolygons:
237237

238238

239-
qgis:hublines:
240-
This algorithm creates hub and spoke diagrams with lines drawn from points on the Spoke Point layer to matching points in the Hub Point layer.
241-
242-
Determination of which hub goes with each point is based on a match between the Hub ID field on the hub points and the Spoke ID field on the spoke points.
243-
244239
qgis:hypsometriccurves: >
245240
This algorithm computes hypsometric curves for an input Digital Elevation Model. Curves are produced as table files in an output folder specified by the user.
246241

‎python/plugins/processing/algs/qgis/HubLines.py

Lines changed: 0 additions & 139 deletions
This file was deleted.

‎python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
from .Hillshade import Hillshade
8585
from .HubDistanceLines import HubDistanceLines
8686
from .HubDistancePoints import HubDistancePoints
87-
from .HubLines import HubLines
8887
from .HypsometricCurves import HypsometricCurves
8988
from .IdwInterpolation import IdwInterpolation
9089
from .ImportIntoPostGIS import ImportIntoPostGIS
@@ -216,7 +215,6 @@ def getAlgs(self):
216215
Hillshade(),
217216
HubDistanceLines(),
218217
HubDistancePoints(),
219-
HubLines(),
220218
HypsometricCurves(),
221219
IdwInterpolation(),
222220
ImportIntoPostGIS(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ hub_lines_multi_to_z.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y><gml:Z>0</gml:Z></gml:coord>
10+
<gml:coord><gml:X>7</gml:X><gml:Y>2</gml:Y><gml:Z>4</gml:Z></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:hub_lines_multi_to_z fid="points.3">
16+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>5,2,0 2,2,2</gml:coordinates></gml:LineString></ogr:geometryProperty>
17+
<ogr:d>2</ogr:d>
18+
<ogr:fid_2>points.2</ogr:fid_2>
19+
<ogr:elev>2</ogr:elev>
20+
</ogr:hub_lines_multi_to_z>
21+
</gml:featureMember>
22+
<gml:featureMember>
23+
<ogr:hub_lines_multi_to_z fid="points.5">
24+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>0,-5,0 1,1,3</gml:coordinates></gml:LineString></ogr:geometryProperty>
25+
<ogr:d>3</ogr:d>
26+
<ogr:fid_2>points.0</ogr:fid_2>
27+
<ogr:elev>3</ogr:elev>
28+
</ogr:hub_lines_multi_to_z>
29+
</gml:featureMember>
30+
<gml:featureMember>
31+
<ogr:hub_lines_multi_to_z fid="points.7">
32+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>7,-1,0 0,-1,4</gml:coordinates></gml:LineString></ogr:geometryProperty>
33+
<ogr:d>4</ogr:d>
34+
<ogr:fid_2>points.8</ogr:fid_2>
35+
<ogr:elev>4</ogr:elev>
36+
</ogr:hub_lines_multi_to_z>
37+
</gml:featureMember>
38+
</ogr:FeatureCollection>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="hub_lines_multi_to_z" type="ogr:hub_lines_multi_to_z_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="hub_lines_multi_to_z_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="d" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:integer">
22+
<xs:totalDigits value="10"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="fid_2" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:string">
29+
<xs:maxLength value="255"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
<xs:element name="elev" nillable="true" minOccurs="0" maxOccurs="1">
34+
<xs:simpleType>
35+
<xs:restriction base="xs:integer">
36+
<xs:totalDigits value="10"/>
37+
</xs:restriction>
38+
</xs:simpleType>
39+
</xs:element>
40+
</xs:sequence>
41+
</xs:extension>
42+
</xs:complexContent>
43+
</xs:complexType>
44+
</xs:schema>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ hub_lines_to_poly.xsd"
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0.5</gml:X><gml:Y>0</gml:Y></gml:coord>
10+
<gml:coord><gml:X>4.672552783109405</gml:X><gml:Y>5.588675623800385</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:hub_lines_to_poly fid="polys.0">
16+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>0.5,0.5 1,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
17+
<ogr:name>aa</ogr:name>
18+
<ogr:intval>1</ogr:intval>
19+
<ogr:floatval>44.123456</ogr:floatval>
20+
<ogr:fid_2>points.0</ogr:fid_2>
21+
<ogr:id>1</ogr:id>
22+
<ogr:id2>2</ogr:id2>
23+
</ogr:hub_lines_to_poly>
24+
</gml:featureMember>
25+
<gml:featureMember>
26+
<ogr:hub_lines_to_poly fid="polys.2">
27+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2.5,5.5 1,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
28+
<ogr:name>bb</ogr:name>
29+
<ogr:intval>1</ogr:intval>
30+
<ogr:floatval>0.123</ogr:floatval>
31+
<ogr:fid_2>points.0</ogr:fid_2>
32+
<ogr:id>1</ogr:id>
33+
<ogr:id2>2</ogr:id2>
34+
</ogr:hub_lines_to_poly>
35+
</gml:featureMember>
36+
<gml:featureMember>
37+
<ogr:hub_lines_to_poly fid="polys.4">
38+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>4,0 1,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
39+
<ogr:name>aa</ogr:name>
40+
<ogr:intval>1</ogr:intval>
41+
<ogr:floatval>3.33</ogr:floatval>
42+
<ogr:fid_2>points.0</ogr:fid_2>
43+
<ogr:id>1</ogr:id>
44+
<ogr:id2>2</ogr:id2>
45+
</ogr:hub_lines_to_poly>
46+
</gml:featureMember>
47+
<gml:featureMember>
48+
<ogr:hub_lines_to_poly fid="polys.5">
49+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2.94337811900192,4.92360844529751 1,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
50+
<ogr:name>bb</ogr:name>
51+
<ogr:intval>1</ogr:intval>
52+
<ogr:floatval>0.123</ogr:floatval>
53+
<ogr:fid_2>points.0</ogr:fid_2>
54+
<ogr:id>1</ogr:id>
55+
<ogr:id2>2</ogr:id2>
56+
</ogr:hub_lines_to_poly>
57+
</gml:featureMember>
58+
<gml:featureMember>
59+
<ogr:hub_lines_to_poly fid="polys.6">
60+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>4.67255278310941,5.32264875239923 1,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
61+
<ogr:name>bb</ogr:name>
62+
<ogr:intval>1</ogr:intval>
63+
<ogr:floatval>0.123</ogr:floatval>
64+
<ogr:fid_2>points.0</ogr:fid_2>
65+
<ogr:id>1</ogr:id>
66+
<ogr:id2>2</ogr:id2>
67+
</ogr:hub_lines_to_poly>
68+
</gml:featureMember>
69+
<gml:featureMember>
70+
<ogr:hub_lines_to_poly fid="polys.8">
71+
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3.12072936660269,5.58867562380038 3,3</gml:coordinates></gml:LineString></ogr:geometryProperty>
72+
<ogr:name>bb</ogr:name>
73+
<ogr:intval>2</ogr:intval>
74+
<ogr:floatval>0.123</ogr:floatval>
75+
<ogr:fid_2>points.1</ogr:fid_2>
76+
<ogr:id>2</ogr:id>
77+
<ogr:id2>1</ogr:id2>
78+
</ogr:hub_lines_to_poly>
79+
</gml:featureMember>
80+
</ogr:FeatureCollection>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="hub_lines_to_poly" type="ogr:hub_lines_to_poly_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="hub_lines_to_poly_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometryProperty" type="gml:LineStringPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="name" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
<xs:maxLength value="2"/>
23+
</xs:restriction>
24+
</xs:simpleType>
25+
</xs:element>
26+
<xs:element name="intval" nillable="true" minOccurs="0" maxOccurs="1">
27+
<xs:simpleType>
28+
<xs:restriction base="xs:integer">
29+
<xs:totalDigits value="10"/>
30+
</xs:restriction>
31+
</xs:simpleType>
32+
</xs:element>
33+
<xs:element name="floatval" nillable="true" minOccurs="0" maxOccurs="1">
34+
<xs:simpleType>
35+
<xs:restriction base="xs:decimal">
36+
</xs:restriction>
37+
</xs:simpleType>
38+
</xs:element>
39+
<xs:element name="fid_2" nillable="true" minOccurs="0" maxOccurs="1">
40+
<xs:simpleType>
41+
<xs:restriction base="xs:string">
42+
<xs:maxLength value="255"/>
43+
</xs:restriction>
44+
</xs:simpleType>
45+
</xs:element>
46+
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
47+
<xs:simpleType>
48+
<xs:restriction base="xs:integer">
49+
<xs:totalDigits value="10"/>
50+
</xs:restriction>
51+
</xs:simpleType>
52+
</xs:element>
53+
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
54+
<xs:simpleType>
55+
<xs:restriction base="xs:integer">
56+
<xs:totalDigits value="10"/>
57+
</xs:restriction>
58+
</xs:simpleType>
59+
</xs:element>
60+
</xs:sequence>
61+
</xs:extension>
62+
</xs:complexContent>
63+
</xs:complexType>
64+
</xs:schema>

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ tests:
24442444
name: expected/hub_distance_lines.gml
24452445
type: vector
24462446

2447-
- algorithm: qgis:hublines
2447+
- algorithm: native:hublines
24482448
name: Hub lines
24492449
params:
24502450
HUBS:
@@ -2460,6 +2460,46 @@ tests:
24602460
name: expected/hub_lines.gml
24612461
type: vector
24622462

2463+
- algorithm: native:hublines
2464+
name: Hub lines (with polygons)
2465+
params:
2466+
HUBS:
2467+
name: dissolve_polys.gml
2468+
type: vector
2469+
HUB_FIELD: intval
2470+
SPOKES:
2471+
name: points.gml
2472+
type: vector
2473+
SPOKE_FIELD: id
2474+
results:
2475+
OUTPUT:
2476+
name: expected/hub_lines_to_poly.gml
2477+
type: vector
2478+
compare:
2479+
fields:
2480+
fid: skip
2481+
fid_2: skip
2482+
2483+
- algorithm: native:hublines
2484+
name: Hub lines ( with z )
2485+
params:
2486+
HUBS:
2487+
name: multipoints.gml
2488+
type: vector
2489+
HUB_FIELD: d
2490+
SPOKES:
2491+
name: pointsz.gml
2492+
type: vector
2493+
SPOKE_FIELD: elev
2494+
results:
2495+
OUTPUT:
2496+
name: expected/hub_lines_multi_to_z.gml
2497+
type: vector
2498+
compare:
2499+
fields:
2500+
fid: skip
2501+
fid_2: skip
2502+
24632503
- algorithm: qgis:pointstopath
24642504
name: Points to path (non grouped)
24652505
params:

‎src/core/processing/qgsnativealgorithms.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
9191
addAlgorithm( new QgsMeanCoordinatesAlgorithm() );
9292
addAlgorithm( new QgsRasterLayerUniqueValuesReportAlgorithm() );
9393
addAlgorithm( new QgsJoinByAttributeAlgorithm() );
94+
addAlgorithm( new QgsJoinWithLinesAlgorithm() );
9495
}
9596

9697
void QgsSaveSelectedFeatures::initAlgorithm( const QVariantMap & )
@@ -2878,4 +2879,134 @@ QVariantMap QgsJoinByAttributeAlgorithm::processAlgorithm( const QVariantMap &pa
28782879
}
28792880

28802881

2882+
void QgsJoinWithLinesAlgorithm::initAlgorithm( const QVariantMap & )
2883+
{
2884+
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "HUBS" ),
2885+
QObject::tr( "Hub layer" ) ) );
2886+
addParameter( new QgsProcessingParameterField( QStringLiteral( "HUB_FIELD" ),
2887+
QObject::tr( "Hub ID field" ), QVariant(), QStringLiteral( "HUBS" ) ) );
2888+
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "SPOKES" ),
2889+
QObject::tr( "Spoke layer" ) ) );
2890+
addParameter( new QgsProcessingParameterField( QStringLiteral( "SPOKE_FIELD" ),
2891+
QObject::tr( "Spoke ID field" ), QVariant(), QStringLiteral( "SPOKES" ) ) );
2892+
2893+
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Hub lines" ), QgsProcessing::TypeVectorLine ) );
2894+
}
2895+
2896+
QString QgsJoinWithLinesAlgorithm::shortHelpString() const
2897+
{
2898+
return QObject::tr( "This algorithm creates hub and spoke diagrams by connecting lines from points on the Spoke layer to matching points in the Hub layer.\n\n"
2899+
"Determination of which hub goes with each point is based on a match between the Hub ID field on the hub points and the Spoke ID field on the spoke points.\n\n"
2900+
"If input layers are not point layers, a point on the surface of the geometries will be taken as the connecting location." );
2901+
}
2902+
2903+
QgsJoinWithLinesAlgorithm *QgsJoinWithLinesAlgorithm::createInstance() const
2904+
{
2905+
return new QgsJoinWithLinesAlgorithm();
2906+
}
2907+
2908+
QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
2909+
{
2910+
if ( parameters.value( QStringLiteral( "SPOKES" ) ) == parameters.value( QStringLiteral( "HUBS" ) ) )
2911+
throw QgsProcessingException( QObject::tr( "Same layer given for both hubs and spokes" ) );
2912+
2913+
std::unique_ptr< QgsFeatureSource > hubSource( parameterAsSource( parameters, QStringLiteral( "HUBS" ), context ) );
2914+
std::unique_ptr< QgsFeatureSource > spokeSource( parameterAsSource( parameters, QStringLiteral( "SPOKES" ), context ) );
2915+
if ( !hubSource || !spokeSource )
2916+
return QVariantMap();
2917+
2918+
QString fieldHubName = parameterAsString( parameters, QStringLiteral( "HUB_FIELD" ), context );
2919+
int fieldHubIndex = hubSource->fields().lookupField( fieldHubName );
2920+
QString fieldSpokeName = parameterAsString( parameters, QStringLiteral( "SPOKE_FIELD" ), context );
2921+
int fieldSpokeIndex = spokeSource->fields().lookupField( fieldSpokeName );
2922+
2923+
if ( fieldHubIndex < 0 || fieldSpokeIndex < 0 )
2924+
throw QgsProcessingException( QObject::tr( "Invalid ID field" ) );
2925+
2926+
QgsFields fields = QgsProcessingUtils::combineFields( hubSource->fields(), spokeSource->fields() );
2927+
2928+
QgsWkbTypes::Type outType = QgsWkbTypes::LineString;
2929+
bool hasZ = false;
2930+
if ( QgsWkbTypes::hasZ( hubSource->wkbType() ) || QgsWkbTypes::hasZ( spokeSource->wkbType() ) )
2931+
{
2932+
outType = QgsWkbTypes::addZ( outType );
2933+
hasZ = true;
2934+
}
2935+
bool hasM = false;
2936+
if ( QgsWkbTypes::hasM( hubSource->wkbType() ) || QgsWkbTypes::hasM( spokeSource->wkbType() ) )
2937+
{
2938+
outType = QgsWkbTypes::addM( outType );
2939+
hasM = true;
2940+
}
2941+
2942+
QString dest;
2943+
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields,
2944+
outType, hubSource->sourceCrs() ) );
2945+
if ( !sink )
2946+
return QVariantMap();
2947+
2948+
auto getPointFromFeature = [hasZ, hasM]( const QgsFeature & feature )->QgsPoint
2949+
{
2950+
QgsPoint p;
2951+
if ( feature.geometry().type() == QgsWkbTypes::PointGeometry && !feature.geometry().isMultipart() )
2952+
p = *static_cast< QgsPoint *>( feature.geometry().geometry() );
2953+
else
2954+
p = *static_cast< QgsPoint *>( feature.geometry().pointOnSurface().geometry() );
2955+
if ( hasZ && !p.is3D() )
2956+
p.addZValue( 0 );
2957+
if ( hasM && !p.isMeasure() )
2958+
p.addMValue( 0 );
2959+
return p;
2960+
};
2961+
2962+
QgsFeatureIterator hubFeatures = hubSource->getFeatures();
2963+
double step = hubSource->featureCount() > 0 ? 100.0 / hubSource->featureCount() : 1;
2964+
int i = 0;
2965+
QgsFeature hubFeature;
2966+
while ( hubFeatures.nextFeature( hubFeature ) )
2967+
{
2968+
i++;
2969+
if ( feedback->isCanceled() )
2970+
{
2971+
break;
2972+
}
2973+
2974+
feedback->setProgress( i * step );
2975+
2976+
if ( !hubFeature.hasGeometry() )
2977+
continue;
2978+
2979+
QgsPoint hubPoint = getPointFromFeature( hubFeature );
2980+
QgsAttributes hubAttributes = hubFeature.attributes();
2981+
2982+
QgsFeatureRequest spokeRequest = QgsFeatureRequest().setDestinationCrs( hubSource->sourceCrs() );
2983+
spokeRequest.setFilterExpression( QgsExpression::createFieldEqualityExpression( fieldSpokeName, hubFeature.attribute( fieldHubIndex ) ) );
2984+
2985+
QgsFeatureIterator spokeFeatures = spokeSource->getFeatures( spokeRequest );
2986+
QgsFeature spokeFeature;
2987+
while ( spokeFeatures.nextFeature( spokeFeature ) )
2988+
{
2989+
if ( feedback->isCanceled() )
2990+
{
2991+
break;
2992+
}
2993+
2994+
QgsPoint spokePoint = getPointFromFeature( spokeFeature );
2995+
QgsGeometry line( new QgsLineString( QVector< QgsPoint >() << hubPoint << spokePoint ) );
2996+
2997+
QgsFeature outFeature;
2998+
QgsAttributes outAttributes = hubAttributes;
2999+
outAttributes.append( spokeFeature.attributes() );
3000+
outFeature.setAttributes( outAttributes );
3001+
outFeature.setGeometry( line );
3002+
sink->addFeature( outFeature, QgsFeatureSink::FastInsert );
3003+
}
3004+
}
3005+
3006+
QVariantMap outputs;
3007+
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
3008+
return outputs;
3009+
}
3010+
3011+
28813012
///@endcond

‎src/core/processing/qgsnativealgorithms.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,30 @@ class QgsJoinByAttributeAlgorithm : public QgsProcessingAlgorithm
871871

872872
};
873873

874+
/**
875+
* Native join by lines ("hub lines") algorithm.
876+
*/
877+
class QgsJoinWithLinesAlgorithm : public QgsProcessingAlgorithm
878+
{
879+
880+
public:
881+
882+
QgsJoinWithLinesAlgorithm() = default;
883+
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
884+
QString name() const override { return QStringLiteral( "hublines" ); }
885+
QString displayName() const override { return QObject::tr( "Join by lines (hub lines)" ); }
886+
virtual QStringList tags() const override { return QObject::tr( "join,connect,lines,points,hub,spoke" ).split( ',' ); }
887+
QString group() const override { return QObject::tr( "Vector analysis" ); }
888+
QString shortHelpString() const override;
889+
QgsJoinWithLinesAlgorithm *createInstance() const override SIP_FACTORY;
890+
891+
protected:
892+
893+
virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
894+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
895+
896+
};
897+
874898
///@endcond PRIVATE
875899

876900
#endif // QGSNATIVEALGORITHMS_H

0 commit comments

Comments
 (0)
Please sign in to comment.