Re: [GRASS-user] sampling points in a grid

2015-02-18 Thread Margherita Di Leo
On Tue, Feb 17, 2015 at 5:30 PM, Markus Neteler nete...@osgeo.org wrote:

 On Tue, Feb 17, 2015 at 4:49 PM, Margherita Di Leo direg...@gmail.com
 wrote:
  Hi,
 
  I have a vector of points. According to a regular grid, I need to
 (randomly)
  sample a certain number n of these points in each cell of the grid. Such
  number n is given in a column of the attribute table of the grid. How
 would
  you do this?

 With a small script this should be doable:
 - generate the grid as polygons (v.mkgrid)
 - loop over each polygon
  - fetch category number or v.extract
  - fetch corresponding number of points to be created from DB
  - v.random, using the current grid polygon for restricted creation
 feature

 http://grass.osgeo.org/grass70/manuals/v.random.html#restriction-to-vector-areas


Here lies the problem. I need to randomly pick points that are already
existing. Example: for grid cell that has ID 42, I have 50 points, and have
to randomly pick 7 out of these 50.


  - save point map
 - patch all point maps into single resulting map
 - remove single point maps

 Something like this...

 Markus




-- 
Best regards,

Dr. Margherita DI LEO
Scientific / technical project officer

European Commission - DG JRC
Institute for Environment and Sustainability (IES)
Via Fermi, 2749
I-21027 Ispra (VA) - Italy - TP 261

Tel. +39 0332 78 3600
margherita.di-...@jrc.ec.europa.eu

Disclaimer: The views expressed are purely those of the writer and may not
in any circumstance be regarded as stating an official position of the
European Commission.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] sampling points in a grid

2015-02-18 Thread Johannes Radinger
Maybe you can use a database selection approach for example in sqlite.
First update your points with your grid cell ID and then randomly select
7 rows from the selection where the grid cell ID == 42.

In sqlite there exists the function random(). Here you can find
an approach to select random rows from a sqlite table:
http://stackoverflow.com/questions/2279706/select-random-row-from-an-sqlite-table

I have not tested that approach, but maybe worth a try...

/Johannes

On Wed, Feb 18, 2015 at 11:55 AM, Margherita Di Leo direg...@gmail.com
wrote:



 On Tue, Feb 17, 2015 at 5:30 PM, Markus Neteler nete...@osgeo.org wrote:

 On Tue, Feb 17, 2015 at 4:49 PM, Margherita Di Leo direg...@gmail.com
 wrote:
  Hi,
 
  I have a vector of points. According to a regular grid, I need to
 (randomly)
  sample a certain number n of these points in each cell of the grid. Such
  number n is given in a column of the attribute table of the grid. How
 would
  you do this?

 With a small script this should be doable:
 - generate the grid as polygons (v.mkgrid)
 - loop over each polygon
  - fetch category number or v.extract
  - fetch corresponding number of points to be created from DB
  - v.random, using the current grid polygon for restricted creation
 feature

 http://grass.osgeo.org/grass70/manuals/v.random.html#restriction-to-vector-areas


 Here lies the problem. I need to randomly pick points that are already
 existing. Example: for grid cell that has ID 42, I have 50 points, and have
 to randomly pick 7 out of these 50.


  - save point map
 - patch all point maps into single resulting map
 - remove single point maps

 Something like this...

 Markus




 --
 Best regards,

 Dr. Margherita DI LEO
 Scientific / technical project officer

 European Commission - DG JRC
 Institute for Environment and Sustainability (IES)
 Via Fermi, 2749
 I-21027 Ispra (VA) - Italy - TP 261

 Tel. +39 0332 78 3600
 margherita.di-...@jrc.ec.europa.eu

 Disclaimer: The views expressed are purely those of the writer and may not
 in any circumstance be regarded as stating an official position of the
 European Commission.

 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] sampling points in a grid

2015-02-17 Thread Thomas Adams
Margherita,

Actually, my approach with be little changed either way; without know of a
better GRASS-only approach, the kind of thing I have done is to:

(1) write-out to a text file for all grids x, y, value
(2) index the lines, producing, id, x, y, value
(3) in R randomly sample the index
(4) from (3) you have id, x, y, value for the random sample
(5) import (4) into grass using v.in.ascii

This will take a little scripting…

Best,
Tom


On Tue, Feb 17, 2015 at 8:49 AM, Margherita Di Leo direg...@gmail.com
wrote:

 Hi,

 I have a vector of points. According to a regular grid, I need to
 (randomly) sample a certain number n of these points in each cell of the
 grid. Such number n is given in a column of the attribute table of the
 grid. How would you do this?
 I have half idea to play with the coordinates and Monte Carlo, but I have
 the feeling that I'm not thinking GIS and there must be a easier way.

 Thank you for any hint

 --
 Best regards,

 Dr. Margherita DI LEO
 Scientific / technical project officer

 European Commission - DG JRC
 Institute for Environment and Sustainability (IES)
 Via Fermi, 2749
 I-21027 Ispra (VA) - Italy - TP 261

 Tel. +39 0332 78 3600
 margherita.di-...@jrc.ec.europa.eu

 Disclaimer: The views expressed are purely those of the writer and may not
 in any circumstance be regarded as stating an official position of the
 European Commission.

 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user




-- 
Thomas E Adams, III
718 McBurney Drive
Lebanon, OH 45036

1 (513) 739-9512 (cell)
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] sampling points in a grid

2015-02-17 Thread Markus Neteler
On Tue, Feb 17, 2015 at 4:49 PM, Margherita Di Leo direg...@gmail.com wrote:
 Hi,

 I have a vector of points. According to a regular grid, I need to (randomly)
 sample a certain number n of these points in each cell of the grid. Such
 number n is given in a column of the attribute table of the grid. How would
 you do this?

With a small script this should be doable:
- generate the grid as polygons (v.mkgrid)
- loop over each polygon
 - fetch category number or v.extract
 - fetch corresponding number of points to be created from DB
 - v.random, using the current grid polygon for restricted creation feature

http://grass.osgeo.org/grass70/manuals/v.random.html#restriction-to-vector-areas
 - save point map
- patch all point maps into single resulting map
- remove single point maps

Something like this...

Markus
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user