30 #include <QtAlgorithms> 36 : mTolerance( tolerance )
41 if ( mTolerance <= 0 )
42 return p1.
x() == p2.
x() ? p1.
y() < p2.
y() : p1.
x() < p2.
x();
44 double tx1 = ceil( p1.
x() / mTolerance );
45 double tx2 = ceil( p2.
x() / mTolerance );
47 return ceil( p1.
y() / mTolerance ) < ceil( p2.
y() / mTolerance );
55 template <
typename RandIter,
typename Type,
typename CompareOp > RandIter
my_binary_search( RandIter begin, RandIter end, Type val, CompareOp
comp )
58 RandIter not_found = end;
62 RandIter avg = begin + ( end - begin ) / 2;
63 if ( begin == avg || end == avg )
65 if ( !comp( *begin, val ) && !comp( val, *begin ) )
67 if ( !comp( *end, val ) && !comp( val, *end ) )
72 if ( comp( val, *avg ) )
74 else if ( comp( *avg, val ) )
100 int directionFieldId,
101 const QString& directDirectionValue,
102 const QString& reverseDirectionValue,
103 const QString& bothDirectionValue,
107 mVectorLayer = myLayer;
108 mDirectionFieldId = directionFieldId;
109 mDirectDirectionValue = directDirectionValue;
110 mReverseDirectionValue = reverseDirectionValue;
111 mDefaultDirection = defaultDirection;
112 mBothDirectionValue = bothDirectionValue;
122 return QString(
"Vector line" );
150 tmpInfo.mLength = std::numeric_limits<double>::infinity();
172 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
175 bool isFirstPoint =
true;
177 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
185 for ( i = 0; i != additionalPoints.
size(); ++i )
190 info.
mLength = additionalPoints[ i ].sqrDist( pt1 );
195 info.
mLength = additionalPoints[ i ].sqrDistToSegment( pt1.
x(), pt1.
y(),
199 if ( pointLengthMap[ i ].mLength > info.
mLength )
205 pointLengthMap[ i ] = info;
211 isFirstPoint =
false;
214 emit buildProgress( ++step, featureCount );
220 for ( i = 0; i < tiedPoint.
size(); ++i )
222 if ( tiedPoint[ i ] !=
QgsPoint( 0.0, 0.0 ) )
230 qSort( points.
begin(), points.
end(), pointCompare );
234 for ( i = 0;i < points.
size();++i )
237 for ( i = 0; i < tiedPoint.
size() ; ++i )
245 if ( mDirectionFieldId != -1 )
253 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
256 for ( it2 = tmp.
begin(); it2 != tmp.
end(); ++it2 )
261 qSort( tmpAttr.
begin(), tmpAttr.
end() );
264 for ( it2 = tmpAttr.
begin(); it2 != tmpAttr.
end(); ++it2 )
266 if ( *it2 == lastAttrId )
281 int directionType = mDefaultDirection;
285 if ( str == mBothDirectionValue )
289 else if ( str == mDirectDirectionValue )
293 else if ( str == mReverseDirectionValue )
306 for ( mplIt = mpl.
begin(); mplIt != mpl.
end(); ++mplIt )
310 bool isFirstPoint =
true;
312 for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
319 pointsOnArc[ 0.0 ] = pt1;
320 pointsOnArc[ pt1.
sqrDist( pt2 )] = pt2;
328 if ( pointLengthIt != pointLengthMap.
end() )
331 for ( it = pointLengthIt; it - pointLengthMap.
begin() >= 0; --it )
333 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
335 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
338 for ( it = pointLengthIt + 1; it != pointLengthMap.
end(); ++it )
340 if ( it->mFirstPoint == pt1 && it->mLastPoint == pt2 )
342 pointsOnArc[ pt1.
sqrDist( it->mTiedPoint )] = it->mTiedPoint;
350 int pt1idx = -1, pt2idx = -1;
351 bool isFirstPoint =
true;
352 for ( pointsIt = pointsOnArc.
begin(); pointsIt != pointsOnArc.
end(); ++pointsIt )
357 pt2idx = tmp - points.
begin();
359 if ( !isFirstPoint && pt1 != pt2 )
364 for ( it = mProperterList.
begin(); it != mProperterList.
end(); ++it )
366 prop.
push_back(( *it )->property( distance, feature ) );
369 if ( directionType == 1 ||
372 builder->
addArc( pt1idx, pt1, pt2idx, pt2, prop );
374 if ( directionType == 2 ||
377 builder->
addArc( pt2idx, pt2, pt1idx, pt1, prop );
382 isFirstPoint =
false;
386 isFirstPoint =
false;
389 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 and x,y.
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)