Skip to content

Commit

Permalink
Made snapping projection aware. This feature needs more testing
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5443 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 12, 2006
1 parent bfd40e5 commit 94135f7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
77 changes: 71 additions & 6 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -2730,6 +2730,19 @@ bool QgsVectorLayer::snapPoint(QgsPoint& point, double tolerance)
dataProvider->reset();
dataProvider->select(&selectrect);

if(projectionsEnabled() && coordinateTransform())
{
//inverse tramsform point to layer SRS
try
{
point = coordinateTransform()->transform(point, QgsCoordinateTransform::INVERSE);
}
catch(QgsCsException &cse)
{
return false;
}
}

//go to through the features reported by the spatial filter of the provider
while ((fet = dataProvider->getNextFeature(false)))
{
Expand Down Expand Up @@ -2783,6 +2796,19 @@ bool QgsVectorLayer::snapPoint(QgsPoint& point, double tolerance)
point.setX(mindistx);
point.setY(mindisty);

if(projectionsEnabled())
{
//transform point to canvas SRC
try
{
point = coordinateTransform()->transform(point);
}
catch(QgsCsException &cse)
{
return false;
}
}

return true;
}

Expand All @@ -2807,10 +2833,23 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point, QgsGeometryVertexInd

double minSqrDist = tolerance*tolerance; //current minimum distance

QgsRect selectrect(point.x()-tolerance, point.y()-tolerance, point.x()+tolerance, point.y()+tolerance);
QgsRect selectrect(origPoint.x()-tolerance, origPoint.y()-tolerance, origPoint.x()+tolerance, origPoint.y()+tolerance);
dataProvider->reset();
dataProvider->select(&selectrect);

if(projectionsEnabled() && coordinateTransform())
{
//inverse tramsform points to layer SRS
try
{
origPoint = coordinateTransform()->transform(point, QgsCoordinateTransform::INVERSE);
}
catch(QgsCsException &cse)
{
return false;
}
}

// Go through the committed features
while ((feature = dataProvider->getNextFeature(false)))
{
Expand All @@ -2830,8 +2869,6 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point, QgsGeometryVertexInd
snappedFeatureId = feature->featureId();
snappedGeometry = *(feature->geometry());
vertexFound = true;
delete feature;
return true;
}
delete feature;
}
Expand All @@ -2857,7 +2894,6 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point, QgsGeometryVertexInd
snappedFeatureId = (*iter)->featureId();
snappedGeometry = *((*iter)->geometry());
vertexFound = true;
return true;
}
}

Expand All @@ -2873,11 +2909,27 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point, QgsGeometryVertexInd
snappedFeatureId = it->first;
snappedGeometry = it->second;
vertexFound = true;
return true;
}
}

return false;
if(!vertexFound)
{
return false;
}

if(projectionsEnabled())
{
//transform point to canvas SRC
try
{
point = coordinateTransform()->transform(point);
}
catch(QgsCsException &cse)
{
return false;
}
}
return true;
}


Expand All @@ -2904,6 +2956,19 @@ QgsGeometry& snappedGeometry, double tolerance)
dataProvider->reset();
dataProvider->select(&selectrect);

if(projectionsEnabled() && coordinateTransform())
{
//inverse tramsform points to layer SRS
try
{
origPoint = coordinateTransform()->transform(point, QgsCoordinateTransform::INVERSE);
}
catch(QgsCsException &cse)
{
return false;
}
}

// Go through the committed features
while ((feature = dataProvider->getNextFeature(false)))
{
Expand Down
1 change: 1 addition & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1130,6 +1130,7 @@ bool QgsOgrProvider::deleteFeatures(std::list<int> const & id)
returnvalue=false;
}
}
ogrLayer->SyncToDisk();
return returnvalue;
}

Expand Down

0 comments on commit 94135f7

Please sign in to comment.