29 #include <QtAlgorithms> 35 : mTolerance( tolerance )
40 if ( mTolerance <= 0 )
41 return p1.
x() == p2.
x() ? p1.
y() < p2.
y() : p1.
x() < p2.
x();
43 double tx1 = ceil( p1.
x() / mTolerance );
44 double tx2 = ceil( p2.
x() / mTolerance );
46 return ceil( p1.
y() / mTolerance ) < ceil( p2.
y() / mTolerance );
54 template <
typename RandIter,
typename Type,
typename CompareOp > RandIter
my_binary_search( RandIter begin, RandIter end, Type val, CompareOp
comp )
57 RandIter not_found = end;
61 RandIter avg = begin + ( end - begin ) / 2;
62 if ( begin == avg || end == avg )
64 if ( !comp( *begin, val ) && !comp( val, *begin ) )
66 if ( !comp( *end, val ) && !comp( val, *end ) )
71 if ( comp( val, *avg ) )
73 else if ( comp( *avg, val ) )
100 const QString& directDirectionValue,
101 const QString& reverseDirectionValue,
102 const QString& bothDirectionValue,
106 mVectorLayer = myLayer;
107 mDirectionFieldId = directionFieldId;
108 mDirectDirectionValue = directDirectionValue;
109 mReverseDirectionValue = reverseDirectionValue;
110 mDefaultDirection = defaultDirection;
111 mBothDirectionValue = bothDirectionValue;
121 return QString(
"Vector line" );
149 tmpInfo.mLength = std::numeric_limits<double>::infinity();
171 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
174 bool isFirstPoint =
true;
176 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
184 for ( i = 0; i != additionalPoints.
size(); ++i )
189 info.
mLength = additionalPoints[ i ].sqrDist( pt1 );
194 info.
mLength = additionalPoints[ i ].sqrDistToSegment( pt1.
x(), pt1.
y(),
198 if ( pointLengthMap[ i ].mLength > info.
mLength )
204 pointLengthMap[ i ] = info;
210 isFirstPoint =
false;
213 emit buildProgress( ++step, featureCount );
219 for ( i = 0; i < tiedPoint.
size(); ++i )
221 if ( tiedPoint[ i ] !=
QgsPoint( 0.0, 0.0 ) )
229 qSort( points.
begin(), points.
end(), pointCompare );
233 for ( i = 0;i < points.
size();++i )
236 for ( i = 0; i < tiedPoint.
size() ; ++i )
244 if ( mDirectionFieldId != -1 )
252 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
255 for ( it2 = tmp.
begin(); it2 != tmp.
end(); ++it2 )
260 qSort( tmpAttr.
begin(), tmpAttr.
end() );
263 for ( it2 = tmpAttr.
begin(); it2 != tmpAttr.
end(); ++it2 )
265 if ( *it2 == lastAttrId )
280 int directionType = mDefaultDirection;
284 if ( str == mBothDirectionValue )
288 else if ( str == mDirectDirectionValue )
292 else if ( str == mReverseDirectionValue )
305 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
309 bool isFirstPoint =
true;
311 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
318 pointsOnArc[ 0.0 ] = pt1;
319 pointsOnArc[ pt1.
sqrDist( pt2 )] = pt2;
327 if ( pointLengthIt != pointLengthMap.
end() )
330 for ( it = pointLengthIt; it - pointLengthMap.
begin() >= 0; --it )
332 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
334 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
337 for ( it = pointLengthIt + 1; it != pointLengthMap.
end(); ++it )
339 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
341 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
349 int pt1idx = -1, pt2idx = -1;
350 bool isFirstPoint =
true;
351 for ( pointsIt = pointsOnArc.
begin(); pointsIt != pointsOnArc.
end(); ++pointsIt )
356 pt2idx = tmp - points.
begin();
358 if ( !isFirstPoint && pt1 != pt2 )
363 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
365 prop.
push_back(( *it )->property( distance, feature ) );
368 if ( directionType == 1 ||
371 builder->
addArc( pt1idx, pt1, pt2idx, pt2, prop );
373 if ( directionType == 2 ||
376 builder->
addArc( pt2idx, pt2, pt1idx, pt1, prop );
381 isFirstPoint =
false;
385 isFirstPoint =
false;
388 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
void makeGraph(QgsGraphBuilderInterface *builder, const QVector< QgsPoint > &additionalPoints, QVector< QgsPoint > &tiedPoints) const override
Make a graph using RgGraphBuilder.
bool operator()(const QgsPoint &p1, const QgsPoint &p2) const
void push_back(const T &value)
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
bool coordinateTransformationEnabled()
get coordinate transformation enabled
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
Determine interface for creating a graph.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
double x() const
Get the x 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)...
double measureLine(const QList< QgsPoint > &points) const
Measures the length of a line with multiple segments.
bool TiePointInfoCompare(const TiePointInfo &a, const TiePointInfo &b)
QList< int > QgsAttributeList
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
A class to represent a point.
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsLineVectorLayerDirector(QgsVectorLayer *myLayer, int directionFieldId, const QString &directDirectionValue, const QString &reverseDirectionValue, const QString &bothDirectionValue, int defaultDirection)
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
virtual ~QgsLineVectorLayerDirector()
Destructor.
void push_back(const T &value)
double y() const
Get the y value of the point.
double topologyTolerance()
get topology tolerance
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
bool nextFeature(QgsFeature &f)
QgsPointCompare(double tolerance)
Represents a vector layer which manages a vector based data sets.
QgsDistanceArea * distanceArea()
get measurement tool
RandIter my_binary_search(RandIter begin, RandIter end, Type val, CompareOp comp)