[R-sig-Geo] Speeding up focal

2016-03-18 Thread Kenny Bell
I am trying to use raster::focal to fill some holes in many RasterLayers. I
call:

focal(raster_layer, fun = mean, w = matrix(1, nrow = 3, ncol = 3), NAonly =
TRUE, na.rm = TRUE)

I am only interested in filling in holes in a small subset of each
RasterLayer (i.e. a country when the raster is global). focal spends a lot
of time trying to fill in the oceans and holes in other countries.

Is there any way to get focal to only change values for some specific
subset of a RasterLayer?

Thanks so much!
Kenny

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Fill NoData cells in a raster

2016-03-18 Thread Jefferson Ferreira-Ferreira
A bunch of options is given here too:
http://rstudio-pubs-static.s3.amazonaws.com/1057_1f7e9ac569644689b7e4de78c1fece90.html

2016-03-18 10:45 GMT-04:00 Zack Holden :

> Marine,
> The focal() function in the raster library should work. You should be able
> to apply a custom function to only NA cells by setting NAonly=T.
>
> require(raster)
> ?focal
>
> Zack
>
>
> On Thu, Mar 17, 2016 at 5:27 PM, Marine Regis 
> wrote:
>
> > Hello,
> >
> > I am beginner in spatial statistics and I would need some advice. I have
> a
> > raster that is based on a grid of 30 m resolution and in which each cell
> is
> > assigned to one of ten land cover types (coded as 1, 2, 3, 4, ..., 10 in
> > the raster). However, there are some NoData cells in the raster. Is there
> > an efficient way to fill NoData cells with reasonable values of land
> cover
> > types? Should I use an interpolation method?
> >
> > Thank you very much for your time.
> >
> > Marine
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ___
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 

*Jefferson Ferreira-Ferreira*

Geógrafo – GEOPROCESSAMENTO IDSM | Coordenadoria de TI


jefferson.ferre...@mamiraua.org.br

*Instituto de Desenvolvimento Sustentável Mamirauá*

Ministério da Ciência, Tecnologia e Inovação

Telefone: +55 97 3343-9710

*Google Maps* - Mapas deste e-mail:

Exibir mapa ampliado



*Contatos particulares:*
*(55) 9615-0100*

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: [R-sig-Geo] Find a circle center with spatial points

2016-03-18 Thread Barry Rowlingson
On Fri, Mar 18, 2016 at 2:43 PM, Alex Mandel  wrote:
> library(rgeos)
> gCentroid
>
> http://www.rdocumentation.org/packages/rgeos/functions/topo-unary-gCentroid
>
> Assuming its a circle that would be the center.

Only if you have points uniformly (or uniform-randomly) distributed
round the full extent of the circle. From Adrien's plot it looks like
he's got an arc there.

 It seems more like a three-parameter optimisation problem. Find x, y,
and r that define the circle that minimises the sum of squared
distances from data points to the circle.

 I'm not sure how you'd choose a good initial x,y,r for your optimiser
since I suspect the surface you're optimising over is not unimodal...
You could try taking lots of random samples of three points from your
data and computing the unique circle that fits those points, then
using the mean (or possibly median, there's a fair chance of massive
outliers) value as the initial values.

A quick googling has actually found this little paper on the subject:

http://www.spaceroots.org/documents/circle/circle-fitting.pdf

So I'll shut up now.

Barry

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Find a circle center with spatial points

2016-03-18 Thread Chris Reudenbach

Oops :-[ , Barry thanks for clarification , I got it now.

I don't understand the math either but as a kind of "reparation"
for not reading well enough I found the authors java code.
https://www.spaceroots.org/documents/circle/CircleFitter.java
After download you should for standalone compilation delete line 37 
"package org.spaceroots;"

compile it with:

 javac CircleFitter.java -Xlint:unchecked

then you can run it with:

java CircleFitter input.file

The input data should be formated like:

# input
# x y
0 5
1 4.5
2.5 4
3 3.5
4 2
5 0

the above input yields

initial circle: -001.69467803 -000.69446643 006.23578103
converged after 7 iterations
final circle: -001.34339845 -001.34426151 006.44308386
with the format x,y,radius

which at least make sense with respect to the data.

You easily can  run it from R by system() and grab the output in a file 
using a OS depending pipe

or you may run it using the rJava package which could be more complex.

cheers Chris

if you want you can call it from R with javaR

Am 18.03.2016 um 20:11 schrieb Barry Rowlingson:

On Fri, Mar 18, 2016 at 6:49 PM, Chris Reudenbach
 wrote:

Because it seems to be an arc and not a circle issue that you can solve the
problem by
picking arbitrary two points of your assumed "arc" then construct
(calculate)  the perpendicular bisector of
the line between them and do so for another arbitrary two points of the
assumed "arc".

The intersection of the perpendicular lines is the assumed center of the
arc.

If you iterate over all points this should be a pretty good estimation of
the real center.

  This is the  "sample 3 points and find the fitted circle" idea, you
are likely to get massive "outliers" and if you take the mean
coordinate it could fail horribly. See the paper I linked to for an
example. They use the median to get an initial "robust" estimate of
x,y,R, and then use some specialised optimisation to improve the
estimate - you can't just throw it into "optim"!

  Not sure I understand the maths in it yet though

Barry



___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo