Grass and raster package

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Grass and raster package

Martin
Dear all,

is it possible to load a complete Grass mapset into a raster stack or brick with a single command?
Martin Brandt

Department of Geography and
Regional Research
UZA II, Althanstr. 14
1090 Wien, AUSTRIA
http://geooekologie.univie.ac.at
Reply | Threaded
Open this post in threaded view
|

Re: Grass and raster package

Martin
i found a solution, if someone else is interested:

system("g.mlist type=rast pattern='lin*' >tmp")

k=c(scan("tmp", what='string'))  

x=readRAST6(k)

b=brick(x)
Martin Brandt

Department of Geography and
Regional Research
UZA II, Althanstr. 14
1090 Wien, AUSTRIA
http://geooekologie.univie.ac.at
Reply | Threaded
Open this post in threaded view
|

Re: Grass and raster package

Roger Bivand
Administrator
On Mon, 25 Oct 2010, Martin wrote:

>
> i found a solution, if someone else is interested:
>
> system("g.mlist type=rast pattern='lin*' >tmp")
>
> k=c(scan("tmp", what='string'))

Indeed, using GRASS itself often helps! You can simplify to:

k <- execGRASS("g.mlist", parameters=list(type="rast",
   pattern="'elev*'"), intern=TRUE)

(example tried in spearfish, also works in Linux with pattern="elev*")

Roger

>
> x=readRAST6(k)
>
> b=brick(x)
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

eculidean threshold for clustering

jgarcia-2
In reply to this post by Martin
Dear all,
I am wondering if there is a direct function (I cannot find any) in R, to
obtain, a "factor" vector to identify which points could be grouped in a
set, using a specific threshold distance as clustering criterion.

#e.g, with 7 points with coordinates:

x <- c(1.01,0.95,1.05,1.03,3.03,2.99,3.04)
y <- c(3.01,3.02,3.04,5.23,2.01,2.02,1.98)

# and, let's say, distance threshold 0.5, the answer would be:
(1,1,1,2,3,3,3)

# where the threshold is the maximum distance between any two points for
each cluster

A better approach would be that threshold could be specified as the
distance between any point in each cluster, and its corresponding center
of mass for that cluster, but I guess this would require some loops. Isn't
it? S, I would be happy enough with the abovementioned approach.

If there isn't a direct function, don't worry. I'll try to find a solution
computing distances...

Thanks,
Javier
---




> is it possible to load a complete Grass mapset into a raster stack or
> brick
> with a single command?
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Grass-and-raster-package-tp5667199p5667199.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: eculidean threshold for clustering

Roger Bivand
Administrator
On Tue, 26 Oct 2010, [hidden email] wrote:

> Dear all,
> I am wondering if there is a direct function (I cannot find any) in R, to
> obtain, a "factor" vector to identify which points could be grouped in a
> set, using a specific threshold distance as clustering criterion.
>
> #e.g, with 7 points with coordinates:
>
> x <- c(1.01,0.95,1.05,1.03,3.03,2.99,3.04)
> y <- c(3.01,3.02,3.04,5.23,2.01,2.02,1.98)

library(spdep)
dnb <- dnearneigh(cbind(x, y), 0, 0.5)
n.comp.nb(dnb)$comp.id
# [1] 1 1 1 2 3 3 3

>
> # and, let's say, distance threshold 0.5, the answer would be:
> (1,1,1,2,3,3,3)
>
> # where the threshold is the maximum distance between any two points for
> each cluster
>
> A better approach would be that threshold could be specified as the
> distance between any point in each cluster, and its corresponding center
> of mass for that cluster, but I guess this would require some loops. Isn't
> it? S, I would be happy enough with the abovementioned approach.

I think that this might need hierarchical clustering and custom cut-offs
and # clusters.

Hope this helps,

Roger

>
> If there isn't a direct function, don't worry. I'll try to find a solution
> computing distances...
>
> Thanks,
> Javier
> ---
>
>
>
>
>> is it possible to load a complete Grass mapset into a raster stack or
>> brick
>> with a single command?
>>
>> --
>> View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/Grass-and-raster-package-tp5667199p5667199.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: eculidean threshold for clustering

Marcelino de la Cruz
In reply to this post by jgarcia-2
This seems a single linkage clustering issue:

 > grouping <- hclust(dist(data.frame(x,y)),"single")
 > cutree(grouping, h=0.5)
[1] 1 1 1 2 3 3 3

Cheers,

Marcelino



At 13:04 26/10/2010, [hidden email] wrote:

>Dear all,
>I am wondering if there is a direct function (I cannot find any) in R, to
>obtain, a "factor" vector to identify which points could be grouped in a
>set, using a specific threshold distance as clustering criterion.
>
>#e.g, with 7 points with coordinates:
>
>x <- c(1.01,0.95,1.05,1.03,3.03,2.99,3.04)
>y <- c(3.01,3.02,3.04,5.23,2.01,2.02,1.98)
>
># and, let's say, distance threshold 0.5, the answer would be:
>(1,1,1,2,3,3,3)
>
># where the threshold is the maximum distance between any two points for
>each cluster
>
>A better approach would be that threshold could be specified as the
>distance between any point in each cluster, and its corresponding center
>of mass for that cluster, but I guess this would require some loops. Isn't
>it? S, I would be happy enough with the abovementioned approach.
>
>If there isn't a direct function, don't worry. I'll try to find a solution
>computing distances...
>
>Thanks,
>Javier
>---
>
>
>
>
> > is it possible to load a complete Grass mapset into a raster stack or
> > brick
> > with a single command?
> >
> > --
> > View this message in context:
> >
> http://r-sig-geo.2731867.n2.nabble.com/Grass-and-raster-package-tp5667199p5667199.html
> > Sent from the R-sig-geo mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > [hidden email]
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
>_______________________________________________
>R-sig-Geo mailing list
>[hidden email]
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo

____________________________________

Marcelino de la Cruz Rot
Depto. Biologia Vegetal
EUIT Agricola
Universidad Politecnica de Madrid

tel: 34 + 913365435
____________________________________  
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: eculidean threshold for clustering

jgarcia-2
Thank you, Marcelino, Roger and Alexander,
I didn't know any of these.
Cheers,
Javier
...

> This seems a single linkage clustering issue:
>
>  > grouping <- hclust(dist(data.frame(x,y)),"single")
>  > cutree(grouping, h=0.5)
> [1] 1 1 1 2 3 3 3
>
> Cheers,
>
> Marcelino
>
>
>
> At 13:04 26/10/2010, [hidden email] wrote:
>>Dear all,
>>I am wondering if there is a direct function (I cannot find any) in R, to
>>obtain, a "factor" vector to identify which points could be grouped in a
>>set, using a specific threshold distance as clustering criterion.
>>
>>#e.g, with 7 points with coordinates:
>>
>>x <- c(1.01,0.95,1.05,1.03,3.03,2.99,3.04)
>>y <- c(3.01,3.02,3.04,5.23,2.01,2.02,1.98)
>>
>># and, let's say, distance threshold 0.5, the answer would be:
>>(1,1,1,2,3,3,3)
>>
>># where the threshold is the maximum distance between any two points for
>>each cluster
>>
>>A better approach would be that threshold could be specified as the
>>distance between any point in each cluster, and its corresponding center
>>of mass for that cluster, but I guess this would require some loops.
>> Isn't
>>it? S, I would be happy enough with the abovementioned approach.
>>
>>If there isn't a direct function, don't worry. I'll try to find a
>> solution
>>computing distances...
>>
>>Thanks,
>>Javier
>>---
>>
>>
>>
>>
>> > is it possible to load a complete Grass mapset into a raster stack or
>> > brick
>> > with a single command?
>> >
>> > --
>> > View this message in context:
>> >
>> http://r-sig-geo.2731867.n2.nabble.com/Grass-and-raster-package-tp5667199p5667199.html
>> > Sent from the R-sig-geo mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > [hidden email]
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>>_______________________________________________
>>R-sig-Geo mailing list
>>[hidden email]
>>https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> ____________________________________
>
> Marcelino de la Cruz Rot
> Depto. Biologia Vegetal
> EUIT Agricola
> Universidad Politecnica de Madrid
>
> tel: 34 + 913365435
> ____________________________________

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Spatial clustering using skater for similar adjacent polygons

yanboulanger
In reply to this post by Marcelino de la Cruz

Dear all,

I'm using the "skater" function in spdep in order to perform a spatial clustering of polygons containing fire regime data. However, I have the following problem. When I compute the cost, some of my polygons are similar to all their neighbors; hence, all edges have 0 cost values for these polygons. When I compute the nb2listw using the neighbors list and the glist as cost, it obviously reports that   :

>In nb2listw(ecodist_80_99.nb, lcosts_ecodist_80_99, style = "W",  :
  zero sum general weights

For those who are familiar with spatial clustering, I'm looking for proposition. Maybe the only issue would be to dissolve these polygons and then rerun the analyses. Morever, is there another spatial clustering technique in R that can cope with such data?

Thanks in advance,

Yan

Yan Boulanger
Dendrolab - Datation de bâtiments patrimoniaux par dendrochronologie
www.dendrolab.ca
[hidden email]

 

Université du Québec à Rimouski
Département de Biologie
Centre d'études nordiques
300, allée des Ursulines
Rimouski, PQ G5L 3A1
(418) 723-1986 poste 1482
 


     
        [[alternative HTML version deleted]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo