Re: [R-sig-Geo] help: krigged map do not show colours

2015-08-05 Thread Jon Skoien

Anand,

I could not open your .grd file in R, I think the .gri file is missing.
However, looking at it in a text editor, and comparing with your 
R-script, it seems something went wrong with your projections. Your 
.csv-file has LatLong coordinates, but you are setting the projection to 
+proj=utm +zone=40 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 
+towgs84=0,0,0, the same as you seem to have in your prediction raster. 
But you need to reproject your observations in this case.


# First set the right projection:
proj4string(carbon_seq) - CRS(+init=epsg4326) # epsg-code for latlong
# Then transform
carbon_seq = spTransform(carbon_seq, CRS(+proj=utm +zone=40 +south 
+datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0))


If you do this, your prediction grid should overlap your observations, 
and the colors should reflect your color ramp. What you essentially did 
before was to make a prediction thousands of km away from your 
observations, and then all values will be the same.


Best wishes,
Jon


On 8/4/2015 12:48 PM, Anand Sookun wrote:

Dear Jon and Roman

Thanks for the reply.

Im attaching the code.

You may be right that the variogram may be problematic but it fitted
well visually.

I think also that the prediction grid was not well created. I wiould be
grateful to have to hints.code how to create a useful grid and also for
the spplot or other alternatives

I can send more info if required.

Cheers

Anand

On Tue, Aug 4, 2015 at 1:39 PM, Jon Skoien jon.sko...@jrc.ec.europa.eu
mailto:jon.sko...@jrc.ec.europa.eu wrote:

Hi,

You have attached some data, but we still dont know exactly what you
do with the data (do you use the logarithm, how many bins, did you
project the data set...?). However, having had a quick look using
the LatLong coordinates (not really recommended), I can see that the
variogram from this data set is not particularly well defined, and
it could well be that you fitted a model with pure nugget effect. In
that case you will get the same prediction everywhere and no color
differences.

Have a look at
  summary(map)
and particularly the summary of var1.pred.
You could also plot the variogram of the data together with your
model, vmf, and see how they fit.

I am not sure what you mean by not being able to create a prediction
grid with data included. Do you mean that you want a grid which
exactly overlays some of the data points? Matching one point should
not be difficult, 2 and 3 should be possible, but you might get some
problems with precision (FAQ 7.31).

Best wishes,
Jon




On 8/3/2015 5:30 PM, Anand Sookun wrote:

Hi

Thank you Roman for your kind response.

The data is as attached which is part of the whole dataset.

My other problem is that im not able to create an appropriate
prediction grid with some data included.

The codes which failed to show colour ramps are

map - krige(logcarbseq ~ 1, locations = carbon_seq, newdata =
map,model = vmf)
str(map)
print(spplot(map, var1.pred, asp=1,
col.regions=bpy.colors(64),main=OK prediction, carbon))
print(spplot(map, var1.var,col.regions=cm.colors(64),asp=1,
main=OK prediction variance, carbon))

I look forward to hopefully get some solutions.

Thanks again and warm regards

Anand

On Mon, Aug 3, 2015 at 4:09 PM, Roman Luštrik
roman.lust...@gmail.com mailto:roman.lust...@gmail.com wrote:

What is the variability of the plotted variable?

Cheers,
Roman

On Sun, Aug 2, 2015 at 11:03 AM, Anand Sookun
mailto:asoo...@gmail.comasoo...@gmail.com
mailto:asoo...@gmail.com wrote:

Hi

I have kriged my data but the map shows uniform colours -
no gradual
contour colour plot on map

code: print(spplot(k40, var1.pred, asp=1,
col.regions=bpy.colors(64),main=OK prediction, log-ppm Zn))

thnaks for any help

Anand Sookun
--
---
*Anand Sookun (**MPhil. **PhD Candidate, University of
Mauritius)*
*Director cum Freelance Consultant*
*Soft Sustainable Services (Mauritius)*
*Research and Consultancy*

Website: http://sustain-ability.webs.com/



https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic

[[alternative HTML version deleted]]

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




--
In God we trust, all others bring data.




--
---
/*Anand Sookun (*//*MPhil. *//*PhD Candidate, 

Re: [R-sig-Geo] help: krigged map do not show colours

2015-08-05 Thread Jon Skoien
Hi,

You have attached some data, but we still dont know exactly what you do 
with the data (do you use the logarithm, how many bins, did you project 
the data set...?). However, having had a quick look using the LatLong 
coordinates (not really recommended), I can see that the variogram from 
this data set is not particularly well defined, and it could well be 
that you fitted a model with pure nugget effect. In that case you will 
get the same prediction everywhere and no color differences.

Have a look at
  summary(map)
and particularly the summary of var1.pred.
You could also plot the variogram of the data together with your model, 
vmf, and see how they fit.

I am not sure what you mean by not being able to create a prediction 
grid with data included. Do you mean that you want a grid which exactly 
overlays some of the data points? Matching one point should not be 
difficult, 2 and 3 should be possible, but you might get some problems 
with precision (FAQ 7.31).

Best wishes,
Jon



On 8/3/2015 5:30 PM, Anand Sookun wrote:
 Hi

 Thank you Roman for your kind response.

 The data is as attached which is part of the whole dataset.

 My other problem is that im not able to create an appropriate 
 prediction grid with some data included.

 The codes which failed to show colour ramps are

 map - krige(logcarbseq ~ 1, locations = carbon_seq, newdata = 
 map,model = vmf)
 str(map)
 print(spplot(map, var1.pred, asp=1, 
 col.regions=bpy.colors(64),main=OK prediction, carbon))
 print(spplot(map, var1.var,col.regions=cm.colors(64),asp=1, main=OK 
 prediction variance, carbon))

 I look forward to hopefully get some solutions.

 Thanks again and warm regards

 Anand

 On Mon, Aug 3, 2015 at 4:09 PM, Roman Lu�trik roman.lust...@gmail.com 
 mailto:roman.lust...@gmail.com wrote:

 What is the variability of the plotted variable?

 Cheers,
 Roman

 On Sun, Aug 2, 2015 at 11:03 AM, Anand Sookun asoo...@gmail.com
 mailto:asoo...@gmail.com wrote:

 Hi

 I have kriged my data but the map shows uniform colours - no
 gradual
 contour colour plot on map

 code: print(spplot(k40, var1.pred, asp=1,
 col.regions=bpy.colors(64),main=OK prediction, log-ppm Zn))

 thnaks for any help

 Anand Sookun
 --
 ---
 *Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
 *Director cum Freelance Consultant*
 *Soft Sustainable Services (Mauritius)*
 *Research and Consultancy*

 Website: http://sustain-ability.webs.com/


 
 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic

 [[alternative HTML version deleted]]

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




 -- 
 In God we trust, all others bring data.




 -- 
 ---
 /*Anand Sookun (*//*MPhil. *//*PhD Candidate, University of Mauritius)*/
 /*Director cum Freelance Consultant*/
 /*Soft Sustainable Services (Mauritius)*/
 /*Research and Consultancy*/

 Website: http://sustain-ability.webs.com/


 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic



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

-- 
Jon Olav Sk�ien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Climate Risk Management Unit

Via Fermi 2749, TP 100-01,  I-21027 Ispra (VA), ITALY

jon.sko...@jrc.ec.europa.eu
Tel:  +39 0332 789205

Disclaimer: Views expressed in this email are those of the individual and do 
not necessarily represent official views of the European Commission.


[[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] help: krigged map do not show colours

2015-08-05 Thread Anand Sookun
Dear Jon and Roman

Thanks for the reply.

Im attaching the code.

You may be right that the variogram may be problematic but it fitted well
visually.

I think also that the prediction grid was not well created. I wiould be
grateful to have to hints.code how to create a useful grid and also for the
spplot or other alternatives

I can send more info if required.

Cheers

Anand

On Tue, Aug 4, 2015 at 1:39 PM, Jon Skoien jon.sko...@jrc.ec.europa.eu
wrote:

 Hi,

 You have attached some data, but we still dont know exactly what you do
 with the data (do you use the logarithm, how many bins, did you project the
 data set...?). However, having had a quick look using the LatLong
 coordinates (not really recommended), I can see that the variogram from
 this data set is not particularly well defined, and it could well be that
 you fitted a model with pure nugget effect. In that case you will get the
 same prediction everywhere and no color differences.

 Have a look at
  summary(map)
 and particularly the summary of var1.pred.
 You could also plot the variogram of the data together with your model,
 vmf, and see how they fit.

 I am not sure what you mean by not being able to create a prediction grid
 with data included. Do you mean that you want a grid which exactly overlays
 some of the data points? Matching one point should not be difficult, 2 and
 3 should be possible, but you might get some problems with precision (FAQ
 7.31).

 Best wishes,
 Jon




 On 8/3/2015 5:30 PM, Anand Sookun wrote:

 Hi

 Thank you Roman for your kind response.

 The data is as attached which is part of the whole dataset.

 My other problem is that im not able to create an appropriate prediction
 grid with some data included.

 The codes which failed to show colour ramps are

 map - krige(logcarbseq ~ 1, locations = carbon_seq, newdata = map,model =
 vmf)
 str(map)
 print(spplot(map, var1.pred, asp=1, col.regions=bpy.colors(64),main=OK
 prediction, carbon))
 print(spplot(map, var1.var,col.regions=cm.colors(64),asp=1, main=OK
 prediction variance, carbon))

 I look forward to hopefully get some solutions.

 Thanks again and warm regards

 Anand

 On Mon, Aug 3, 2015 at 4:09 PM, Roman Luštrik roman.lust...@gmail.com
 wrote:

 What is the variability of the plotted variable?

 Cheers,
 Roman

 On Sun, Aug 2, 2015 at 11:03 AM, Anand Sookun  asoo...@gmail.com
 asoo...@gmail.com wrote:

 Hi

 I have kriged my data but the map shows uniform colours - no gradual
 contour colour plot on map

 code: print(spplot(k40, var1.pred, asp=1,
 col.regions=bpy.colors(64),main=OK prediction, log-ppm Zn))

 thnaks for any help

 Anand Sookun
 --
 ---
 *Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
 *Director cum Freelance Consultant*
 *Soft Sustainable Services (Mauritius)*
 *Research and Consultancy*

 Website: http://sustain-ability.webs.com/



 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic

 [[alternative HTML version deleted]]

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




 --
 In God we trust, all others bring data.




 --
 ---
 *Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
 *Director cum Freelance Consultant*
 *Soft Sustainable Services (Mauritius)*
 *Research and Consultancy*

 Website:  http://sustain-ability.webs.com/
 http://sustain-ability.webs.com/



 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic
 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic



 ___
 R-sig-Geo mailing 
 listR-sig-Geo@r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo


 --
 Jon Olav Skøien
 Joint Research Centre - European Commission
 Institute for Environment and Sustainability (IES)
 Climate Risk Management Unit

 Via Fermi 2749, TP 100-01,  I-21027 Ispra (VA), ITALY
 jon.sko...@jrc.ec.europa.eu
 Tel:  +39 0332 789205

 Disclaimer: Views expressed in this email are those of the individual and do 
 not necessarily represent official views of the European Commission.




-- 
---
*Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
*Director cum Freelance Consultant*
*Soft Sustainable Services (Mauritius)*
*Research and Consultancy*

Website: http://sustain-ability.webs.com/


https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic


To sig geoAug2015.R
Description: Binary data


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


Re: [R-sig-Geo] help: krigged map do not show colours

2015-08-05 Thread Roman Luštrik
Unfortunately we don't have access to all the variables you use in `krige`
call. Consider making a reproducible example.

Cheers,
Roman


On Mon, Aug 3, 2015 at 5:30 PM, Anand Sookun asoo...@gmail.com wrote:

 Hi

 Thank you Roman for your kind response.

 The data is as attached which is part of the whole dataset.

 My other problem is that im not able to create an appropriate prediction
 grid with some data included.

 The codes which failed to show colour ramps are

 map - krige(logcarbseq ~ 1, locations = carbon_seq, newdata = map,model =
 vmf)
 str(map)
 print(spplot(map, var1.pred, asp=1, col.regions=bpy.colors(64),main=OK
 prediction, carbon))
 print(spplot(map, var1.var,col.regions=cm.colors(64),asp=1, main=OK
 prediction variance, carbon))

 I look forward to hopefully get some solutions.

 Thanks again and warm regards

 Anand

 On Mon, Aug 3, 2015 at 4:09 PM, Roman Luštrik roman.lust...@gmail.com
 wrote:

 What is the variability of the plotted variable?

 Cheers,
 Roman

 On Sun, Aug 2, 2015 at 11:03 AM, Anand Sookun asoo...@gmail.com wrote:

 Hi

 I have kriged my data but the map shows uniform colours - no gradual
 contour colour plot on map

 code: print(spplot(k40, var1.pred, asp=1,
 col.regions=bpy.colors(64),main=OK prediction, log-ppm Zn))

 thnaks for any help

 Anand Sookun
 --
 ---
 *Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
 *Director cum Freelance Consultant*
 *Soft Sustainable Services (Mauritius)*
 *Research and Consultancy*

 Website: http://sustain-ability.webs.com/



 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic

 [[alternative HTML version deleted]]

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




 --
 In God we trust, all others bring data.




 --
 ---
 *Anand Sookun (**MPhil. **PhD Candidate, University of Mauritius)*
 *Director cum Freelance Consultant*
 *Soft Sustainable Services (Mauritius)*
 *Research and Consultancy*

 Website: http://sustain-ability.webs.com/



 https://www.linkedin.com/profile/view?id=161468467trk=nav_responsive_tab_profile_pic




-- 
In God we trust, all others bring data.

[[alternative HTML version deleted]]

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


[R-sig-Geo] From spatial points to spatial pictures

2015-08-05 Thread Maurizio Marchi
Hi everybody,
I'm maurizio Marchi and I'm working as a post-doc at the Forestry Research
Centre of Arezzo (Italy) and I have a question concerning spatial points
management.
During my research activities I have to collect data about the crown
projection on the ground of trees. The aim is to measure the crown area
and to draw a sort of picture on GIS software (QGIS in my case) to analyze
the area and the perimeter of the crowns compared to the free area of a
plot (generally a circular plot) to have an idea of how much photosynthetic
radiation is able to reach the soil. My working steps are:
1) During the survey on the field each crown of each tree is initially
drawn collecting 8 points that have to be connected to become a spatial
polygon:

###---example of table to be processed
TREE   POINT   X   Y
11   xy
12   xy
13   xy
14   xy
15   xy
16   xy
17   xy
18   xy
21   xy
22   xy
23   xy
24   xy
25   xy
26   xy
27   xy
28   xy
[..]
N8   xy

2) the points,sorted by Tree become the vertices of the polygons

3) The polygons have to be processed to obtain a smoothed polygons,
circumscribing the polygonal crowns (e.g.
http://grasswiki.osgeo.org/wiki/V.generalize_tutorial)

I generally do it on QGIS and GRASS but is there something more appropriate
on R to do this? for example with rgdal or sp package?

Many thanks


-- 
Maurizio Marchi
Calenzano (FI) - Italy
ID Skype: maurizioxyz
Ubuntu 14.04 LTS
linux user 552742

[[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] help: krigged map do not show colours

2015-08-05 Thread Anand Sookun
Dear Jon

I have to thank you so much for solving this issue. I did't notice that
there was a projection and grid problem.

I hope I would be able to move forward with my analysis with R and perhaps
still need your kind and much appreciated help.

Cheers

Anand

On Wed, Aug 5, 2015 at 12:08 PM, Jon Skoien jon.sko...@jrc.ec.europa.eu
wrote:

 Good.
 For the next function, I think you are trying to use an sp-function
 (gridded) on a raster object. You can convert between these, but not
 necessarily use the same functions. Use
 spgrid = rasterToPoints(YourRaster, spatial = TRUE)
 gridded(spgrid) = TRUE
 if you want to convert your raster layer to a spatial object.

 Best wishes,
 Jon



 On 8/5/2015 10:00 AM, Anand Sookun wrote:

 Dear John

 Thanks again.
 this time it worked but the variogram is not plotting well and some other
 problems croped.
 Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘gridded’ for signature
 ‘RasterLayer

 I will try by looking closely at the scripts and be back to you soon

 Best Wishes

 Anand

 On Wed, Aug 5, 2015 at 11:36 AM, Jon Skoien jon.sko...@jrc.ec.europa.eu
 wrote:

 Dear Anand

 On 8/5/2015 9:03 AM, Anand Sookun wrote:

 Dear John

 Greetings

 I really appreciate your help. Itried what you proposed but got stuck
 with the following:

  proj4string(carbon_seq) - CRS(+init=epsg 4326) # epsg-code for
 latlong
 Error in CRS(+init=epsg 4326) : no colon in init= string

 Sorry, there is a : missing, should be
 CRS(+init=epsg:4326)

 See if it works better!
 Jon


 Also I TRIED AGAIN
  proj4string(carbon_seq) - CRS(+init=epsg4326) # epsg-code for latlong
 Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function ‘proj4string-’ for
 signature ‘data.frame, CRS

 I tried with rgdal but got the same eror
  require(rgdal)
 Loading required package: rgdal
 rgdal: version: 0.8-16, (SVN revision 498)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
 Path to GDAL shared files:
 C:/Users/Anand/Documents/R/win-library/3.0/rgdal/gdal
 GDAL does not use iconv for recoding strings.
 Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
 Path to PROJ.4 shared files:
 C:/Users/Anand/Documents/R/win-library/3.0/rgdal/proj


 im attacing the gri file.

 Thanks for your time.

 CHEERS

 ANAND

 On Tue, Aug 4, 2015 at 4:55 PM, Jon Skoien 
 jon.sko...@jrc.ec.europa.eujon.sko...@jrc.ec.europa.eu wrote:

 Anand,

 I could not open your .grd file in R, I think the .gri file is missing.
 However, looking at it in a text editor, and comparing with your
 R-script, it seems something went wrong with your projections. Your
 .csv-file has LatLong coordinates, but you are setting the projection to
 +proj=utm +zone=40 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84
 +towgs84=0,0,0, the same as you seem to have in your prediction raster.
 But you need to reproject your observations in this case.

 # First set the right projection:
 proj4string(carbon_seq) - CRS(+init=epsg4326) # epsg-code for latlong
 # Then transform
 carbon_seq = spTransform(carbon_seq, CRS(+proj=utm +zone=40 +south
 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0))

 If you do this, your prediction grid should overlap your observations,
 and the colors should reflect your color ramp. What you essentially did
 before was to make a prediction thousands of km away from your
 observations, and then all values will be the same.

 Best wishes,
 Jon


 On 8/4/2015 12:48 PM, Anand Sookun wrote:

 Dear Jon and Roman

 Thanks for the reply.

 Im attaching the code.

 You may be right that the variogram may be problematic but it fitted
 well visually.

 I think also that the prediction grid was not well created. I wiould be
 grateful to have to hints.code how to create a useful grid and also for
 the spplot or other alternatives

 I can send more info if required.

 Cheers

 Anand

 On Tue, Aug 4, 2015 at 1:39 PM, Jon Skoien jon.sko...@jrc.ec.europa.eu
 mailto:jon.sko...@jrc.ec.europa.eu wrote:

 Hi,

 You have attached some data, but we still dont know exactly what you
 do with the data (do you use the logarithm, how many bins, did you
 project the data set...?). However, having had a quick look using
 the LatLong coordinates (not really recommended), I can see that the
 variogram from this data set is not particularly well defined, and
 it could well be that you fitted a model with pure nugget effect. In
 that case you will get the same prediction everywhere and no color
 differences.

 Have a look at
   summary(map)
 and particularly the summary of var1.pred.
 You could also plot the variogram of the data together with your
 model, vmf, and see how they fit.

 I am not sure what you mean by not being able to create a prediction
 grid with data included. Do you mean that you want a grid which

Re: [R-sig-Geo] From spatial points to spatial pictures

2015-08-05 Thread boB Rudis
Can you provide a (small) real set of data (with real values for x  y)?

On Wed, Aug 5, 2015 at 9:56 AM, Maurizio Marchi
mauriziomarch...@gmail.com wrote:
 photosynthetic
 radiation

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


Re: [R-sig-Geo] From spatial points to spatial pictures

2015-08-05 Thread boB Rudis
Maurizio provided his data set offline. The code + data + sample plots
are in this gist:
https://gist.github.com/hrbrmstr/e29cf9138e480db9e67d

The data is just as he described it, so it's really just a matter of
creating some polygons from the the points spline interpolation:

library(ggplot2)
library(ggthemes)
library(sp)

#' Make smooth polys from points
#'
#' From: http://gis.stackexchange.com/a/24929/29544
#'
#' @param xy n x 2 matrix with n = k
#' @param k # of vertices to expand points to
#' @param ... other args passed to \code{spline()}
spline.poly - function(xy, vertices, k=3, ...) {

  # Wrap k vertices around each end.
  n - dim(xy)[1]
  if (k = 1) {
data - rbind(xy[(n-k+1):n,], xy, xy[1:k, ])
  } else {
data - xy
  }

  # Spline the x and y coordinates.
  data.spline - spline(1:(n+2*k), data[,1], n=vertices, ...)
  x - data.spline$x
  x1 - data.spline$y
  x2 - spline(1:(n+2*k), data[,2], n=vertices, ...)$y

  # Retain only the middle part.
  cbind(x1, x2)[k  x  x = n+k, ]
}

# read in the data
trees - read.csv(CrownsExample.csv)

# sort data by tree  point
trees - trees[with(trees, order(TREE, POINT)),]

# plot just points colored by tree to make sure points look ok
ggplot(trees, aes(x=X, y=Y, color=factor(TREE))) + coord_equal() +
geom_point()

# small function to avoid anonymous fnction in `by` make a polygon
from our points
make_tree_poly - function(tree) {
  tree_pts - spline.poly(as.matrix(tree[, c(X, Y)]), 100)
  Polygons(list(Polygon(tree_pts)), ID=unique(tree$TREE))
}

# for each tree, make a set of smoothed polygons then make the whole thing
# a SpatialPolygonsDataFrame so more spatial ops can be done on it (or more
# data stored with it)
tree_polys - SpatialPolygonsDataFrame(
  SpatialPolygons(unclass(by(trees, trees$TREE, make_tree_poly)),
  proj4string=CRS(+proj=utm +zone=32 +ellps=GRS80
+units=m +no_defs )),
  data.frame(id=unique(trees$TREE), row.names=unique(trees$TREE)))

# plot the new polygon tree crowns colored by tree
tree_map - fortify(tree_polys)
ggplot() +
  geom_map(data=tree_map, map=tree_map,
   aes(x=long, y=lat, fill=id, map_id=id, color=id)) +
  geom_point(data=trees, aes(x=X, y=Y)) + # original points just
to show it's accurate
  coord_equal() +
  theme_map()

On Wed, Aug 5, 2015 at 9:56 AM, Maurizio Marchi
mauriziomarch...@gmail.com wrote:
 Hi everybody,
 I'm maurizio Marchi and I'm working as a post-doc at the Forestry Research
 Centre of Arezzo (Italy) and I have a question concerning spatial points
 management.
 During my research activities I have to collect data about the crown
 projection on the ground of trees. The aim is to measure the crown area
 and to draw a sort of picture on GIS software (QGIS in my case) to analyze
 the area and the perimeter of the crowns compared to the free area of a
 plot (generally a circular plot) to have an idea of how much photosynthetic
 radiation is able to reach the soil. My working steps are:
 1) During the survey on the field each crown of each tree is initially
 drawn collecting 8 points that have to be connected to become a spatial
 polygon:

 ###---example of table to be processed
 TREE   POINT   X   Y
 11   xy
 12   xy
 13   xy
 14   xy
 15   xy
 16   xy
 17   xy
 18   xy
 21   xy
 22   xy
 23   xy
 24   xy
 25   xy
 26   xy
 27   xy
 28   xy
 [..]
 N8   xy

 2) the points,sorted by Tree become the vertices of the polygons

 3) The polygons have to be processed to obtain a smoothed polygons,
 circumscribing the polygonal crowns (e.g.
 http://grasswiki.osgeo.org/wiki/V.generalize_tutorial)

 I generally do it on QGIS and GRASS but is there something more appropriate
 on R to do this? for example with rgdal or sp package?

 Many thanks


 --
 Maurizio Marchi
 Calenzano (FI) - Italy
 ID Skype: maurizioxyz
 Ubuntu 14.04 LTS
 linux user 552742

 [[alternative HTML version deleted]]

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

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