Hi,
when I delineate a basin using r.stream.basins, and convert the raster map of the basin into vector (r.to.vect), I sometimes get multiple polygons: i.e. one bigger and a couple of one cell polygons. (you can reproduce the behavior in NC sample dataset using easting=643677.87 northing=222800.246).
Since i need to remove the small polygons in a script, I would like to know whether I can use:
grass.run_command(‘v.extract’, list = 1,
input = v_basins,
output = v_basin,
type = ‘area’,
overwrite = True)
In fact, it seems to me that the bigger polygon is always listed as the first record. Is that always true? Does r.to.vect (feature=area) always list as first record the polygon with the larger area?
Or else, I should set a SQL query about the area. I’ve already tried something like:
grass.run_command(‘v.extract’, where = ‘area = max(area)’,
input = v_basins,
output = v_basin,
type = ‘area’,
overwrite = True)
but it seems that the SQL statement is incorrect … I’m not experienced with SQL.
Any idea?
Thanks,
madi
–
Ing. Margherita Di Leo, Ph.D.
On Mon, Apr 9, 2012 at 3:39 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
Hi,
when I delineate a basin using r.stream.basins, and convert the raster map
of the basin into vector (r.to.vect), I sometimes get multiple polygons:
i.e. one bigger and a couple of one cell polygons. (you can reproduce the
behavior in NC sample dataset using easting=643677.87 northing=222800.246).
Since i need to remove the small polygons in a script, I would like to know
whether I can use:
grass\.run\_command\('v\.extract', list = 1,
Wouldn't it be better to remove them with v.clean and rmarea to avoid holes?
Markus
Ciao Markus,
On Mon, Apr 9, 2012 at 3:47 PM, Markus Neteler <neteler@osgeo.org> wrote:
Wouldn’t it be better to remove them with v.clean and rmarea to avoid holes?
just tried with:
grass.run_command(‘v.clean’, input = v_basins,
output = v_basin,
type = ‘area’,
tool = ‘rmarea’,
thresh = 1, # I also tried 10
overwrite = True)
Maybe I do something wrong, but this way I can’t get rid of small polygons, and, in addiction, I need to set the threshold parameter, which I’m not sure to be suitable for all cases…
where am I wrong?
Thanks,
madi
Markus
–
Ing. Margherita Di Leo, Ph.D.
On Mon, Apr 9, 2012 at 4:25 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
Ciao Markus,
On Mon, Apr 9, 2012 at 3:47 PM, Markus Neteler <neteler@osgeo.org> wrote:
Wouldn't it be better to remove them with v.clean and rmarea to avoid
holes?
just tried with:
grass\.run\_command\('v\.clean', input = v\_basins,
output = v\_basin,
type = 'area',
tool = 'rmarea',
thresh = 1, \# I also tried 10
overwrite = True\)
Maybe I do something wrong, but this way I can't get rid of small polygons,
what is exactly happening? Nothing or some are removed?
and, in addiction, I need to set the threshold parameter, which I'm not sure
to be suitable for all cases...
I wanted to suggest to run quartile statistics (extended stats in v.univar) on
an "area" column (if needed, add with v.to.db). But I realized that it only
supports extended statistics on point data No idea why this limitation...
So I thought to suggest the 1st quartile as threshold.
Maybe someone else has an idea?
Markus
On Mon, Apr 9, 2012 at 5:54 PM, Markus Neteler <neteler@osgeo.org> wrote:
On Mon, Apr 9, 2012 at 4:25 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
Ciao Markus,
On Mon, Apr 9, 2012 at 3:47 PM, Markus Neteler <neteler@osgeo.org> wrote:
Wouldn’t it be better to remove them with v.clean and rmarea to avoid
holes?
just tried with:
grass.run_command(‘v.clean’, input = v_basins,
output = v_basin,
type = ‘area’,
tool = ‘rmarea’,
thresh = 1, # I also tried 10
overwrite = True)
Maybe I do something wrong, but this way I can’t get rid of small polygons,
what is exactly happening? Nothing or some are removed?
In this case, nothing is removed. I’ll give it some more try…
and, in addiction, I need to set the threshold parameter, which I’m not sure
to be suitable for all cases…
I wanted to suggest to run quartile statistics (extended stats in v.univar) on
an “area” column (if needed, add with v.to.db). But I realized that it only
supports extended statistics on point data No idea why this limitation…
So I thought to suggest the 1st quartile as threshold.
Thanks, I’ll work on this idea.
Maybe someone else has an idea?
Markus
–
Ing. Margherita Di Leo, Ph.D.
On Mon, Apr 9, 2012 at 6:43 PM, Margherita Di Leo <dileomargherita@gmail.com> wrote:
On Mon, Apr 9, 2012 at 5:54 PM, Markus Neteler <neteler@osgeo.org> wrote:
On Mon, Apr 9, 2012 at 4:25 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
Ciao Markus,
On Mon, Apr 9, 2012 at 3:47 PM, Markus Neteler <neteler@osgeo.org> wrote:
Wouldn’t it be better to remove them with v.clean and rmarea to avoid
holes?
just tried with:
grass.run_command(‘v.clean’, input = v_basins,
output = v_basin,
type = ‘area’,
tool = ‘rmarea’,
thresh = 1, # I also tried 10
overwrite = True)
Maybe I do something wrong, but this way I can’t get rid of small polygons,
what is exactly happening? Nothing or some are removed?
In this case, nothing is removed. I’ll give it some more try…
Looks like small areas are removed, but the table associated to the vector map is not updated, hence the records of the small areas are still present (cat = 2 and cat = 3). My error? What am I missing?
–
Ing. Margherita Di Leo, Ph.D.
The one-cell areas are correct, at least within the logic of vector
topology. If you used r.to.vect with the -v flag, the one-cell areas
will have the same category like the neighboring areas belonging to
the same basin, that is, area calculations for basins done with
v.to.db will be correct and all areas belonging to the same basin will
share the same category (row in the attribute table).
If you want to remove one-cell areas with v.clean tool=rmarea, the
threshold should obviously be larger than the area of one cell (nsres
* ewres) of the original raster and smaller than two cells (2 * nsres
* ewres).
If you want to get rid of entries in the attribute table that are no
longer linked to a vector feature, you can use v.extract layer=1
type=area for areas in layer 1 or alternatively check the min and max
category values with v.category op=report and then v.extract
list=min-max.
Markus M
On Mon, Apr 9, 2012 at 7:35 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
On Mon, Apr 9, 2012 at 6:43 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
On Mon, Apr 9, 2012 at 5:54 PM, Markus Neteler <neteler@osgeo.org> wrote:
On Mon, Apr 9, 2012 at 4:25 PM, Margherita Di Leo
<dileomargherita@gmail.com> wrote:
> Ciao Markus,
>
> On Mon, Apr 9, 2012 at 3:47 PM, Markus Neteler <neteler@osgeo.org>
> wrote:
>>
>> Wouldn't it be better to remove them with v.clean and rmarea to avoid
>> holes?
>
>
> just tried with:
>
>
> grass.run_command('v.clean', input = v_basins,
> output = v_basin,
> type = 'area',
> tool = 'rmarea',
> thresh = 1, # I also tried 10
> overwrite = True)
>
> Maybe I do something wrong, but this way I can't get rid of small
> polygons,
what is exactly happening? Nothing or some are removed?
In this case, nothing is removed. I'll give it some more try..
Looks like small areas are removed, but the table associated to the vector
map is not updated, hence the records of the small areas are still present
(cat = 2 and cat = 3). My error? What am I missing?
--
Ing. Margherita Di Leo, Ph.D.
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev
Hi Markus,
On Mon, Apr 9, 2012 at 8:09 PM, Markus Metz <markus.metz.giswork@googlemail.com> wrote:
The one-cell areas are correct, at least within the logic of vector
topology. If you used r.to.vect with the -v flag, the one-cell areas
will have the same category like the neighboring areas belonging to
the same basin, that is, area calculations for basins done with
v.to.db will be correct and all areas belonging to the same basin will
share the same category (row in the attribute table).
I think this is my case… Thanks a lot!
madi
–
Ing. Margherita Di Leo, Ph.D.