[GRASS-dev] [GRASS GIS] #3226: v.select: how to handle situation where no features are found

GRASS GIS trac at osgeo.org
Sat Feb 9 18:25:00 PST 2019


#3226: v.select: how to handle situation where no features are found
--------------------------+-------------------------
  Reporter:  mlennert     |      Owner:  grass-dev@…
      Type:  defect       |     Status:  closed
  Priority:  normal       |  Milestone:  7.2.4
 Component:  Vector       |    Version:  svn-trunk
Resolution:  fixed        |   Keywords:  v.select
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+-------------------------

Comment (by hcho):

 I'm not sure if "not" creating an empty vector is more efficient. For
 example,
 {{{
 v.select ainput=vect1 binput=vect2 output=outvect operator=disjoint --o

 # the existence and validity of outvect would be guaranteed if v.select
 created
 # an empty output for no features
 for cat in `v.db.select -c map=outvect column=cat`; do
     echo $cat
 done
 }}}
 needs to be changed like this:
 {{{
 # make sure there is no previous output vector because v.select won't
 # delete or create a new empty vector when no features are selected
 g.remove -f type=vector name=outvect

 v.select ainput=vect1 binput=vect2 output=outvect operator=disjoint --o

 # check if v.select selected any features
 eval `g.findfile element=vector file=outvect`
 if [ "x$file" != "x" ]; then
     for cat in `v.db.select -c map=outvect column=cat`; do
         echo $cat
     done
 fi
 }}}

 I think "at least" this module should delete the output vector if no
 features are selected with --o flag to avoid a false positive "by mistake"
 and save one line, but for me, it makes more sense to create an empty
 output for easier scripting. Maybe a new flag like -e for empty output?

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/3226#comment:14>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list