Skip to content
Permalink
Browse files

functions to get layer field and type from name

git-svn-id: http://svn.osgeo.org/qgis/trunk@4980 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 8, 2006
1 parent c628d6e commit 3e21403b9ab3f60bfd451bdf01addc16cc02e95a
Showing with 51 additions and 15 deletions.
  1. +42 −15 src/providers/grass/qgsgrassprovider.cpp
  2. +9 −0 src/providers/grass/qgsgrassprovider.h
@@ -101,30 +101,25 @@ QgsGrassProvider::QgsGrassProvider(QString const & uri)
mLayerType = CENTROID;
mGrassType = GV_CENTROID;
} else {
// Get field number
int pos = mLayer.find('_');

if ( pos == -1 ) {
mLayerField = grassLayer ( mLayer );
if ( mLayerField == -1 ) {
std::cerr << "Invalid layer name, no underscore found: " << mLayer.toLocal8Bit().data() << std::endl;
return;
}

mLayerField = mLayer.left(pos).toInt();
}

QString ts = mLayer.right( mLayer.length() - pos - 1 );
if ( ts.compare("point") == 0 ) {
mGrassType = grassLayerType ( mLayer );

if ( mGrassType == GV_POINT ) {
mLayerType = POINT;
mGrassType = GV_POINT; // ?! centroids may be points
} else if ( ts.compare("line") == 0 ) {
} else if ( mGrassType == GV_LINES ) {
mLayerType = LINE;
mGrassType = GV_LINE | GV_BOUNDARY;
} else if ( ts.compare("polygon") == 0 ) {
} else if ( mGrassType == GV_AREA ) {
mLayerType = POLYGON;
mGrassType = GV_AREA;
} else {
std::cerr << "Invalid layer name, wrong type: " << ts.toLocal8Bit().data() << std::endl;
std::cerr << "Invalid layer name, wrong type: " << mLayer.toLocal8Bit().data() << std::endl;
return;
}

}
#ifdef QGISDEBUG
std::cerr << "mLayerField: " << mLayerField << std::endl;
@@ -1273,6 +1268,38 @@ int QgsGrassProvider::grassLayer()
return mLayerField;
}

int QgsGrassProvider::grassLayer(QString name)
{
// Get field number
int pos = name.find('_');

if ( pos == -1 ) {
return -1;
}

return name.left(pos).toInt();
}

int QgsGrassProvider::grassLayerType(QString name)
{
int pos = name.find('_');

if ( pos == -1 ) {
return -1;
}

QString ts = name.right( name.length() - pos - 1 );
if ( ts.compare("point") == 0 ) {
return GV_POINT; // ?! centroids may be points
} else if ( ts.compare("line") == 0 ) {
return GV_LINES;
} else if ( ts.compare("polygon") == 0 ) {
return GV_AREA;
}

return -1;
}

//----------------------------------------- Edit -------------------------------------------------------

bool QgsGrassProvider::isGrassEditable ( void )
@@ -453,6 +453,15 @@ class QgsGrassProvider : public QgsVectorDataProvider
/** Returns GRASS layer number */
int grassLayer();

/** Returns GRASS layer number for given layer name or -1 if cannot
* get layer number
*/
static int grassLayer(QString);

/** Returns GRASS layer type (GV_POINT, GV_LINES, GV_AREA) for
* given layer name or -1 if cannot get layer type
*/
static int grassLayerType(QString);

/** return a provider name

0 comments on commit 3e21403

Please sign in to comment.
You can’t perform that action at this time.