[GRASS-user] Re: Extracting centroids as a raster (and are these centroids really at the center?)

Marcello Gorini gorini at gmail.com
Mon Jan 9 09:49:12 EST 2012


Marcello:

>> Dear all,
>>
>> I need to extract the center of raster areas as another raster.
>>
>> Since my script is totaly raster-based (and I am not used to using
>> vectors),
>> I tried to find some kind of r.thin that would generate the centroids,
>> instead of trying to "force" the area into lines.

Markus:

>find a script attached which calculated centroids from raster areas.
>You may expand it with a final r.in.xyz step to write out the calculated
>centroid(s) as raster map.
>
>Hope this helps,
>Markus

Thanks A LOT !!

Now the centroids are in the center :)

You can see in the attached image the new ones in pink. Great!

But I encountered a few problems to get there. I don't know if it is
something with me or my system (6.4.0svn on old ubuntu 9.1), but the script
wasn't looping correctly over the different areas.

It seemed that r.category was ignoring the mask created in the loop and that
was causing trouble. So, instead of using r.mask, I actually created a
temporary raster containing only the selected area in the loop. I also put
the area calculation with r.stats inside the loop.

Also, as you instructed, I made the program output the centroid coordinates
to a file and then use it as input to r.in.xyz to create the raster. It
worked as a charm!

Thanks again,
Marcello.

P.S.; I also attached the modified r.centroid.new if you would like to take
a look. I hope I didn't deform your script too much :)

http://osgeo-org.1803224.n2.nabble.com/file/n7168100/centroids.png 

http://osgeo-org.1803224.n2.nabble.com/file/n7168100/r.centroid.new
r.centroid.new 

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Extracting-centroids-as-a-raster-and-are-these-centroids-really-at-the-center-tp7146840p7168100.html
Sent from the Grass - Users mailing list archive at Nabble.com.


More information about the grass-user mailing list