Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
faces
  • Loading branch information
blazek committed Mar 29, 2012
1 parent 1077410 commit 287bebe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -853,6 +853,14 @@ QStringList GRASS_LIB_EXPORT QgsGrass::vectorLayers( QString gisdbase,
list.append( l );
}

/* Faces */
int nfaces = Vect_cidx_get_type_count( &map, field, GV_FACE );
if ( nfaces > 0 )
{
QString l = fs + "_face";
list.append( l );
}

/* Polygons */
int nareas = Vect_cidx_get_type_count( &map, field, GV_AREA );
if ( nareas > 0 )
Expand Down
34 changes: 28 additions & 6 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -143,6 +143,10 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
{
mLayerType = LINE;
}
else if ( mGrassType == GV_FACE )
{
mLayerType = FACE;
}
else if ( mGrassType == GV_AREA )
{
mLayerType = POLYGON;
Expand Down Expand Up @@ -175,6 +179,7 @@ QgsGrassProvider::QgsGrassProvider( QString uri )
mQgisType = QGis::WKBLineString;
break;
case POLYGON:
case FACE:
mQgisType = QGis::WKBPolygon;
break;
}
Expand Down Expand Up @@ -347,7 +352,7 @@ bool QgsGrassProvider::nextFeature( QgsFeature& feature )
feature.clearAttributeMap();

// TODO int may be 64 bits (memcpy)
if ( type & ( GV_POINTS | GV_LINES ) ) /* points or lines */
if ( type & ( GV_POINTS | GV_LINES | GV_FACE ) ) /* points or lines */
{
Vect_read_line( mMap, mPoints, mCats, id );
int npoints = mPoints->n_points;
Expand All @@ -356,10 +361,14 @@ bool QgsGrassProvider::nextFeature( QgsFeature& feature )
{
wkbsize = 1 + 4 + 2 * 8;
}
else // GV_LINES
else if ( type & GV_LINES )
{
wkbsize = 1 + 4 + 4 + npoints * 2 * 8;
}
else // GV_FACE
{
wkbsize = 1 + 4 + 4 + 4 + npoints * 2 * 8;
}
wkb = new unsigned char[wkbsize];
unsigned char *wkbp = wkb;
wkbp[0] = ( unsigned char ) QgsApplication::endian();
Expand All @@ -369,9 +378,18 @@ bool QgsGrassProvider::nextFeature( QgsFeature& feature )
memcpy( wkbp, &mQgisType, 4 );
wkbp += 4;

/* Number of rings */
if ( type & GV_FACE )
{
int nrings = 1;
memcpy( wkbp, &nrings, 4 );
wkbp += 4;
}

/* number of points */
if ( type & GV_LINES )
if ( type & ( GV_LINES | GV_FACE ) )
{
QgsDebugMsg( QString( "set npoints = %1" ).arg( npoints ) );
memcpy( wkbp, &npoints, 4 );
wkbp += 4;
}
Expand Down Expand Up @@ -494,7 +512,7 @@ void QgsGrassProvider::select( QgsAttributeList fetchAttributes,
box.N = rect.yMaximum(); box.S = rect.yMinimum();
box.E = rect.xMaximum(); box.W = rect.xMinimum();
box.T = PORT_DOUBLE_MAX; box.B = -PORT_DOUBLE_MAX;
if ( mLayerType == POINT || mLayerType == CENTROID || mLayerType == LINE || mLayerType == BOUNDARY )
if ( mLayerType == POINT || mLayerType == CENTROID || mLayerType == LINE || mLayerType == FACE || mLayerType == BOUNDARY )
{
Vect_select_lines_by_box( mMap, &box, mGrassType, mList );
}
Expand All @@ -519,7 +537,7 @@ void QgsGrassProvider::select( QgsAttributeList fetchAttributes,
Vect_append_point( Polygon, rect.xMinimum(), rect.yMaximum(), 0 );
Vect_append_point( Polygon, rect.xMinimum(), rect.yMinimum(), 0 );

if ( mLayerType == POINT || mLayerType == CENTROID || mLayerType == LINE || mLayerType == BOUNDARY )
if ( mLayerType == POINT || mLayerType == CENTROID || mLayerType == LINE || mLayerType == FACE || mLayerType == BOUNDARY )
{
Vect_select_lines_by_polygon( mMap, Polygon, 0, NULL, mGrassType, mList );
}
Expand Down Expand Up @@ -1386,6 +1404,10 @@ int QgsGrassProvider::grassLayerType( QString name )
{
return GV_LINES;
}
else if ( ts.compare( "face" ) == 0 )
{
return GV_FACE;
}
else if ( ts.compare( "polygon" ) == 0 )
{
return GV_AREA;
Expand Down Expand Up @@ -2314,7 +2336,7 @@ QString *QgsGrassProvider::isOrphan( int field, int cat, int *orphan )
{
int t, id;
int ret = Vect_cidx_find_next( mMap, fieldIndex, cat,
GV_POINTS | GV_LINES, 0, &t, &id );
GV_POINTS | GV_LINES | GV_FACE, 0, &t, &id );

if ( ret >= 0 )
{
Expand Down
1 change: 1 addition & 0 deletions src/providers/grass/qgsgrassprovider.h
Expand Up @@ -518,6 +518,7 @@ class GRASS_EXPORT QgsGrassProvider : public QgsVectorDataProvider
{
POINT = 1, // <field>_point
LINE, // <field>_line
FACE, // <field>_face
POLYGON, // <field>_polygon
BOUNDARY, // boundary (currently not used)
CENTROID // centroid (currently not used)
Expand Down

0 comments on commit 287bebe

Please sign in to comment.