30 #include <QtAlgorithms> 39 : mTolerance( tolerance )
44 if ( mTolerance <= 0 )
45 return p1.
x() == p2.
x() ? p1.
y() < p2.
y() : p1.
x() < p2.
x();
47 double tx1 = ceil( p1.
x() / mTolerance );
48 double tx2 = ceil( p2.
x() / mTolerance );
50 return ceil( p1.
y() / mTolerance ) < ceil( p2.
y() / mTolerance );
58 template <
typename RandIter,
typename Type,
typename CompareOp > RandIter
my_binary_search( RandIter begin, RandIter end, Type val, CompareOp
comp )
61 RandIter not_found = end;
65 RandIter avg = begin + ( end - begin ) / 2;
66 if ( begin == avg || end == avg )
68 if ( !comp( *begin, val ) && !comp( val, *begin ) )
70 if ( !comp( *end, val ) && !comp( val, *end ) )
75 if ( comp( val, *avg ) )
77 else if ( comp( *avg, val ) )
103 int directionFieldId,
104 const QString& directDirectionValue,
105 const QString& reverseDirectionValue,
106 const QString& bothDirectionValue,
110 mVectorLayer = myLayer;
111 mDirectionFieldId = directionFieldId;
112 mDirectDirectionValue = directDirectionValue;
113 mReverseDirectionValue = reverseDirectionValue;
114 mDefaultDirection = defaultDirection;
115 mBothDirectionValue = bothDirectionValue;
125 return QString(
"Vector line" );
153 tmpInfo.mLength = std::numeric_limits<double>::infinity();
175 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
178 bool isFirstPoint =
true;
180 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
188 for ( i = 0; i != additionalPoints.
size(); ++i )
193 info.
mLength = additionalPoints[ i ].sqrDist( pt1 );
198 info.
mLength = additionalPoints[ i ].sqrDistToSegment( pt1.
x(), pt1.
y(),
202 if ( pointLengthMap[ i ].mLength > info.
mLength )
208 pointLengthMap[ i ] = info;
214 isFirstPoint =
false;
217 emit buildProgress( ++step, featureCount );
223 for ( i = 0; i < tiedPoint.
size(); ++i )
225 if ( tiedPoint[ i ] !=
QgsPoint( 0.0, 0.0 ) )
233 qSort( points.
begin(), points.
end(), pointCompare );
237 for ( i = 0;i < points.
size();++i )
240 for ( i = 0; i < tiedPoint.
size() ; ++i )
248 if ( mDirectionFieldId != -1 )
256 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
259 for ( it2 = tmp.
begin(); it2 != tmp.
end(); ++it2 )
264 qSort( tmpAttr.
begin(), tmpAttr.
end() );
267 for ( it2 = tmpAttr.
begin(); it2 != tmpAttr.
end(); ++it2 )
269 if ( *it2 == lastAttrId )
284 int directionType = mDefaultDirection;
288 if ( str == mBothDirectionValue )
292 else if ( str == mDirectDirectionValue )
296 else if ( str == mReverseDirectionValue )
309 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
313 bool isFirstPoint =
true;
315 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
322 pointsOnArc[ 0.0 ] = pt1;
323 pointsOnArc[ pt1.
sqrDist( pt2 )] = pt2;
331 if ( pointLengthIt != pointLengthMap.
end() )
334 for ( it = pointLengthIt; it - pointLengthMap.
begin() >= 0; --it )
336 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
338 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
341 for ( it = pointLengthIt + 1; it != pointLengthMap.
end(); ++it )
343 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
345 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
353 int pt1idx = -1, pt2idx = -1;
354 bool isFirstPoint =
true;
355 for ( pointsIt = pointsOnArc.
begin(); pointsIt != pointsOnArc.
end(); ++pointsIt )
360 pt2idx = tmp - points.
begin();
362 if ( !isFirstPoint && pt1 != pt2 )
367 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
369 prop.
push_back(( *it )->property( distance, feature ) );
372 if ( directionType == 1 ||
375 builder->
addArc( pt1idx, pt1, pt2idx, pt2, prop );
377 if ( directionType == 2 ||
380 builder->
addArc( pt2idx, pt2, pt1idx, pt1, prop );
385 isFirstPoint =
false;
389 isFirstPoint =
false;
392 emit buildProgress( ++step, featureCount );
Wrapper for iterator of features from vector data provider or vector layer.
virtual void addVertex(int id, const QgsPoint &pt)
add vertex
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
void makeGraph(QgsGraphBuilderInterface *builder, const QVector< QgsPoint > &additionalPoints, QVector< QgsPoint > &tiedPoints) const override
Make a graph using RgGraphBuilder.
void push_back(const T &value)
bool coordinateTransformationEnabled()
get coordinate transformation enabled
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
Determine interface for creating a graph.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
double y() const
Get the y value of the point.
QgsCoordinateReferenceSystem & destinationCrs()
get destinaltion Crs
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
virtual void addArc(int pt1id, const QgsPoint &pt1, int pt2id, const QgsPoint &pt2, const QVector< QVariant > &properties)
add arc
QString name() const override
return Director name
This class wraps a request for features to a vector layer (or directly its vector data provider)...
bool TiePointInfoCompare(const TiePointInfo &a, const TiePointInfo &b)
QList< int > QgsAttributeList
double measureLine(const QList< QgsPoint > &points) const
Measures the length of a line with multiple segments.
A class to represent a point.
bool operator()(const QgsPoint &p1, const QgsPoint &p2) const
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsLineVectorLayerDirector(QgsVectorLayer *myLayer, int directionFieldId, const QString &directDirectionValue, const QString &reverseDirectionValue, const QString &bothDirectionValue, int defaultDirection)
virtual ~QgsLineVectorLayerDirector()
Destructor.
void push_back(const T &value)
double topologyTolerance()
get topology tolerance
static Type flatType(Type type)
Returns the flat type for a WKB type.
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
bool nextFeature(QgsFeature &f)
QgsPointCompare(double tolerance)
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsDistanceArea * distanceArea()
get measurement tool
double x() const
Get the x value of the point.
RandIter my_binary_search(RandIter begin, RandIter end, Type val, CompareOp comp)