From Rainer at krugs.de Tue Sep 1 10:08:41 2015 From: Rainer at krugs.de (Rainer M Krug) Date: Tue, 01 Sep 2015 10:08:41 +0200 Subject: [R-sig-Geo] mapView: basic interactive viewing of spatial data in R In-Reply-To: <55E2E36D.8090408@gmail.com> (Tim Appelhans's message of "Sun, 30 Aug 2015 13:05:17 +0200") References: <55B207E2.9030408@gmail.com> <55E2E36D.8090408@gmail.com> Message-ID: Tim Appelhans writes: > Dear list, > after some really good discussions and good feedback at Geostat 2015 > summer school in Lancaster (Many thanks to Tom, Barry, Edzer, Roger > and all the others for inviting me), I have now ported the mapView > code into its own package called mapview (mind the small 'v'!) > > The package can be found at > > https://github.com/environmentalinformatics-marburg/mapview > > and can be installed using library(devtools) > > devtools::install_github("environmentalinformatics-marburg/mapview") > > > Any suggestions, bug reports or feature requests should be filed here > > https://github.com/environmentalinformatics-marburg/mapview/issues > Thanks a lot. I am looking forward of using this package a little bit more (at the moment nothing spatial happening here) Cheers, Rainer > > Cheers > Tim > > > > On 24.07.2015 12:03, Rainer M Krug wrote: >> Tim Appelhans writes: >> >>> Dear list members, >>> >>> I would like to draw your attention to a little 'project' I've been >>> working on over the past few weeks. >>> >>> Using leaflet for R, I have defined some methods for spatial data (e.g. >>> Raster*, Spatial* objects) to quickly visualise them in either the >>> RStudio Viewer pan or the default web browser. The function I created >>> for this is called mapView(). >>> >>> Think of it as an interactive version of spplot()/plot() for spatial >>> data (though less versatile). It enables zooming, paning and basic layer >>> queries (i.e. printing of the attributes in the @data slot of Spatial* >>> objects + the x/y location of the feature). For Raster* objects queries >>> are currently not available as leaflet translates the data into RGB >>> values for display. Furthermore, background maps can be defined and >>> multiple different spatial object layers can be overlaid. >>> At the moment mapView() lives in our Rsenal package on github >>> (https://github.com/environmentalinformatics-marburg/Rsenal) but this is >>> likely going to change at some point in the not too distant future. This >>> also depends on whether there is active interest in developping this >>> sort of thing further to provide more than the current admittedly rather >>> limited functionality. This, however, would involve JavaScript coding >>> which I do not have any experience with. >>> >>> A quick (non-interactive) intorduction can be found here: >>> >>> https://metvurst.wordpress.com/ >>> >>> The full introductory article including interactive examples is >>> published here: >>> >>> http://environmentalinformatics-marburg.github.io/web-presentations/20150723_mapView.html >>> >>> I hope this may prove useful for some of you. >> This looks like something I was really missing! I was always exporting >> my spatial data into GRASS and viewing it there - but this looks really >> brilliant! This makes out of R a very powerful command line GIS. >> >> I would really like to see this functionality in a separate R package on >> CRAN - even with only its current functionality, it is very useful! >> >> Thanks a lot and keep us posted, >> >> Rainer >> >>> Also, if anyone is keen to get involved in taking this further, please >>> let me know and we will see how to best proceed. >>> >>> Best, >>> Tim -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: Rainer at krugs.de Skype: RMkrug PGP: 0x0F52F982 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 480 bytes Desc: not available URL: From zhangjiaqiang at gmail.com Tue Sep 1 12:44:21 2015 From: zhangjiaqiang at gmail.com (Zhang Jiaqiang) Date: Tue, 1 Sep 2015 18:44:21 +0800 Subject: [R-sig-Geo] Divide Voronoi cell using azimuth in R Message-ID: Hello, I am totally a newbie to geo and I have an exact same question with the question on stackoverflow: Divide Voronoi cell using azimuth in R Which is: given some nodes with lat/lon, with help of the deldir, I can easily get the N voronoi cells. But I need to divide each one based on three given azimuth values, i.e., divide each polygon into three polygons and show 3*N polygons on the map/plot. The answer on stackoverflow gives a general idea, I read several times but still not sure where to start. I would be highly appreciated if someone can give me some suggestions on that. Best regards wushuzh [[alternative HTML version deleted]] From sa12372 at bristol.ac.uk Tue Sep 1 20:38:47 2015 From: sa12372 at bristol.ac.uk (Sherien Al-Azerji) Date: Tue, 1 Sep 2015 19:38:47 +0100 Subject: [R-sig-Geo] inquiry Message-ID: Dear All, I'm trying to use the gstat code which called Universal Kriging and run the example in this page http://spatial-analyst.net/wiki/index.php?title=Regression-kriging_guide I got some problems hope you can help me to fix it and understand the code well 1- when I read the slope file I didn't get the same data structure as in the example, the 'SpatialGridDataFrame' [package "sp"] with 4 slots instead of 6 slots 2- thus when I run the rest of the code I got error messages after trying to create grid-points overlay Can any one help me please to fix the problem Best Regards Dema [[alternative HTML version deleted]] From edzer.pebesma at uni-muenster.de Tue Sep 1 23:17:14 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Tue, 1 Sep 2015 23:17:14 +0200 Subject: [R-sig-Geo] inquiry In-Reply-To: References: Message-ID: <55E615DA.9060908@uni-muenster.de> The script on that page does not match the data in the .zip file on the same page, and is pretty much outdated (e.g., sp::overlay was deprecated long ago, and later removed). Attached is a script that at least works with the data in the .zip, and with current state of R spatial packages. Tom Hengl would have to confirm that everything is still in line with what he had originally in mind. On 09/01/2015 08:38 PM, Sherien Al-Azerji wrote: > Dear All, > > I'm trying to use the gstat code which called Universal Kriging and run the > example in this page > > http://spatial-analyst.net/wiki/index.php?title=Regression-kriging_guide > > I got some problems hope you can help me to fix it and understand the code > well > > 1- when I read the slope file I didn't get the same data structure as in > the example, the 'SpatialGridDataFrame' [package "sp"] with 4 slots instead > of 6 slots > > 2- thus when I run the rest of the code I got error messages after trying > to create grid-points overlay > > Can any one help me please to fix the problem > > Best Regards > Dema > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: UK_in.R Type: text/x-r-source Size: 2188 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From mburulou at yahoo.com Wed Sep 2 01:08:28 2015 From: mburulou at yahoo.com (Lucy Mburu) Date: Wed, 02 Sep 2015 01:08:28 +0200 Subject: [R-sig-Geo] Robust estimation with INLA Message-ID: <55E62FEC.8090201@yahoo.com> Hi all, I am trying to fit a spatial model with INLA, but I need to incorporate the weights of influential points. I have estimated the weights after running a robust regression model and stored the list of weights as a named vector. Is there a possibility for including this vector into the call for slm.inla? Using the columbus example: mod1<-rlm(CRIME~INC+HOVAL,data=columbus,psi="psi.bisquare") xweight<-mod1$w How can I now incorporate "xweight" into the example on page 13 of the INLABMA documentation (https://cran.r-project.org/web/packages/INLABMA/INLABMA.pdf)? Thanks for your ideas. Lucy Mburu. From btupper at bigelow.org Wed Sep 2 15:07:17 2015 From: btupper at bigelow.org (Ben Tupper) Date: Wed, 2 Sep 2015 09:07:17 -0400 Subject: [R-sig-Geo] sp and latticeExtra: add colorbar for layer drawn 'under' In-Reply-To: <55E2DCF0.7070400@uni-muenster.de> References: <0B67D297-87E4-4177-B4DF-D10355EA31B3@bigelow.org> <55E07580.1090707@gmail.com> <1E740328-BE71-4CEB-9BC6-190B3EF4AAF0@bigelow.org> <55E17370.30509@gmail.com> <55E2DCF0.7070400@uni-muenster.de> Message-ID: <35CF0130-5C32-44D3-9992-0759A6FE1FDD@bigelow.org> Hi, On Aug 30, 2015, at 6:37 AM, Edzer Pebesma wrote: > On 08/29/2015 10:55 AM, Tim Appelhans wrote: >> >> I am not sure why SpatialPolygons* objects get rendered via levelplot. > > because levelplot has the understanding of plotting something in 2D, > using colours according to the continuous variation of a third variable. Thanks to you and Tim for the clarifications. I can see in the source code, spplot.R, that SpatialPolygonsDataFrame and SpatialLinesDataFrame are handled by levelplot; thanks for pointing that out. That SpatialPointsDataFrame is handled by xyplot gives me pause now. In fact, if I think about it it confuses me, so I best not think about that first thing in the morning! I agree with Tim that starting with the raster first and then adding the polygons with latticeExtra::as.layer() is more intuitive. Thanks again, Ben > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of M?nster, > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > Journal of Statistical Software: http://www.jstatsoft.org/ > Computers & Geosciences: http://elsevier.com/locate/cageo/ > Spatial Statistics Society http://www.spatialstatistics.info > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org From grothered at gmail.com Wed Sep 2 14:48:03 2015 From: grothered at gmail.com (Gareth Davies) Date: Wed, 2 Sep 2015 22:48:03 +1000 Subject: [R-sig-Geo] Looking for an R package for focal statistics, (moving window) within a 3D neighborhood Message-ID: <55E6F003.1070207@gmail.com> Hi Jose, If you end up writing your own function for this sort of thing, I'd advise you consider whether data.frames are the right data structure to use -- since they have a very high speed penalty for row-wise operations like what you are talking about. If all your attributes are of the same data type, it is much faster to use a matrix. For example, compare the speed of these: x = data.frame(a = runif(1e+06), b=runif(1e+06), c=runif(1e+06)) # Simulate row-wise access and replacement # This is slow since 'x' is a data.frame for(i in 1:1000) x[i,] = runif(3) # This is equivalent to above, but much faster since it uses a matrix x = matrix(runif(3e+06), ncol=3) for(i in 1:1000) x[i,] = runif(3) If your data is not all of the same type, then you can't use a matrix. In that case you might want to experiment with using e.g. a list of vectors and operating on each independently, or maybe have a look at the data.table package [though I am less well versed with this]. Cheers, Gareth. From edzer.pebesma at uni-muenster.de Wed Sep 2 16:01:05 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Wed, 2 Sep 2015 16:01:05 +0200 Subject: [R-sig-Geo] sp and latticeExtra: add colorbar for layer drawn 'under' In-Reply-To: <35CF0130-5C32-44D3-9992-0759A6FE1FDD@bigelow.org> References: <0B67D297-87E4-4177-B4DF-D10355EA31B3@bigelow.org> <55E07580.1090707@gmail.com> <1E740328-BE71-4CEB-9BC6-190B3EF4AAF0@bigelow.org> <55E17370.30509@gmail.com> <55E2DCF0.7070400@uni-muenster.de> <35CF0130-5C32-44D3-9992-0759A6FE1FDD@bigelow.org> Message-ID: <55E70121.2080607@uni-muenster.de> On 09/02/2015 03:07 PM, Ben Tupper wrote: > I can see in the source code, spplot.R, that SpatialPolygonsDataFrame and SpatialLinesDataFrame are handled by levelplot; thanks for pointing that out. That SpatialPointsDataFrame is handled by xyplot gives me pause now. In fact, if I think about it it confuses me, so I best not think about that first thing in the morning! xyplot has the concept of one symbol per observation, with a colour, a size, a symbol type. That is how I thought of plots of SpatialPointsDataFrame at the time I wrote it. -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From ariel.fuentesdi at usach.cl Wed Sep 2 16:38:23 2015 From: ariel.fuentesdi at usach.cl (Ariel Fuentesdi) Date: Wed, 2 Sep 2015 11:38:23 -0300 Subject: [R-sig-Geo] reading postgis tables in R Message-ID: Hi everyone, I want to create a function which reads postgis tables and want to be the same for any kind of geometry. So, to do that I'd need to set a parameter which could be read in lapply functions, but it give me the following error: *Error in paste0("Spatial", geom1, "DataFrame") : * * cannot coerce type 'closure' to vector of type 'character'* The reproducible example is this: gid <- c(1,2) zone_id <- c(589, 581) town_id <- c(474, 466) wkt_geometry <- c("MULTIPOLYGON(((-70.902653 -33.242532,-70.900006 -33.237868,-70.900668 -33.236605,-70.899909 -33.232652,-70.89831 -33.229934,-70.897992 -33.227534,-70.899267 -33.222999,-70.897992 -33.219532,-70.897641 -33.200243,-70.892572 -33.204329,-70.88857 -33.20633,-70.885546 -33.20799,-70.884318 -33.20965,-70.882689 -33.213397,-70.882051 -33.220599,-70.873443 -33.222199,-70.865792 -33.221399,-70.865154 -33.220865,-70.861647 -33.217398,-70.85814 -33.209397,-70.855909 -33.202461,-70.85304 -33.198727,-70.846663 -33.191792,-70.846663 -33.184057,-70.846344 -33.177122,-70.830722 -33.177389,-70.822752 -33.178989,-70.819563 -33.174188,-70.813825 -33.170987,-70.800944 -33.16732,-70.793388 -33.166292,-70.791496 -33.17379,-70.783797 -33.179596,-70.748539 -33.259149,-70.743316 -33.270727,-70.747927 -33.275772,-70.754351 -33.2785,-70.759947 -33.285681,-70.762916 -33.286342,-70.772603 -33.290689,-70.783412 -33.282591,-70.786165 -33.279097,-70.788321 -33.277946,-70.825829 -33.278245,-70.836842 -33.277051,-70.848297 -33.272638,-70.850352 -33.273257,-70.853415 -33.272184,-70.855298 -33.272017,-70.862105 -33.272412,-70.868061 -33.269172,-70.87846 -33.257314,-70.88375 -33.253678,-70.895186 -33.250674,-70.897354 -33.246738,-70.902653 -33.242532)))", "MULTIPOLYGON(((-70.793388 -33.166292,-70.78131 -33.169929,-70.772849 -33.169721,-70.766379 -33.170762,-70.75966 -33.173677,-70.752444 -33.172011,-70.749458 -33.168473,-70.734776 -33.16077,-70.728306 -33.161186,-70.725568 -33.162435,-70.714121 -33.162435,-70.685504 -33.165142,-70.672813 -33.169097,-70.66485 -33.170138,-70.656389 -33.171388,-70.651391 -33.17226,-70.654977 -33.176059,-70.656312 -33.178125,-70.65728 -33.180025,-70.660418 -33.179745,-70.676771 -33.18198,-70.676488 -33.188112,-70.67926 -33.202358,-70.680196 -33.203671,-70.682466 -33.203979,-70.6829 -33.204286,-70.684936 -33.209201,-70.685504 -33.216101,-70.688844 -33.225207,-70.690981 -33.231827,-70.696012 -33.237303,-70.697394 -33.239876,-70.697523 -33.241653,-70.702239 -33.241919,-70.708004 -33.244915,-70.717354 -33.251168,-70.72421 -33.265236,-70.731222 -33.268233,-70.736832 -33.270577,-70.741818 -33.274095,-70.743316 -33.270727,-70.748539 -33.259149,-70.783797 -33.179596,-70.791496 -33.17379,-70.793388 -33.166292)))") shape.df <- data.frame(gid, zone_id, wkt_geometry) SGeom <- function(wkt, p4ss, geom1, geom2){ require(rgeos) require(sp) list_geom <- lapply(wkt, "readWKT", p4s=p4ss) coords <- mapply(spChFIDs, list_geom, as.character(shape.df[,1])) SGeomdf <- paste0("Spatial", geom1, "DataFrame")(paste0("Spatial", geom1)(unlist(lapply(coords, function(x) paste0("x@", geom2))), proj4string=p4ss), shape.df[, -ncol(shape.df)]) SGeomdf} geom.shp <- SGeom(wkt = shape.df$wkt_geometry, p4ss = CRS("+proj=longlat +datum=WGS84"), Polygons, polygons) Thank you, Ariel Fuentes [[alternative HTML version deleted]] From qiuhuanihao at gmail.com Wed Sep 2 23:28:46 2015 From: qiuhuanihao at gmail.com (Qiuhua Ma) Date: Wed, 2 Sep 2015 15:28:46 -0600 Subject: [R-sig-Geo] Error message --- stsls and lagsarlm! Message-ID: Hi, I run spatial lag model with k nearest neighbor weight matrix using both stsls and lagsarlm! I tried k=4: > nb4nwuisale <- knn2nb(knearneigh(sales.nonwuidata.sp, k = 4)) > knn4nwuilistws <- nb2listw(nb4nwuisale, style="W") #stsls method > sp.lagsls.knn4nwuilistws <- stsls(fm_comrisk, data=sales.nonwuidata.sp, knn4nwuilistws) Error in base::chol2inv(x, ...) : element (89, 89) is zero, so the inverse cannot be computed #ML method > sp.lagml.knn4nwuilistws <- lagsarlm(fm_comrisk, data=sales.nonwuidata.sp, knn4nwuilistws) Warning messages: 1: In lagsarlm(fm1, data = sales.nonwuidata.sp, knn4nwuilistws) : inversion of asymptotic covariance matrix failed for tol.solve = 1e-10 reciprocal condition number = 3.30065e-13 - using numerical Hessian. 2: In sqrt(diag(fdHess)[-1]) : NaNs produced I also tried other weight matrix but got the same error message. Any suggestions on how to deal with the error/warning message... thanks, Chelsea [[alternative HTML version deleted]] From metastate at gmail.com Thu Sep 3 00:11:47 2015 From: metastate at gmail.com (Metastate Metastate) Date: Wed, 2 Sep 2015 17:11:47 -0500 Subject: [R-sig-Geo] Error with gwr.mixed in GWmodel package Message-ID: Hi, I applied the gwr.basic and gwr.mixed on the same SPDF file using the codes below. I got an error message on gwr.mixed: Error in SpatialPolygonsDataFrame(Sr = polygons, data = mgwr.df) : row.names of data and Polygons IDs do not match I had no problem with gwr.basic. The code I used was: gwr.res2 <- gwr.basic(Yield_Detrend~Tsfc_4_10+PCP_IN_7_8+PCP_IN_4_6, data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, F123.test = TRUE) mgwr.res2 <-gwr.mixed(Yield_Detrend~Tsfc_4_10+Pcp_30D_LT_2IN_4+PCP_IN_7_8 +Elevation, fixed.vars=c("Pcp_30D_LT_2IN_4", "Elevation"),data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, diagnostic=T) Also, Is it any easy way I can provide the spdf file if you need it to check? Thank you very much for your help. Meta [[alternative HTML version deleted]] From frtog at vestas.com Thu Sep 3 06:55:10 2015 From: frtog at vestas.com (=?iso-8859-1?Q?Frede_Aakmann_T=F8gersen?=) Date: Thu, 3 Sep 2015 04:55:10 +0000 Subject: [R-sig-Geo] reading postgis tables in R In-Reply-To: References: Message-ID: Hi Your code seem to be garbled especially for the definition of the SGeomdf function: SGeomdf <- paste0("Spatial", geom1, "DataFrame")(paste0("Spatial", geom1)(unlist(lapply(coords, function(x) paste0("x@", geom2))), proj4string=p4ss), shape.df[, -ncol(shape.df)]) SGeomdf} Please don't post in html but in plain text. Yours sincerely / Med venlig hilsen Frede Aakmann T?gersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547 6050 frtog at vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Ariel Fuentesdi Sent: 2. september 2015 16:38 To: r-sig-geo at r-project.org Subject: [R-sig-Geo] reading postgis tables in R Hi everyone, I want to create a function which reads postgis tables and want to be the same for any kind of geometry. So, to do that I'd need to set a parameter which could be read in lapply functions, but it give me the following error: *Error in paste0("Spatial", geom1, "DataFrame") : * * cannot coerce type 'closure' to vector of type 'character'* The reproducible example is this: gid <- c(1,2) zone_id <- c(589, 581) town_id <- c(474, 466) wkt_geometry <- c("MULTIPOLYGON(((-70.902653 -33.242532,-70.900006 -33.237868,-70.900668 -33.236605,-70.899909 -33.232652,-70.89831 -33.229934,-70.897992 -33.227534,-70.899267 -33.222999,-70.897992 -33.219532,-70.897641 -33.200243,-70.892572 -33.204329,-70.88857 -33.20633,-70.885546 -33.20799,-70.884318 -33.20965,-70.882689 -33.213397,-70.882051 -33.220599,-70.873443 -33.222199,-70.865792 -33.221399,-70.865154 -33.220865,-70.861647 -33.217398,-70.85814 -33.209397,-70.855909 -33.202461,-70.85304 -33.198727,-70.846663 -33.191792,-70.846663 -33.184057,-70.846344 -33.177122,-70.830722 -33.177389,-70.822752 -33.178989,-70.819563 -33.174188,-70.813825 -33.170987,-70.800944 -33.16732,-70.793388 -33.166292,-70.791496 -33.17379,-70.783797 -33.179596,-70.748539 -33.259149,-70.743316 -33.270727,-70.747927 -33.275772,-70.754351 -33.2785,-70.759947 -33.285681,-70.762916 -33.286342,-70.772603 -33.290689,-70.783412 -33.282591,-70.786165 -33.279097,-70.788321 -33.277946,-70.825829 -33.278245,-70.836842 -33.277051,-70.848297 -33.272638,-70.850352 -33.273257,-70.853415 -33.272184,-70.855298 -33.272017,-70.862105 -33.272412,-70.868061 -33.269172,-70.87846 -33.257314,-70.88375 -33.253678,-70.895186 -33.250674,-70.897354 -33.246738,-70.902653 -33.242532)))", "MULTIPOLYGON(((-70.793388 -33.166292,-70.78131 -33.169929,-70.772849 -33.169721,-70.766379 -33.170762,-70.75966 -33.173677,-70.752444 -33.172011,-70.749458 -33.168473,-70.734776 -33.16077,-70.728306 -33.161186,-70.725568 -33.162435,-70.714121 -33.162435,-70.685504 -33.165142,-70.672813 -33.169097,-70.66485 -33.170138,-70.656389 -33.171388,-70.651391 -33.17226,-70.654977 -33.176059,-70.656312 -33.178125,-70.65728 -33.180025,-70.660418 -33.179745,-70.676771 -33.18198,-70.676488 -33.188112,-70.67926 -33.202358,-70.680196 -33.203671,-70.682466 -33.203979,-70.6829 -33.204286,-70.684936 -33.209201,-70.685504 -33.216101,-70.688844 -33.225207,-70.690981 -33.231827,-70.696012 -33.237303,-70.697394 -33.239876,-70.697523 -33.241653,-70.702239 -33.241919,-70.708004 -33.244915,-70.717354 -33.251168,-70.72421 -33.265236,-70.731222 -33.268233,-70.736832 -33.270577,-70.741818 -33.274095,-70.743316 -33.270727,-70.748539 -33.259149,-70.783797 -33.179596,-70.791496 -33.17379,-70.793388 -33.166292)))") shape.df <- data.frame(gid, zone_id, wkt_geometry) SGeom <- function(wkt, p4ss, geom1, geom2){ require(rgeos) require(sp) list_geom <- lapply(wkt, "readWKT", p4s=p4ss) coords <- mapply(spChFIDs, list_geom, as.character(shape.df[,1])) SGeomdf <- paste0("Spatial", geom1, "DataFrame")(paste0("Spatial", geom1)(unlist(lapply(coords, function(x) paste0("x@", geom2))), proj4string=p4ss), shape.df[, -ncol(shape.df)]) SGeomdf} geom.shp <- SGeom(wkt = shape.df$wkt_geometry, p4ss = CRS("+proj=longlat +datum=WGS84"), Polygons, polygons) Thank you, Ariel Fuentes [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo From Roger.Bivand at nhh.no Thu Sep 3 07:57:53 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Thu, 3 Sep 2015 07:57:53 +0200 Subject: [R-sig-Geo] Error with gwr.mixed in GWmodel package In-Reply-To: References: Message-ID: On Thu, 3 Sep 2015, Metastate Metastate wrote: > Hi, > > I applied the gwr.basic and gwr.mixed on the same SPDF file using the codes > below. I got an error message on gwr.mixed: > > Error in SpatialPolygonsDataFrame(Sr = polygons, data = mgwr.df) : > row.names of data and Polygons IDs do not match > > I had no problem with gwr.basic. > > The code I used was: > > gwr.res2 <- gwr.basic(Yield_Detrend~Tsfc_4_10+PCP_IN_7_8+PCP_IN_4_6, > data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, > F123.test = TRUE) > > mgwr.res2 <-gwr.mixed(Yield_Detrend~Tsfc_4_10+Pcp_30D_LT_2IN_4+PCP_IN_7_8 > +Elevation, fixed.vars=c("Pcp_30D_LT_2IN_4", > "Elevation"),data = Yield.spdf.sub,kernel = "bisquare", adaptive = > TRUE, bw=50, diagnostic=T) > > Also, Is it any easy way I can provide the spdf file if you need it to > check? Please try to create a complete example with built-in data first. Also look carefully at your input data - is there anything specific about your data that the built-in data set doesn't match (eg. a factor covariate?). Finally, pasting the output of traceback() run immediately after gwr.mixed() fails may show where in the function the problem arises. Roger > > Thank you very much for your help. > > Meta > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From Roger.Bivand at nhh.no Thu Sep 3 08:06:32 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Thu, 3 Sep 2015 08:06:32 +0200 Subject: [R-sig-Geo] Error message --- stsls and lagsarlm! In-Reply-To: References: Message-ID: On Wed, 2 Sep 2015, Qiuhua Ma wrote: > Hi, > > I run spatial lag model with k nearest neighbor weight matrix using both > stsls and lagsarlm! > > I tried k=4: > >> nb4nwuisale <- knn2nb(knearneigh(sales.nonwuidata.sp, k = 4)) > >> knn4nwuilistws <- nb2listw(nb4nwuisale, style="W") > > > #stsls method >> sp.lagsls.knn4nwuilistws <- stsls(fm_comrisk, data=sales.nonwuidata.sp, > knn4nwuilistws) > Error in base::chol2inv(x, ...) : > element (89, 89) is zero, so the inverse cannot be computed > > #ML method >> sp.lagml.knn4nwuilistws <- lagsarlm(fm_comrisk, data=sales.nonwuidata.sp, > knn4nwuilistws) > Warning messages: > 1: In lagsarlm(fm1, data = sales.nonwuidata.sp, knn4nwuilistws) : > inversion of asymptotic covariance matrix failed for tol.solve = 1e-10 > reciprocal condition number = 3.30065e-13 - using numerical Hessian. > 2: In sqrt(diag(fdHess)[-1]) : NaNs produced > > I also tried other weight matrix but got the same error message. Any > suggestions on how to deal with the error/warning message... Since the problem does not appear to come from the weights, it probably comes from the data. Could you look at the VIFs in a regular lm() to see whether your covariates are close to collinear? Your formulae do not indicate how many columns there are in the model matrix (89 is a large number - are many of the RHS variables factors, are you using many dummies?). Running traceback() after the failure in stsls() would show the context of the error. Roger > > thanks, > > Chelsea > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From uzzal at gist.ac.kr Thu Sep 3 10:26:57 2015 From: uzzal at gist.ac.kr (Uzzal) Date: Thu, 3 Sep 2015 17:26:57 +0900 (KST) Subject: [R-sig-Geo] How to plot multiple variogram with different title in loop? Message-ID: <308531685.1441268817278.JavaMail.root@eunhasu> I have a csv file contains hourly PM10 concentration of 1 march to 7 march. Please, download from here. I have already plotted all the hourly variogram (total 161) in a loop by automap package. Here is the coad, this code work properly library(sp) library(gstat) library(rgdal) library(automap) library(latticeExtra) seoul1to7 seoul1to7[seoul1to7==0] seoul1to7 seoul1to7_split seq(seoul1to7_split) vars { dat coordinates(dat) proj4string(dat) dat variogram plot return(plot) }) vars[[1]] vars[[2]] Here, I can get the individual plot by `vars[[1]], vars[[2]]...`etc command but all the variogram has a same title. Now, I want to get all the variogram with different title in a loop. I want my variogram title be like, "Variogram for 2012-03-01 1.00", "Variogram for 2012-03-01 2.00" .....etc. To do this I wrote this code but It doesn't work! a a hours hours vars_hourlyvars_hourly[[1]] I keep my desired different title in `hours` variable like "2012-03-01 01:00", "2012-03-01 02:00", "2012-03-01 03:00" ...etc. could you please help me to plot all the variograms (total 161) with different title? I am badly struck with this problem. Thanks. Orpheus -------------- next part -------------- An HTML attachment was scrubbed... URL: From manuel.schneider at agroscope.admin.ch Thu Sep 3 10:50:17 2015 From: manuel.schneider at agroscope.admin.ch (Manuel Schneider) Date: Thu, 3 Sep 2015 08:50:17 +0000 Subject: [R-sig-Geo] Robust estimation with INLA References: <55E62FEC.8090201@yahoo.com> Message-ID: Lucy Mburu via R-sig-Geo r-project.org> writes: > > Hi all, > > I am trying to fit a spatial model with INLA, but I need to > incorporate the weights of influential points. I have estimated the > weights after running a robust regression model and stored the list of > weights as a named vector. Is there a possibility for including this > vector into the call for slm.inla? > In standard inla you have to set inla.setOption("enable.inla.argument.weights", TRUE) You can then use the weights arument in inla(). Maybe that works similarly in sim.inla. Always check carefully, as weighting can cause unwanted results. From binbinlu at whu.edu.cn Thu Sep 3 13:27:46 2015 From: binbinlu at whu.edu.cn (binbinlu at whu.edu.cn) Date: Thu, 3 Sep 2015 19:27:46 +0800 Subject: [R-sig-Geo] Error with gwr.mixed in GWmodel package References: Message-ID: <2015090319274650545517@whu.edu.cn> Hi Metastate, Yes, I found there is a problem in the function gwr.mixed, as the Line 119 code should be : SpatialPolygonsDataFrame(Sr=polygons, data=mgwr.df, match.ID=F) but the parameter "match.ID=F" is missed. I've revised it in the attached code. Currently you can re-source this function after loading the package. It will be fine to run you command. I will update the code in the next submission of package. Cheers. Best regards, Binbin From: Metastate Metastate Date: 2015-09-03 06:11 To: r-sig-geo Subject: [R-sig-Geo] Error with gwr.mixed in GWmodel package Hi, I applied the gwr.basic and gwr.mixed on the same SPDF file using the codes below. I got an error message on gwr.mixed: Error in SpatialPolygonsDataFrame(Sr = polygons, data = mgwr.df) : row.names of data and Polygons IDs do not match I had no problem with gwr.basic. The code I used was: gwr.res2 <- gwr.basic(Yield_Detrend~Tsfc_4_10+PCP_IN_7_8+PCP_IN_4_6, data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, F123.test = TRUE) mgwr.res2 <-gwr.mixed(Yield_Detrend~Tsfc_4_10+Pcp_30D_LT_2IN_4+PCP_IN_7_8 +Elevation, fixed.vars=c("Pcp_30D_LT_2IN_4", "Elevation"),data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, diagnostic=T) Also, Is it any easy way I can provide the spdf file if you need it to check? Thank you very much for your help. Meta [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: gwr.mixed.R Type: application/octet-stream Size: 5825 bytes Desc: not available URL: From mburulou at yahoo.com Thu Sep 3 15:10:46 2015 From: mburulou at yahoo.com (Lucy M.) Date: Thu, 3 Sep 2015 13:10:46 +0000 Subject: [R-sig-Geo] Robust estimation with INLA In-Reply-To: References: Message-ID: <203701572.951336.1441285846584.JavaMail.yahoo@mail.yahoo.com> Thanks a lot Manuel Schneider, the setting does work for slm.inla. I will check that the results have no problems. Regards, Lucy Mburu. On Thursday, September 3, 2015 10:51 AM, Manuel Schneider wrote: Lucy Mburu via R-sig-Geo r-project.org> writes: > > Hi all, > > I am trying to fit a spatial model with INLA, but I need to > incorporate the weights of influential points. I have estimated the > weights after running a robust regression model and stored the list of > weights as a named vector. Is there a possibility for including this > vector into the call for slm.inla? > In standard inla you have to set inla.setOption("enable.inla.argument.weights", TRUE) You can then use the weights arument in inla(). Maybe that works similarly in sim.inla. Always check carefully, as weighting can cause unwanted results. _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From debangs at uwaterloo.ca Thu Sep 3 16:05:59 2015 From: debangs at uwaterloo.ca (Donovan Bangs) Date: Thu, 3 Sep 2015 10:05:59 -0400 Subject: [R-sig-Geo] Updated RSAGA version and vignette on CRAN Message-ID: <002101d0e651$a97bb2a0$fc7317e0$@connect.uwaterloo.ca> Greetings R-sig-Geo, The latest version of RSAGA (0.94-3) is now available on CRAN. This package provides access to geocomputing and terrain analysis functions of SAGA GIS by running the command line version of SAGA. Updates to this package are compatible with SAGA versions 2.0.4 to 2.2.0 A vignette is now provided, giving an introduction and overview of geocomputing with RSAGA. The vignette provides a walk-through using RSAGA for terrain analysis and model prediction with grids using generalized additive modeling, in a case study of landslide susceptibility. Vignette on CRAN: https://cran.r-project.org/web/packages/RSAGA/vignettes/RSAGA-landslides.pdf Project Github: https://github.com/debangs/RSAGA Best Regards, Donovan Bangs From tim.appelhans at gmail.com Thu Sep 3 16:43:57 2015 From: tim.appelhans at gmail.com (Tim Appelhans) Date: Thu, 3 Sep 2015 16:43:57 +0200 Subject: [R-sig-Geo] Updated RSAGA version and vignette on CRAN In-Reply-To: <002101d0e651$a97bb2a0$fc7317e0$@connect.uwaterloo.ca> References: <002101d0e651$a97bb2a0$fc7317e0$@connect.uwaterloo.ca> Message-ID: <55E85CAD.5050707@gmail.com> Very nice! Thanks! Tim On 03.09.2015 16:05, Donovan Bangs wrote: > Greetings R-sig-Geo, > > The latest version of RSAGA (0.94-3) is now available on CRAN. This package > provides access to geocomputing and terrain analysis functions of SAGA GIS > by running the command line version of SAGA. Updates to this package are > compatible with SAGA versions 2.0.4 to 2.2.0 > > A vignette is now provided, giving an introduction and overview of > geocomputing with RSAGA. The vignette provides a walk-through using RSAGA > for terrain analysis and model prediction with grids using generalized > additive modeling, in a case study of landslide susceptibility. > > Vignette on CRAN: > https://cran.r-project.org/web/packages/RSAGA/vignettes/RSAGA-landslides.pdf > > Project Github: https://github.com/debangs/RSAGA > > Best Regards, > Donovan Bangs > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- ##################################### Tim Appelhans Department of Geography Environmental Informatics Philipps Universit?t Marburg Deutschhausstra?e 12 35032 Marburg (Paketpost: 35037 Marburg) Germany Tel +49 (0) 6421 28-25957 http://environmentalinformatics-marburg.de/ From uzzal at gist.ac.kr Thu Sep 3 17:28:08 2015 From: uzzal at gist.ac.kr (Uzzal) Date: Fri, 4 Sep 2015 00:28:08 +0900 (KST) Subject: [R-sig-Geo] How to extract a table of range, psill and nugget from multiple plotted variogram Message-ID: <104830461.1441294088446.JavaMail.root@eunhasu> Hello, I have a csv file named "seoul1to7" contains hourly pm10 concentration for around 105 sites collected for 7 days. Please download from here By using this dataset, I have plotted variogram for every hour of 7 days (total 161 variogram) using automap package in R. From every variogram, I can see that the range, sill and nugget value is written on the variogram plot. But I want to extract all the psill,range and nugget value in a table for every individual variogram (hour). Is it possible in R? [Actually, in future I want to make some graph using those range, sill and nugget to compare the changes]. I wrote the following code to plot 161 variogram : library(sp) library(gstat) library(rgdal) library(automap) library(latticeExtra) library(ggplot2)seoul1to7hoursvars.. vars[[161]] If you have any further query please let me know. Thanks in advance. Orpheus -------------- next part -------------- An HTML attachment was scrubbed... URL: From alannie.grant at pitt.edu Thu Sep 3 18:23:30 2015 From: alannie.grant at pitt.edu (Grant, Alannie Grace Gabrielle) Date: Thu, 3 Sep 2015 16:23:30 +0000 Subject: [R-sig-Geo] Resource for Global Average Maximum Monthly Temperature Message-ID: Hi All! I am trying to find an data set that consists of the average maximum monthly temperature for the world. What I mean by this is data for a particular month averaged across many years (ex: average maximum temperature for April from 1950-2000). I thought I found the correct resource from the United Nations Environment Programme http://geodata.grid.unep.ch/results.php however, the data seems to be missing something and there are not many different values. The data from here for average minimum temperature seems to be fine, containing a txt file for specific classes. Does anyone know of any other resources for this? Your assistance is appreciate! Alannie [[alternative HTML version deleted]] From metastate at gmail.com Fri Sep 4 01:24:08 2015 From: metastate at gmail.com (Metastate Metastate) Date: Thu, 3 Sep 2015 18:24:08 -0500 Subject: [R-sig-Geo] Error with gwr.mixed in GWmodel package In-Reply-To: <2015090318244797362614@whu.edu.cn> References: <2015090318244797362614@whu.edu.cn> Message-ID: Thank you very much, Dr. Lu. Regards, Meta On Thu, Sep 3, 2015 at 5:24 AM, binbinlu at whu.edu.cn wrote: > Hi Metastate, > > Yes, I found there is a problem in the function gwr.mixed, as the Line 119 > code should be : > SpatialPolygonsDataFrame(Sr=polygons, data=mgwr.df, match.ID=F) > but the parameter "match.ID=F" is missed. > I've revised it in the attached code. Currently you can re-source this > function after loading the package. It will be fine to run you command. I > will update the code in the next submission of package. Cheers. > > Best regards, > > Binbin > > > > *From:* Metastate Metastate > *Date:* 2015-09-03 06:11 > *To:* r-sig-geo > *Subject:* [R-sig-Geo] Error with gwr.mixed in GWmodel package > Hi, > > I applied the gwr.basic and gwr.mixed on the same SPDF file using the codes > below. I got an error message on gwr.mixed: > > Error in SpatialPolygonsDataFrame(Sr = polygons, data = mgwr.df) : > row.names of data and Polygons IDs do not match > > I had no problem with gwr.basic. > > The code I used was: > > gwr.res2 <- gwr.basic(Yield_Detrend~Tsfc_4_10+PCP_IN_7_8+PCP_IN_4_6, > data = Yield.spdf.sub,kernel = "bisquare", adaptive = TRUE, bw=50, > F123.test = TRUE) > > mgwr.res2 <-gwr.mixed(Yield_Detrend~Tsfc_4_10+Pcp_30D_LT_2IN_4+PCP_IN_7_8 > +Elevation, fixed.vars=c("Pcp_30D_LT_2IN_4", > "Elevation"),data = Yield.spdf.sub,kernel = "bisquare", adaptive = > TRUE, bw=50, diagnostic=T) > > Also, Is it any easy way I can provide the spdf file if you need it to > check? > > Thank you very much for your help. > > Meta > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > [[alternative HTML version deleted]] From hiztirab at yahoo.com Fri Sep 4 05:39:03 2015 From: hiztirab at yahoo.com (Iztirab Hussain) Date: Fri, 4 Sep 2015 03:39:03 +0000 (UTC) Subject: [R-sig-Geo] Working with .ai file in R In-Reply-To: <291497384.1451198.1441337447753.JavaMail.yahoo@mail.yahoo.com> References: <291497384.1451198.1441337447753.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1991432482.1430691.1441337943243.JavaMail.yahoo@mail.yahoo.com> Hi I have to import/load adobe illustrator file (ai.) in R to work on it, please guid me. RegardsIrfanBeijing, China On Friday, September 4, 2015 11:30 AM, Iztirab Hussain wrote: Hi I have to import/load adobe illustrator file (ai.) in R to work on it, please guid me. RegardsIrfanBeijing, China [[alternative HTML version deleted]] From timjp at unimelb.edu.au Fri Sep 4 06:31:45 2015 From: timjp at unimelb.edu.au (Tim Peterson) Date: Fri, 4 Sep 2015 14:31:45 +1000 Subject: [R-sig-Geo] Gstat 'polylines' implemented in R? Message-ID: <55E91EB1.2030803@unimelb.edu.au> Hi all, I'm keen to use the gstat feature 'polylines' (appendix B in http://www.gstat.org/gstat.pdf) to restrict the point sample selection to within a polygon. That is, when undertaking localised kriging at a grid cell, samples are only used in the estimation if a line between the sample and grid cell does not cross a polygon boundary. The polylines feature appears to be implemented within the c-code for gstat (polygon.c) but I cannot find any means to use it within R-gstat nor any mention on lists. Any tips would be most welcome. Thanks, Tim ---------------------- Dr. Tim Peterson The Department of Infrastructure Engineering The University of Melbourne, 3010 Australia T: +61 3 8344 9950 , M: +61 0438 385 937 Dept. profile : http://www.ie.unimelb.edu.au/people/staff.php?person_ID=141135 Research Gate : https://www.researchgate.net/profile/Tim_Peterson7 Google Scholar: http://scholar.google.com.au/citations?user=kkYJLF4AAAAJ&hl=en&oi=ao [[alternative HTML version deleted]] From edzer.pebesma at uni-muenster.de Fri Sep 4 10:50:03 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 4 Sep 2015 10:50:03 +0200 Subject: [R-sig-Geo] Gstat 'polylines' implemented in R? In-Reply-To: <55E91EB1.2030803@unimelb.edu.au> References: <55E91EB1.2030803@unimelb.edu.au> Message-ID: <55E95B3B.20504@uni-muenster.de> On 09/04/2015 06:31 AM, Tim Peterson wrote: > Hi all, > > I'm keen to use the gstat feature 'polylines' (appendix B in > http://www.gstat.org/gstat.pdf) to restrict the point sample selection > to within a polygon. That is, when undertaking localised kriging at a > grid cell, samples are only used in the estimation if a line between the > sample and grid cell does not cross a polygon boundary. The polylines > feature appears to be implemented within the c-code for gstat > (polygon.c) but I cannot find any means to use it within R-gstat nor any > mention on lists. Any tips would be most welcome. That is correct, it has not been interfaced from the R code. The idea is nice, but if you work with it you see very very much unwanted features in the interpolated surface: sharp edges that follow the "shadow" of the polygon, as seen from an observation with an extreme value. Back then we thought about a work-around for this using distances measured "around" the obstacles, but that leads to non-positive definite covariance functions. > > Thanks, > > Tim > > ---------------------- > Dr. Tim Peterson > > The Department of Infrastructure Engineering > The University of Melbourne, 3010 Australia > T: +61 3 8344 9950 , M: +61 0438 385 937 > > > Dept. profile : > http://www.ie.unimelb.edu.au/people/staff.php?person_ID=141135 > Research Gate : https://www.researchgate.net/profile/Tim_Peterson7 > Google Scholar: > http://scholar.google.com.au/citations?user=kkYJLF4AAAAJ&hl=en&oi=ao > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From antonio.bubbico at gmail.com Fri Sep 4 12:50:28 2015 From: antonio.bubbico at gmail.com (Antonio Bubbico) Date: Fri, 4 Sep 2015 11:50:28 +0100 Subject: [R-sig-Geo] SDM and SDEM with binary dependent variables Message-ID: Hello, I would like to ask you if you know there is some package I can use to run several spatial econometric models with binary dependent variable. In particular, I would like to run a Spatial Durbin model and the Spatial Durbin Error model. Regards. -- *Dr Antonio Bubbico* Postdoctoral Researcher *School of Agriculture and Food ScienceUniversity College DublinBelfield, Dublin 4Ireland* Tel: +353899528966 e-mail: a ntonio.bubbico at gmail.com Room: 1.27 [[alternative HTML version deleted]] From virgilio.gomez at uclm.es Fri Sep 4 13:01:41 2015 From: virgilio.gomez at uclm.es (Virgilio =?ISO-8859-1?Q?G=F3mez-Rubio?=) Date: Fri, 4 Sep 2015 13:01:41 +0200 Subject: [R-sig-Geo] SDM and SDEM with binary dependent variables In-Reply-To: References: Message-ID: <1441364501.2207.6.camel@uclm.es> Hi, > I would like to ask you if you know there is some package I can use to run > several spatial econometric models with binary dependent variable. > In particular, I would like to run a Spatial Durbin model and the Spatial > Durbin Error model. Check the spatialprobit package and function sarprobit(). Best, Virgilio From Roger.Bivand at nhh.no Fri Sep 4 13:10:54 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 4 Sep 2015 13:10:54 +0200 Subject: [R-sig-Geo] SDM and SDEM with binary dependent variables In-Reply-To: <1441364501.2207.6.camel@uclm.es> References: <1441364501.2207.6.camel@uclm.es> Message-ID: On Fri, 4 Sep 2015, Virgilio G?mez-Rubio wrote: > Hi, > >> I would like to ask you if you know there is some package I can use to run >> several spatial econometric models with binary dependent variable. >> In particular, I would like to run a Spatial Durbin model and the Spatial >> Durbin Error model. > > Check the spatialprobit package and function sarprobit(). Right, and there is semprobit() there too. You can generate the WX's with spdep::create_WX(). Other spatial binary response functions are in the McSpatial package: gmmlogit, gmmprobit, splogit, spprobit, spprobitml. Roger > > Best, > > Virgilio > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From ignacio82 at gmail.com Fri Sep 4 15:29:14 2015 From: ignacio82 at gmail.com (Ignacio Martinez) Date: Fri, 04 Sep 2015 13:29:14 +0000 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ Message-ID: I'm trying to create a map using leaflet. I'm basically following this but my data is a bit different this time around. Additionally, I'm using dplyr instead of data.table. This is the code i'm trying to run: counts <- structure( list( STUSPS = c( "CA", "NC", "TX", "FL", "VA", "OH", "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", "DC", "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", "MO", "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", "MT", "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", "NH", "DE", "PR", "GU", "VI", "MP", "AS" ), count = c( 36511L, 27513L, 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, 13753L, 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, 7985L, 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, 6429L, 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, 4694L, 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, 2143L, 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L ) ), .Names = c("STUSPS", "count"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,-56L) ) x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr") lapply(x, library, character.only = TRUE) # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", layer = "cb_2014_us_state_5m", verbose = FALSE) # Make a copy of the SPDF attribute table, and then work normally, as with any data.frame/data.table object states.df <- states at data # Create an explicit attribute to keep polygons IDs (useful to "re-attach" the table to the polygons later) states.df <- states.df %>% mutate(rn=row.names(states)) # join them states.df <- full_join(x = states.df, y = counts, by="STUSPS") %>% filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% na.omit() %>% mutate(popup=paste0('',NAME,'','
', 'count: ', prettyNum(count,big.mark=",",scientific=FALSE))) # Re-attach the attribute table to the SPDF states at data <- states.df # Make sure polygons IDs and data.frame row.names match states <- spChFIDs(states, states$rn) # Create map as usual... The error I get is: Error in spChFIDs(SP, x) : lengths differ Thanks for the help! Ignacio [[alternative HTML version deleted]] From edzer.pebesma at uni-muenster.de Fri Sep 4 15:50:40 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 4 Sep 2015 15:50:40 +0200 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: References: Message-ID: <55E9A1B0.1090105@uni-muenster.de> On 09/04/2015 03:29 PM, Ignacio Martinez wrote: > I'm trying to create a map using leaflet. I'm basically following this > but my data is a bit > different this time around. Additionally, I'm using dplyr instead of > data.table. > > This is the code i'm trying to run: > > counts <- > structure( > list( > STUSPS = c( > "CA", "NC", "TX", "FL", "VA", "OH", > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", > "DC", > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", > "MO", > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", > "MT", > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", > "NH", > "DE", "PR", "GU", "VI", "MP", "AS" > ), count = c( > 36511L, 27513L, > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, 13753L, > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, 7985L, > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, 6429L, > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, 4694L, > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, 2143L, > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L > ) > ), .Names = c("STUSPS", > "count"), class = c("tbl_df", "tbl", "data.frame"), > row.names = c(NA,-56L) > ) > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr") > lapply(x, library, character.only = TRUE) > # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > layer = "cb_2014_us_state_5m", verbose = FALSE) > # Make a copy of the SPDF attribute table, and then work normally, as > with any data.frame/data.table object > states.df <- states at data > # Create an explicit attribute to keep polygons IDs (useful to > "re-attach" the table to the polygons later) > states.df <- states.df %>% mutate(rn=row.names(states)) > > # join them > states.df <- full_join(x = states.df, y = counts, by="STUSPS") %>% > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% na.omit() %>% > mutate(popup=paste0('',NAME,'','
', > 'count: ', > prettyNum(count,big.mark=",",scientific=FALSE))) at this stage, you have: > dim(states at data) [1] 56 9 > dim(states.df) [1] 55 12 > > # Re-attach the attribute table to the SPDF > states at data <- states.df now, you created an invalid object: > length(geometry(states)) [1] 56 > dim(states at data) [1] 55 12 this confirms once more what has been said on this list so often, that instead of using constructor functions such as SpatialPolygonsDataFrame(), assigning slots directly is dangerous and better left to those who know what they do (and check sanity): > states <- SpatialPolygonsDataFrame(geometry(states), states.df) Error in SpatialPolygonsDataFrame(geometry(states), states.df) : Object length mismatch: geometry(states) has 56 Polygons objects, but states.df has 55 rows > # Make sure polygons IDs and data.frame row.names match > states <- spChFIDs(states, states$rn) > > # Create map as usual... > > The error I get is: > > Error in spChFIDs(SP, x) : lengths differ > > > Thanks for the help! > > > Ignacio > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From ignacio82 at gmail.com Fri Sep 4 15:53:48 2015 From: ignacio82 at gmail.com (Ignacio Martinez) Date: Fri, 04 Sep 2015 13:53:48 +0000 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: <55E9A1B0.1090105@uni-muenster.de> References: <55E9A1B0.1090105@uni-muenster.de> Message-ID: Thanks Edzer. I think I understand the problem better now (this is all very new to me). Is there a solution so I can generate the map with my data? Thanks again! On Fri, Sep 4, 2015 at 9:51 AM Edzer Pebesma wrote: > > > On 09/04/2015 03:29 PM, Ignacio Martinez wrote: > > I'm trying to create a map using leaflet. I'm basically following this > > but my data is a bit > > different this time around. Additionally, I'm using dplyr instead of > > data.table. > > > > This is the code i'm trying to run: > > > > counts <- > > structure( > > list( > > STUSPS = c( > > "CA", "NC", "TX", "FL", "VA", "OH", > > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", > > "DC", > > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", > > "MO", > > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", > > "MT", > > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", > > "NH", > > "DE", "PR", "GU", "VI", "MP", "AS" > > ), count = c( > > 36511L, 27513L, > > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, > 13753L, > > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, > 7985L, > > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, > 6429L, > > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, > 4694L, > > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, > 2143L, > > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L > > ) > > ), .Names = c("STUSPS", > > "count"), class = c("tbl_df", "tbl", "data.frame"), > > row.names = c(NA,-56L) > > ) > > > > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr") > > lapply(x, library, character.only = TRUE) > > # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > > layer = "cb_2014_us_state_5m", verbose = FALSE) > > # Make a copy of the SPDF attribute table, and then work normally, as > > with any data.frame/data.table object > > states.df <- states at data > > # Create an explicit attribute to keep polygons IDs (useful to > > "re-attach" the table to the polygons later) > > states.df <- states.df %>% mutate(rn=row.names(states)) > > > > # join them > > states.df <- full_join(x = states.df, y = counts, by="STUSPS") %>% > > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% na.omit() > %>% > > mutate(popup=paste0('',NAME,'','
', > > 'count: ', > > prettyNum(count,big.mark=",",scientific=FALSE))) > > at this stage, you have: > > > dim(states at data) > [1] 56 9 > > dim(states.df) > [1] 55 12 > > > > > # Re-attach the attribute table to the SPDF > > states at data <- states.df > > now, you created an invalid object: > > length(geometry(states)) > [1] 56 > > dim(states at data) > [1] 55 12 > > this confirms once more what has been said on this list so often, that > instead of using constructor functions such as > SpatialPolygonsDataFrame(), assigning slots directly is dangerous and > better left to those who know what they do (and check sanity): > > > states <- SpatialPolygonsDataFrame(geometry(states), states.df) > Error in SpatialPolygonsDataFrame(geometry(states), states.df) : > Object length mismatch: > geometry(states) has 56 Polygons objects, but states.df has 55 rows > > > > # Make sure polygons IDs and data.frame row.names match > > states <- spChFIDs(states, states$rn) > > > > # Create map as usual... > > > > The error I get is: > > > > Error in spChFIDs(SP, x) : lengths differ > > > > > > Thanks for the help! > > > > > > Ignacio > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo at r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of M?nster, > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > Journal of Statistical Software: http://www.jstatsoft.org/ > Computers & Geosciences: http://elsevier.com/locate/cageo/ > Spatial Statistics Society http://www.spatialstatistics.info > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] From edzer.pebesma at uni-muenster.de Fri Sep 4 17:47:14 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 4 Sep 2015 17:47:14 +0200 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: References: <55E9A1B0.1090105@uni-muenster.de> Message-ID: <55E9BD02.3040705@uni-muenster.de> On 09/04/2015 03:53 PM, Ignacio Martinez wrote: > Thanks Edzer. I think I understand the problem better now (this is all > very new to me). Is there a solution so I can generate the map with my data? > The STUSPS fields of counts and states match, but you seem to filter the attribute table after you merged counts and states, which drops PR, but doesn't take it out of states: > match(c("PR", "na", "MH", "FM", "PW"), counts$STUSPS) [1] 52 NA NA NA NA So, in case you want to deselect PR, a shorter way to get there is > m = merge(states, counts) # uses sp::merge.Spatial > m = m[-which(m$STUSPS == "PR"),] > length(m) [1] 55 > Thanks again! > > On Fri, Sep 4, 2015 at 9:51 AM Edzer Pebesma > > > wrote: > > > > On 09/04/2015 03:29 PM, Ignacio Martinez wrote: > > I'm trying to create a map using leaflet. I'm basically following this > > but my data is a bit > > different this time around. Additionally, I'm using dplyr instead of > > data.table. > > > > This is the code i'm trying to run: > > > > counts <- > > structure( > > list( > > STUSPS = c( > > "CA", "NC", "TX", "FL", "VA", "OH", > > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", > "KS", > > "DC", > > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", > "OK", > > "MO", > > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", > "IA", > > "MT", > > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", > "RI", > > "NH", > > "DE", "PR", "GU", "VI", "MP", "AS" > > ), count = c( > > 36511L, 27513L, > > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, > 13923L, 13753L, > > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, > 8076L, 7985L, > > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, > 6674L, 6429L, > > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, > 4797L, 4694L, > > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, > 2156L, 2143L, > > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L > > ) > > ), .Names = c("STUSPS", > > "count"), class = c("tbl_df", "tbl", > "data.frame"), > > row.names = c(NA,-56L) > > ) > > > > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr") > > lapply(x, library, character.only = TRUE) > > # From > https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > > layer = "cb_2014_us_state_5m", verbose = FALSE) > > # Make a copy of the SPDF attribute table, and then work > normally, as > > with any data.frame/data.table object > > states.df <- states at data > > # Create an explicit attribute to keep polygons IDs (useful to > > "re-attach" the table to the polygons later) > > states.df <- states.df %>% mutate(rn=row.names(states)) > > > > # join them > > states.df <- full_join(x = states.df, y = counts, by="STUSPS") %>% > > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% > na.omit() %>% > > mutate(popup=paste0('',NAME,'','
', > > 'count: ', > > prettyNum(count,big.mark=",",scientific=FALSE))) > > at this stage, you have: > > > dim(states at data) > [1] 56 9 > > dim(states.df) > [1] 55 12 > > > > > # Re-attach the attribute table to the SPDF > > states at data <- states.df > > now, you created an invalid object: > > length(geometry(states)) > [1] 56 > > dim(states at data) > [1] 55 12 > > this confirms once more what has been said on this list so often, that > instead of using constructor functions such as > SpatialPolygonsDataFrame(), assigning slots directly is dangerous and > better left to those who know what they do (and check sanity): > > > states <- SpatialPolygonsDataFrame(geometry(states), states.df) > Error in SpatialPolygonsDataFrame(geometry(states), states.df) : > Object length mismatch: > geometry(states) has 56 Polygons objects, but states.df has 55 rows > > > > # Make sure polygons IDs and data.frame row.names match > > states <- spChFIDs(states, states$rn) > > > > # Create map as usual... > > > > The error I get is: > > > > Error in spChFIDs(SP, x) : lengths differ > > > > > > Thanks for the help! > > > > > > Ignacio > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo at r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of M?nster, > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > Journal of Statistical Software: http://www.jstatsoft.org/ > Computers & Geosciences: http://elsevier.com/locate/cageo/ > Spatial Statistics Society http://www.spatialstatistics.info > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From ignacio82 at gmail.com Fri Sep 4 17:59:17 2015 From: ignacio82 at gmail.com (Ignacio Martinez) Date: Fri, 04 Sep 2015 15:59:17 +0000 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: <55E9BD02.3040705@uni-muenster.de> References: <55E9A1B0.1090105@uni-muenster.de> <55E9BD02.3040705@uni-muenster.de> Message-ID: I'm not sure what I'm missing. This is not working (same error): counts <- structure( list( STUSPS = c( "CA", "NC", "TX", "FL", "VA", "OH", "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", "DC", "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", "MO", "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", "MT", "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", "NH", "DE", "PR", "GU", "VI", "MP", "AS" ), count = c( 36511L, 27513L, 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, 13753L, 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, 7985L, 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, 6429L, 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, 4694L, 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, 2143L, 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L ) ), .Names = c("STUSPS", "count"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,-56L) ) x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr", "sp") lapply(x, library, character.only = TRUE) # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", layer = "cb_2014_us_state_5m", verbose = FALSE) # Make a copy of the SPDF attribute table, and then work normally, as with any data.frame/data.table object states.df <- states at data # Create an explicit attribute to keep polygons IDs (useful to "re-attach" the table to the polygons later) states.df <- states.df %>% mutate(rn=row.names(states)) # join them US = merge(states.df, counts) # uses sp::merge.Spatial US = US[-which(US$STUSPS == "PR"),] # Re-attach the attribute table to the SPDF states at data <- US # Make sure polygons IDs and data.frame row.names match states <- spChFIDs(states, states$rn) Thanks! On Fri, Sep 4, 2015 at 11:47 AM Edzer Pebesma wrote: > On 09/04/2015 03:53 PM, Ignacio Martinez wrote: > > Thanks Edzer. I think I understand the problem better now (this is all > > very new to me). Is there a solution so I can generate the map with my > data? > > > > The STUSPS fields of counts and states match, but you seem to filter the > attribute table after you merged counts and states, which drops PR, but > doesn't take it out of states: > > > match(c("PR", "na", "MH", "FM", "PW"), counts$STUSPS) > [1] 52 NA NA NA NA > > So, in case you want to deselect PR, a shorter way to get there is > > > m = merge(states, counts) # uses sp::merge.Spatial > > m = m[-which(m$STUSPS == "PR"),] > > length(m) > [1] 55 > > > > > Thanks again! > > > > On Fri, Sep 4, 2015 at 9:51 AM Edzer Pebesma > > > > > wrote: > > > > > > > > On 09/04/2015 03:29 PM, Ignacio Martinez wrote: > > > I'm trying to create a map using leaflet. I'm basically following > this > > > but my data is a > bit > > > different this time around. Additionally, I'm using dplyr instead > of > > > data.table. > > > > > > This is the code i'm trying to run: > > > > > > counts <- > > > structure( > > > list( > > > STUSPS = c( > > > "CA", "NC", "TX", "FL", "VA", "OH", > > > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", > > "KS", > > > "DC", > > > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", > > "OK", > > > "MO", > > > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", > > "IA", > > > "MT", > > > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", > > "RI", > > > "NH", > > > "DE", "PR", "GU", "VI", "MP", "AS" > > > ), count = c( > > > 36511L, 27513L, > > > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, > > 13923L, 13753L, > > > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, > > 8076L, 7985L, > > > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, > > 6674L, 6429L, > > > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, > > 4797L, 4694L, > > > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, > > 2156L, 2143L, > > > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, > 2L > > > ) > > > ), .Names = c("STUSPS", > > > "count"), class = c("tbl_df", "tbl", > > "data.frame"), > > > row.names = c(NA,-56L) > > > ) > > > > > > > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", > "dplyr") > > > lapply(x, library, character.only = TRUE) > > > # From > > https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > > > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > > > layer = "cb_2014_us_state_5m", verbose = > FALSE) > > > # Make a copy of the SPDF attribute table, and then work > > normally, as > > > with any data.frame/data.table object > > > states.df <- states at data > > > # Create an explicit attribute to keep polygons IDs (useful to > > > "re-attach" the table to the polygons later) > > > states.df <- states.df %>% mutate(rn=row.names(states)) > > > > > > # join them > > > states.df <- full_join(x = states.df, y = counts, by="STUSPS") > %>% > > > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% > > na.omit() %>% > > > mutate(popup=paste0('',NAME,'','
', > > > 'count: ', > > > prettyNum(count,big.mark=",",scientific=FALSE))) > > > > at this stage, you have: > > > > > dim(states at data) > > [1] 56 9 > > > dim(states.df) > > [1] 55 12 > > > > > > > > # Re-attach the attribute table to the SPDF > > > states at data <- states.df > > > > now, you created an invalid object: > > > length(geometry(states)) > > [1] 56 > > > dim(states at data) > > [1] 55 12 > > > > this confirms once more what has been said on this list so often, > that > > instead of using constructor functions such as > > SpatialPolygonsDataFrame(), assigning slots directly is dangerous and > > better left to those who know what they do (and check sanity): > > > > > states <- SpatialPolygonsDataFrame(geometry(states), states.df) > > Error in SpatialPolygonsDataFrame(geometry(states), states.df) : > > Object length mismatch: > > geometry(states) has 56 Polygons objects, but states.df has 55 > rows > > > > > > > # Make sure polygons IDs and data.frame row.names match > > > states <- spChFIDs(states, states$rn) > > > > > > # Create map as usual... > > > > > > The error I get is: > > > > > > Error in spChFIDs(SP, x) : lengths differ > > > > > > > > > Thanks for the help! > > > > > > > > > Ignacio > > > > > > [[alternative HTML version deleted]] > > > > > > _______________________________________________ > > > R-sig-Geo mailing list > > > R-sig-Geo at r-project.org > > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > > > > -- > > Edzer Pebesma > > Institute for Geoinformatics (ifgi), University of M?nster, > > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > > Journal of Statistical Software: http://www.jstatsoft.org/ > > Computers & Geosciences: http://elsevier.com/locate/cageo/ > > Spatial Statistics Society http://www.spatialstatistics.info > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo at r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of M?nster, > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > Journal of Statistical Software: http://www.jstatsoft.org/ > Computers & Geosciences: http://elsevier.com/locate/cageo/ > Spatial Statistics Society http://www.spatialstatistics.info > > [[alternative HTML version deleted]] From ignacio82 at gmail.com Fri Sep 4 18:36:19 2015 From: ignacio82 at gmail.com (Ignacio Martinez) Date: Fri, 04 Sep 2015 16:36:19 +0000 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: References: <55E9A1B0.1090105@uni-muenster.de> <55E9BD02.3040705@uni-muenster.de> Message-ID: This works :-) : library(dplyr) library(leaflet) library(rgdal) library(sp) states <- rgdal::readOGR(dsn = "./cb_2014_us_state_5m.shp", layer = "cb_2014_us_state_5m", verbose = FALSE) statesnames <- states at data %>% mutate(STUSPS = as.character(STUSPS)) %>% select(NAME, STUSPS) counts <- structure( list( STUSPS = c( "TX", "CA", "FL", "OH", "NY", "CO", "MI", "IL", "PA", "NJ", "VA", "NC", "GA", "WA", "MN", "MD", "AZ", "IA", "MA", "WI", "TN", "LA", "IN", "SC", "KY", "ID", "MO", "AL", "OK", "CT", "KS", "OR", "UT", "NE", "ND", "NV", "MS", "AR", "SD", "MT", "DC", "WY", "AK", "NM", "HI", "NH", "WV", "ME", "RI", "DE", "VT", "PR", "VI" ), count = c( 12031L, 11968L, 7232L, 5113L, 4733L, 4392L, 4251L, 4168L, 3640L, 3374L, 3371L, 3284L, 3084L, 2837L, 2662L, 2650L, 2528L, 2414L, 2378L, 2373L, 2236L, 2158L, 2120L, 1959L, 1758L, 1700L, 1547L, 1466L, 1445L, 1345L, 1305L, 1297L, 1253L, 1234L, 1166L, 1063L, 981L, 963L, 915L, 718L, 673L, 653L, 650L, 637L, 579L, 561L, 510L, 496L, 486L, 396L, 273L, 6L, 5L ) ), .Names = c("STUSPS", "count"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,-53L) ) counts <- counts %>% inner_join(statesnames, by = "STUSPS") %>% mutate(popup = paste0( '',NAME,'','
', 'Number: ', prettyNum(count,big.mark = ",",scientific = FALSE) )) USA <- merge(states, counts) # uses sp::merge.Spatial USA <- USA[-which(USA$STUSPS %in% as.character(USA at data$STUSPS[is.na (USA at data$count)])),] pal <- colorNumeric( palette = "Greens", domain = USA$count) leaflet(USA, height = "490px", width = "800px") %>% addPolygons( stroke = FALSE, smoothFactor = 0.2, fillOpacity = 1, color = ~ pal(count), popup = ~popup ) %>% setView(lng = -98.579394, lat = 37, zoom = 4) %>% addLegend(position = "bottomright", pal = pal, title = "Number", opacity = 1, values = USA$count) Please let me know if you see something that I could be doing better. Thanks a lot! Ignacio On Fri, Sep 4, 2015 at 11:59 AM Ignacio Martinez wrote: > I'm not sure what I'm missing. This is not working (same error): > > counts <- > structure( > list( > STUSPS = c( > "CA", "NC", "TX", "FL", "VA", "OH", > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", > "DC", > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", > "MO", > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", > "MT", > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", > "NH", > "DE", "PR", "GU", "VI", "MP", "AS" > ), count = c( > 36511L, 27513L, > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, 13753L, > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, > 7985L, > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, 6429L, > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, 4694L, > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, 2143L, > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L > ) > ), .Names = c("STUSPS", > "count"), class = c("tbl_df", "tbl", "data.frame"), > row.names = c(NA,-56L) > ) > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr", > "sp") > lapply(x, library, character.only = TRUE) > # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > layer = "cb_2014_us_state_5m", verbose = FALSE) > # Make a copy of the SPDF attribute table, and then work normally, as > with any data.frame/data.table object > states.df <- states at data > # Create an explicit attribute to keep polygons IDs (useful to > "re-attach" the table to the polygons later) > states.df <- states.df %>% mutate(rn=row.names(states)) > > # join them > > US = merge(states.df, counts) # uses sp::merge.Spatial > US = US[-which(US$STUSPS == "PR"),] > > > # Re-attach the attribute table to the SPDF > states at data <- US > # Make sure polygons IDs and data.frame row.names match > states <- spChFIDs(states, states$rn) > > Thanks! > > On Fri, Sep 4, 2015 at 11:47 AM Edzer Pebesma < > edzer.pebesma at uni-muenster.de> wrote: > >> On 09/04/2015 03:53 PM, Ignacio Martinez wrote: >> > Thanks Edzer. I think I understand the problem better now (this is all >> > very new to me). Is there a solution so I can generate the map with my >> data? >> > >> >> The STUSPS fields of counts and states match, but you seem to filter the >> attribute table after you merged counts and states, which drops PR, but >> doesn't take it out of states: >> >> > match(c("PR", "na", "MH", "FM", "PW"), counts$STUSPS) >> [1] 52 NA NA NA NA >> >> So, in case you want to deselect PR, a shorter way to get there is >> >> > m = merge(states, counts) # uses sp::merge.Spatial >> > m = m[-which(m$STUSPS == "PR"),] >> > length(m) >> [1] 55 >> >> >> >> > Thanks again! >> > >> > On Fri, Sep 4, 2015 at 9:51 AM Edzer Pebesma >> > > >> > wrote: >> > >> > >> > >> > On 09/04/2015 03:29 PM, Ignacio Martinez wrote: >> > > I'm trying to create a map using leaflet. I'm basically following >> this >> > > but my data is a >> bit >> > > different this time around. Additionally, I'm using dplyr instead >> of >> > > data.table. >> > > >> > > This is the code i'm trying to run: >> > > >> > > counts <- >> > > structure( >> > > list( >> > > STUSPS = c( >> > > "CA", "NC", "TX", "FL", "VA", "OH", >> > > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", >> > "KS", >> > > "DC", >> > > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", >> > "OK", >> > > "MO", >> > > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", >> > "IA", >> > > "MT", >> > > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", >> > "RI", >> > > "NH", >> > > "DE", "PR", "GU", "VI", "MP", "AS" >> > > ), count = c( >> > > 36511L, 27513L, >> > > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, >> > 13923L, 13753L, >> > > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, >> > 8076L, 7985L, >> > > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, >> > 6674L, 6429L, >> > > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, >> > 4797L, 4694L, >> > > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, >> > 2156L, 2143L, >> > > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, >> 7L, 2L >> > > ) >> > > ), .Names = c("STUSPS", >> > > "count"), class = c("tbl_df", "tbl", >> > "data.frame"), >> > > row.names = c(NA,-56L) >> > > ) >> > > >> > > >> > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", >> "dplyr") >> > > lapply(x, library, character.only = TRUE) >> > > # From >> > https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html >> > > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", >> > > layer = "cb_2014_us_state_5m", verbose = >> FALSE) >> > > # Make a copy of the SPDF attribute table, and then work >> > normally, as >> > > with any data.frame/data.table object >> > > states.df <- states at data >> > > # Create an explicit attribute to keep polygons IDs (useful to >> > > "re-attach" the table to the polygons later) >> > > states.df <- states.df %>% mutate(rn=row.names(states)) >> > > >> > > # join them >> > > states.df <- full_join(x = states.df, y = counts, >> by="STUSPS") %>% >> > > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% >> > na.omit() %>% >> > > mutate(popup=paste0('',NAME,'','
', >> > > 'count: ', >> > > prettyNum(count,big.mark=",",scientific=FALSE))) >> > >> > at this stage, you have: >> > >> > > dim(states at data) >> > [1] 56 9 >> > > dim(states.df) >> > [1] 55 12 >> > >> > > >> > > # Re-attach the attribute table to the SPDF >> > > states at data <- states.df >> > >> > now, you created an invalid object: >> > > length(geometry(states)) >> > [1] 56 >> > > dim(states at data) >> > [1] 55 12 >> > >> > this confirms once more what has been said on this list so often, >> that >> > instead of using constructor functions such as >> > SpatialPolygonsDataFrame(), assigning slots directly is dangerous >> and >> > better left to those who know what they do (and check sanity): >> > >> > > states <- SpatialPolygonsDataFrame(geometry(states), states.df) >> > Error in SpatialPolygonsDataFrame(geometry(states), states.df) : >> > Object length mismatch: >> > geometry(states) has 56 Polygons objects, but states.df has 55 >> rows >> > >> > >> > > # Make sure polygons IDs and data.frame row.names match >> > > states <- spChFIDs(states, states$rn) >> > > >> > > # Create map as usual... >> > > >> > > The error I get is: >> > > >> > > Error in spChFIDs(SP, x) : lengths differ >> > > >> > > >> > > Thanks for the help! >> > > >> > > >> > > Ignacio >> > > >> > > [[alternative HTML version deleted]] >> > > >> > > _______________________________________________ >> > > R-sig-Geo mailing list >> > > R-sig-Geo at r-project.org >> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > >> > >> > -- >> > Edzer Pebesma >> > Institute for Geoinformatics (ifgi), University of M?nster, >> > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 >> > Journal of Statistical Software: http://www.jstatsoft.org/ >> > Computers & Geosciences: http://elsevier.com/locate/cageo/ >> > Spatial Statistics Society http://www.spatialstatistics.info >> > >> > _______________________________________________ >> > R-sig-Geo mailing list >> > R-sig-Geo at r-project.org >> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > >> >> -- >> Edzer Pebesma >> Institute for Geoinformatics (ifgi), University of M?nster, >> Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 >> Journal of Statistical Software: http://www.jstatsoft.org/ >> Computers & Geosciences: http://elsevier.com/locate/cageo/ >> Spatial Statistics Society http://www.spatialstatistics.info >> >> [[alternative HTML version deleted]] From r.hijmans at gmail.com Sat Sep 5 13:26:34 2015 From: r.hijmans at gmail.com (Robert J. Hijmans) Date: Sat, 5 Sep 2015 04:26:34 -0700 Subject: [R-sig-Geo] [Help] Error in spChFIDs(SP, x) : lengths differ In-Reply-To: References: <55E9A1B0.1090105@uni-muenster.de> <55E9BD02.3040705@uni-muenster.de> Message-ID: There is no need to 'make a copy of the attribute table' of the sp object. Instead, you should be able to do: library(sp) # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", layer = "cb_2014_us_state_5m") states <- merge(states, counts) states <- states[-which(states$STUSPS == "PR"),] Robert On Fri, Sep 4, 2015 at 8:59 AM, Ignacio Martinez wrote: > I'm not sure what I'm missing. This is not working (same error): > > counts <- > structure( > list( > STUSPS = c( > "CA", "NC", "TX", "FL", "VA", "OH", > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", "KS", > "DC", > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", "OK", > "MO", > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", "IA", > "MT", > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", "RI", > "NH", > "DE", "PR", "GU", "VI", "MP", "AS" > ), count = c( > 36511L, 27513L, > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, 13923L, 13753L, > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, 8076L, 7985L, > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, 6674L, 6429L, > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, 4797L, 4694L, > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, 2156L, 2143L, > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, 2L > ) > ), .Names = c("STUSPS", > "count"), class = c("tbl_df", "tbl", "data.frame"), > row.names = c(NA,-56L) > ) > > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", "dplyr", "sp") > lapply(x, library, character.only = TRUE) > # From https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", > layer = "cb_2014_us_state_5m", verbose = FALSE) > # Make a copy of the SPDF attribute table, and then work normally, as > with any data.frame/data.table object > states.df <- states at data > # Create an explicit attribute to keep polygons IDs (useful to > "re-attach" the table to the polygons later) > states.df <- states.df %>% mutate(rn=row.names(states)) > > # join them > > US = merge(states.df, counts) # uses sp::merge.Spatial > US = US[-which(US$STUSPS == "PR"),] > > > # Re-attach the attribute table to the SPDF > states at data <- US > # Make sure polygons IDs and data.frame row.names match > states <- spChFIDs(states, states$rn) > > Thanks! > > On Fri, Sep 4, 2015 at 11:47 AM Edzer Pebesma > wrote: > >> On 09/04/2015 03:53 PM, Ignacio Martinez wrote: >> > Thanks Edzer. I think I understand the problem better now (this is all >> > very new to me). Is there a solution so I can generate the map with my >> data? >> > >> >> The STUSPS fields of counts and states match, but you seem to filter the >> attribute table after you merged counts and states, which drops PR, but >> doesn't take it out of states: >> >> > match(c("PR", "na", "MH", "FM", "PW"), counts$STUSPS) >> [1] 52 NA NA NA NA >> >> So, in case you want to deselect PR, a shorter way to get there is >> >> > m = merge(states, counts) # uses sp::merge.Spatial >> > m = m[-which(m$STUSPS == "PR"),] >> > length(m) >> [1] 55 >> >> >> >> > Thanks again! >> > >> > On Fri, Sep 4, 2015 at 9:51 AM Edzer Pebesma >> > > >> > wrote: >> > >> > >> > >> > On 09/04/2015 03:29 PM, Ignacio Martinez wrote: >> > > I'm trying to create a map using leaflet. I'm basically following >> this >> > > but my data is a >> bit >> > > different this time around. Additionally, I'm using dplyr instead >> of >> > > data.table. >> > > >> > > This is the code i'm trying to run: >> > > >> > > counts <- >> > > structure( >> > > list( >> > > STUSPS = c( >> > > "CA", "NC", "TX", "FL", "VA", "OH", >> > > "NY", "GA", "IL", "WA", "CO", "AZ", "MD", "LA", "SC", >> > "KS", >> > > "DC", >> > > "TN", "MA", "MI", "MN", "NJ", "WI", "PA", "AL", "KY", >> > "OK", >> > > "MO", >> > > "ID", "MS", "NM", "IN", "NV", "AR", "OR", "AK", "UT", >> > "IA", >> > > "MT", >> > > "HI", "NE", "CT", "WV", "WY", "SD", "VT", "ND", "ME", >> > "RI", >> > > "NH", >> > > "DE", "PR", "GU", "VI", "MP", "AS" >> > > ), count = c( >> > > 36511L, 27513L, >> > > 25861L, 21099L, 19415L, 17012L, 15860L, 14362L, >> > 13923L, 13753L, >> > > 11671L, 10540L, 9777L, 8923L, 8355L, 8219L, 8142L, >> > 8076L, 7985L, >> > > 7770L, 7662L, 7531L, 7273L, 7212L, 7042L, 6708L, >> > 6674L, 6429L, >> > > 6239L, 5580L, 5395L, 5172L, 5013L, 4933L, 4911L, >> > 4797L, 4694L, >> > > 4458L, 3873L, 3757L, 3608L, 3111L, 2604L, 2217L, >> > 2156L, 2143L, >> > > 2030L, 1544L, 1417L, 1168L, 772L, 531L, 148L, 63L, 7L, >> 2L >> > > ) >> > > ), .Names = c("STUSPS", >> > > "count"), class = c("tbl_df", "tbl", >> > "data.frame"), >> > > row.names = c(NA,-56L) >> > > ) >> > > >> > > >> > > x = c("leaflet", "rgdal", "maptools", "mapproj", "rgeos", >> "dplyr") >> > > lapply(x, library, character.only = TRUE) >> > > # From >> > https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html >> > > states <- readOGR(dsn = "./cb_2014_us_state_5m.shp", >> > > layer = "cb_2014_us_state_5m", verbose = >> FALSE) >> > > # Make a copy of the SPDF attribute table, and then work >> > normally, as >> > > with any data.frame/data.table object >> > > states.df <- states at data >> > > # Create an explicit attribute to keep polygons IDs (useful to >> > > "re-attach" the table to the polygons later) >> > > states.df <- states.df %>% mutate(rn=row.names(states)) >> > > >> > > # join them >> > > states.df <- full_join(x = states.df, y = counts, by="STUSPS") >> %>% >> > > filter(!(STUSPS%in%c("PR", "na", "MH", "FM", "PW"))) %>% >> > na.omit() %>% >> > > mutate(popup=paste0('',NAME,'','
', >> > > 'count: ', >> > > prettyNum(count,big.mark=",",scientific=FALSE))) >> > >> > at this stage, you have: >> > >> > > dim(states at data) >> > [1] 56 9 >> > > dim(states.df) >> > [1] 55 12 >> > >> > > >> > > # Re-attach the attribute table to the SPDF >> > > states at data <- states.df >> > >> > now, you created an invalid object: >> > > length(geometry(states)) >> > [1] 56 >> > > dim(states at data) >> > [1] 55 12 >> > >> > this confirms once more what has been said on this list so often, >> that >> > instead of using constructor functions such as >> > SpatialPolygonsDataFrame(), assigning slots directly is dangerous and >> > better left to those who know what they do (and check sanity): >> > >> > > states <- SpatialPolygonsDataFrame(geometry(states), states.df) >> > Error in SpatialPolygonsDataFrame(geometry(states), states.df) : >> > Object length mismatch: >> > geometry(states) has 56 Polygons objects, but states.df has 55 >> rows >> > >> > >> > > # Make sure polygons IDs and data.frame row.names match >> > > states <- spChFIDs(states, states$rn) >> > > >> > > # Create map as usual... >> > > >> > > The error I get is: >> > > >> > > Error in spChFIDs(SP, x) : lengths differ >> > > >> > > >> > > Thanks for the help! >> > > >> > > >> > > Ignacio >> > > >> > > [[alternative HTML version deleted]] >> > > >> > > _______________________________________________ >> > > R-sig-Geo mailing list >> > > R-sig-Geo at r-project.org >> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > >> > >> > -- >> > Edzer Pebesma >> > Institute for Geoinformatics (ifgi), University of M?nster, >> > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 >> > Journal of Statistical Software: http://www.jstatsoft.org/ >> > Computers & Geosciences: http://elsevier.com/locate/cageo/ >> > Spatial Statistics Society http://www.spatialstatistics.info >> > >> > _______________________________________________ >> > R-sig-Geo mailing list >> > R-sig-Geo at r-project.org >> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > >> >> -- >> Edzer Pebesma >> Institute for Geoinformatics (ifgi), University of M?nster, >> Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 >> Journal of Statistical Software: http://www.jstatsoft.org/ >> Computers & Geosciences: http://elsevier.com/locate/cageo/ >> Spatial Statistics Society http://www.spatialstatistics.info >> >> > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From Roger.Bivand at nhh.no Mon Sep 7 13:03:47 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Mon, 7 Sep 2015 13:03:47 +0200 Subject: [R-sig-Geo] rgdal 1.0-7 Message-ID: A new version of rgdal has been accepted on CRAN. Users of CRAN binary packages for Windows and OSX should not see any changes. Other users of rgdal built against unpatched PROJ 4.9.1 will now see (possibly many): "NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files" messages (also when rgdal is loaded silently by sp). This relates to the release of PROJ 4.9.1 (an external dependency of rgdal), which by mistake missed the proj_def.dat file of defaults, see this thread for a discussion: https://stat.ethz.ch/pipermail/r-sig-geo/2015-May/022849.html The original fix to rgdal turned out (recently) not to be sufficient, so please be aware that the use of +init= and +datum= on affected systems may have erroneously injected the wrong +ellps= value. This release of rgdal addresses these specific problems, but only a fresh release of PROJ will resolve it. Debian users may find it useful that a 4.9.1-3 version of proj-data now has the errant file (on sid): https://packages.debian.org/sid/all/proj-data/filelist (thanks to Sebastiaan Couwenberg reacting very rapidly to my reminder posted yesterday on the proj list). If you update rgdal with an unpatched PROJ, you should see these messages if you do anything with CRS objects. This will go away when a new PROJ release appears, or until you add the missing file: https://github.com/OSGeo/proj.4/blob/master/nad/proj_def.dat to your PROJ_LIB location. Roger -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From zhangjiaqiang at gmail.com Tue Sep 8 09:54:58 2015 From: zhangjiaqiang at gmail.com (Zhang Jiaqiang) Date: Tue, 8 Sep 2015 15:54:58 +0800 Subject: [R-sig-Geo] Fwd: Divide Voronoi cell using azimuth in R In-Reply-To: References: Message-ID: Hello All, Here is my code to generate some sample data for my question. As well as a ggplot picture of voronoi. What I want to do is divide each voronoi cell(the polygon in the center which has closure edge ) into three cells(sectors). ?> head(data) site lng lat sector azimuth kpiA 1 a 103.8504 1.315139 a1 0 10 2 a 103.8504 1.315139 a2 120 20 3 a 103.8504 1.315139 a3 240 30 4 b 103.8481 1.321613 b1 50 40 5 b 103.8481 1.321613 b2 190 50 6 b 103.8481 1.321613 b3 320 60 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Rplot.png Type: image/png Size: 34242 bytes Desc: not available URL: From azm at uow.edu.au Tue Sep 8 15:47:31 2015 From: azm at uow.edu.au (Andrew Zammit Mangion) Date: Tue, 8 Sep 2015 13:47:31 +0000 Subject: [R-sig-Geo] Filtering out measurement error with krigeST Message-ID: <1441720051699.20806@uow.edu.au> I wish to check whether I'm missing something obvious or whether what I need is still not implemented. I like to assume that my observations (Z) are different from my underlying process (Y) and that Z = Y + e. I also want to predict Y and and not Z. I know there is a way to do this with krige(), namely by using a variogram defined with an Err() component instead of a Nug() component. That seems to work fine. For example if I do library(gstat) library(sp) data(meuse) coordinates(meuse) = ~x+y data(meuse.grid) gridded(meuse.grid) = ~x+y m <- vgm(.59, "Sph", 874, .04) x1 <- krige(log(zinc)~1, meuse, meuse.grid, model = m) m <- vgm(.59, "Sph", 874, Err=.04) x2 <- krige(log(zinc)~1, meuse, meuse.grid, model = m) then the predictive variance of x1 and x2 are different as expected. However I don't see where I can define an Err() component when constructing a spatio-temporal variogram with vgmST (the help doesn't seem to indicate that this is possible). If I do specify and "Err" parameter in one or both of the space-time variograms (which is undoubtedly wrong, as this should be a parameter to the vgmST function if anything), no error is thrown, but the prediction variances from krigeST are unchanged, suggesting that predictions are still being carried out on Z and not on Y. Any ideas? Thanks for your help, Andrew -- Andrew Zammit Mangion School of Mathematics and Applied Statistics, University of Wollongong, Australia [[alternative HTML version deleted]] From zhangjiaqiang at gmail.com Wed Sep 9 03:46:28 2015 From: zhangjiaqiang at gmail.com (Zhang Jiaqiang) Date: Wed, 9 Sep 2015 09:46:28 +0800 Subject: [R-sig-Geo] Fwd: Divide Voronoi cell using azimuth in R In-Reply-To: References: Message-ID: Hi All, The previous mail size exceeds the max size of the mailist. So I attached my code here. ######## Here begin the R code ########### set.seed(2014) siteNum <- 24 # site, lng, lat clat <- 1.29212 clng <- 103.83470 siteDF <- data.frame(letters[1:siteNum], clng + runif(siteNum, 0.01, 0.03), clat + runif(siteNum, 0.01, 0.03)) colnames(siteDF) <- c('site', 'lng', 'lat') head(siteDF) # site, sector, azimuth, data sectorDF <- data.frame(site = rep(letters[1:siteNum], each=3)) sectorDF$sector <- paste0(sectorDF$site, rep(1:3, siteNum)) sectorDF$azimuth <- c(0, 120, 240, 50, 190, 320, 30, 150, 270) sectorDF$kpiA <- sapply(1:nrow(sectorDF), function(i) i * 10) head(sectorDF) data <- merge(siteDF, sectorDF) head(data) library(deldir) voronoi <- deldir(siteDF$lng, siteDF$lat) ggplot(data=siteDF, aes(x=lng,y=lat)) + geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2),size = 2,data = voronoi$dirsgs,linetype = 1,color= "#419AB0") + geom_point(fill="#EACA3E",pch=21,size = 4,color="white") + geom_text(aes(label=site),hjust=0, vjust=0) ######## Here end the R code ########### [[alternative HTML version deleted]] From thi_veloso at yahoo.com.br Wed Sep 9 04:50:31 2015 From: thi_veloso at yahoo.com.br (Thiago V. dos Santos) Date: Wed, 9 Sep 2015 02:50:31 +0000 (UTC) Subject: [R-sig-Geo] rgdal 1.0-7 In-Reply-To: References: Message-ID: <1843796715.137415.1441767032002.JavaMail.yahoo@mail.yahoo.com> Hi Roger, Thanks for the updated rgdal and for all the information. After upgrading rgdal earlier today I got the warning message for nearly all raster/sp/rgdal operations in R. On a Mac running Yosemite, this is the path I had to copy the proj_def.dat file to (or where I had to create a new file based on the link you've provided): /opt/local/share/proj/ This path assumes that PROJ was installed from MacPorts on its default directory. Regards, Thiago. On Monday, September 7, 2015 6:07 AM, Roger Bivand wrote: A new version of rgdal has been accepted on CRAN. Users of CRAN binary packages for Windows and OSX should not see any changes. Other users of rgdal built against unpatched PROJ 4.9.1 will now see (possibly many): "NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files" messages (also when rgdal is loaded silently by sp). This relates to the release of PROJ 4.9.1 (an external dependency of rgdal), which by mistake missed the proj_def.dat file of defaults, see this thread for a discussion: https://stat.ethz.ch/pipermail/r-sig-geo/2015-May/022849.html The original fix to rgdal turned out (recently) not to be sufficient, so please be aware that the use of +init= and +datum= on affected systems may have erroneously injected the wrong +ellps= value. This release of rgdal addresses these specific problems, but only a fresh release of PROJ will resolve it. Debian users may find it useful that a 4.9.1-3 version of proj-data now has the errant file (on sid): https://packages.debian.org/sid/all/proj-data/filelist (thanks to Sebastiaan Couwenberg reacting very rapidly to my reminder posted yesterday on the proj list). If you update rgdal with an unpatched PROJ, you should see these messages if you do anything with CRS objects. This will go away when a new PROJ release appears, or until you add the missing file: https://github.com/OSGeo/proj.4/blob/master/nad/proj_def.dat to your PROJ_LIB location. Roger -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo From Roger.Bivand at nhh.no Wed Sep 9 09:02:05 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Wed, 9 Sep 2015 09:02:05 +0200 Subject: [R-sig-Geo] rgdal 1.0-7 In-Reply-To: <1843796715.137415.1441767032002.JavaMail.yahoo@mail.yahoo.com> References: <1843796715.137415.1441767032002.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Wed, 9 Sep 2015, Thiago V. dos Santos wrote: > Hi Roger, > > Thanks for the updated rgdal and for all the information. After > upgrading rgdal earlier today I got the warning message for nearly all > raster/sp/rgdal operations in R. > > On a Mac running Yosemite, this is the path I had to copy the > proj_def.dat file to (or where I had to create a new file based on the > link you've provided): > > /opt/local/share/proj/ > > This path assumes that PROJ was installed from MacPorts on its default > directory. Thanks very much for reporting back, and for indicating a resolution for others in the same situation. I believe that those running the CRAN OSX rgdal binary are protected because it ships with the metadata files. A release candidate for PROJ 4.9.2 was issues yesterday evening, and will provide a solution to the problem, but because other issues also need addressing, it may be a little while before it is out, and propagates to MacPorts, etc. Roger > > Regards, > Thiago. > > > > > > On Monday, September 7, 2015 6:07 AM, Roger Bivand wrote: > A new version of rgdal has been accepted on CRAN. Users of CRAN binary > packages for Windows and OSX should not see any changes. > > Other users of rgdal built against unpatched PROJ 4.9.1 will now see > (possibly many): > > "NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files" > > messages (also when rgdal is loaded silently by sp). This relates to the > release of PROJ 4.9.1 (an external dependency of rgdal), which by mistake > missed the proj_def.dat file of defaults, see this thread for a > discussion: > > https://stat.ethz.ch/pipermail/r-sig-geo/2015-May/022849.html > > The original fix to rgdal turned out (recently) not to be sufficient, so > please be aware that the use of +init= and +datum= on affected systems may > have erroneously injected the wrong +ellps= value. This release of rgdal > addresses these specific problems, but only a fresh release of PROJ will > resolve it. > > Debian users may find it useful that a 4.9.1-3 version of proj-data now > has the errant file (on sid): > > https://packages.debian.org/sid/all/proj-data/filelist > > (thanks to Sebastiaan Couwenberg reacting very rapidly to my reminder > posted yesterday on the proj list). > > If you update rgdal with an unpatched PROJ, you should see these messages > if you do anything with CRS objects. This will go away when a new PROJ > release appears, or until you add the missing file: > > https://github.com/OSGeo/proj.4/blob/master/nad/proj_def.dat > > to your PROJ_LIB location. > > Roger > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From sa12372 at bristol.ac.uk Wed Sep 9 13:09:38 2015 From: sa12372 at bristol.ac.uk (Sherien Al-Azerji) Date: Wed, 9 Sep 2015 12:09:38 +0100 Subject: [R-sig-Geo] fix the value of nugget Message-ID: Dear All, I'm running Universal kriking method and I need to set the value of nugget in the variogram model to zero even after fitting a variogram, I need the fitted variogram to have a zero nugget. How can I do this please. another question please, some times when I run my code I get this error message (LDL factor) what this mean? and how can I solve it. Best Regards Sherien [[alternative HTML version deleted]] From javajimburke at gmail.com Wed Sep 9 17:55:32 2015 From: javajimburke at gmail.com (Jim Burke) Date: Wed, 9 Sep 2015 10:55:32 -0500 Subject: [R-sig-Geo] Plot street "Name" for city streets (lines) in a SpatialLinesDataFrame Message-ID: Given a SpatialLinesDataFrame like below. How might I print the street "Name" adjacent to these many streets in the SpatialLinesDataFrame? Just what in the line class can I attach its "Name" to? I want to add this plot as a layer to my other plots. And I cannot post an code snippet example because I don't get that far here. This is more basic. I want some thoughts on how to plot a tiny street name near each street in the SpatialLinesDataFrame. > str(DC_Roads1_sp) Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots ..@ data :'data.frame': 125059 obs. of 31 variables: .. ..$ DC_ID : num [1:125059] 843772 843773 844139 844140 844141 ... .. ..$ Prefix : chr [1:125059] NA NA NA "N" ... .. ..$ Pretype : chr [1:125059] NA NA "STHY" NA ... .. ..$ Name : chr [1:125059] "Freeport" "Freeport" "183" "Valley View" ... Then the line class looks like below (first two are shown) ..@ lines :List of 125059 .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots .. .. .. ..@ Lines:List of 1 .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 .. .. .. ..@ ID : chr "0" .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots .. .. .. ..@ Lines:List of 1 .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 .. .. .. ..@ ID : chr "1" Any and all advice/suggestions/hints/examples is appreciated. Thanks, Jim Burke [[alternative HTML version deleted]] From Roger.Bivand at nhh.no Wed Sep 9 18:21:41 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Wed, 9 Sep 2015 18:21:41 +0200 Subject: [R-sig-Geo] Plot street "Name" for city streets (lines) in a SpatialLinesDataFrame In-Reply-To: References: Message-ID: On Wed, 9 Sep 2015, Jim Burke wrote: > Given a SpatialLinesDataFrame like below. How might I print the street > "Name" adjacent to these many streets in the SpatialLinesDataFrame? Just > what in the line class can I attach its "Name" to? I want to add this plot > as a layer to my other plots. > Please no HTML mail. It is (much) bulkier, and can contain payloads, so all the R lists strip HTML copies/markup, often leading to garbled content. Please provide a reproducible example, possibly with a small subset of OSM data or similar (by URL). Guessing from the structure below with 125K Lines objects would be hard, start small and scale up from there. Find a representative point, possibly a midpoint, for each "street" - probably Lines object - find its angle, and try to offset and rotate the inserted text. In regular cartography, the placement of labels is generally considered hard. There are functions in the maptools package for label placement for point support to avoid overlapping, but these do not accommodate rotation. Since you didn't say why you need this, it is hard to provide sensible advice. An affiliation would give an indication of the motivation. Roger > And I cannot post an code snippet example because I don't get that far > here. This is more basic. I want some thoughts on how to plot a tiny street > name near each street in the SpatialLinesDataFrame. > >> str(DC_Roads1_sp) > Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots > ..@ data :'data.frame': 125059 obs. of 31 variables: > .. ..$ DC_ID : num [1:125059] 843772 843773 844139 844140 844141 ... > .. ..$ Prefix : chr [1:125059] NA NA NA "N" ... > .. ..$ Pretype : chr [1:125059] NA NA "STHY" NA ... > .. ..$ Name : chr [1:125059] "Freeport" "Freeport" "183" "Valley > View" ... > > Then the line class looks like below (first two are shown) > > ..@ lines :List of 125059 > .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots > .. .. .. ..@ Lines:List of 1 > .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot > .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 > .. .. .. ..@ ID : chr "0" > .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots > .. .. .. ..@ Lines:List of 1 > .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot > .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 > .. .. .. ..@ ID : chr "1" > > > Any and all advice/suggestions/hints/examples is appreciated. > > Thanks, > Jim Burke > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From adeela.uaf at gmail.com Wed Sep 9 19:14:01 2015 From: adeela.uaf at gmail.com (adeela uaf) Date: Wed, 9 Sep 2015 22:14:01 +0500 Subject: [R-sig-Geo] error in indicator variogram Message-ID: Hi memebers, I am trying to do indicator kriging, so, fitting indicator variogram. c1 <- ifelse(mt$Cd15 > 0.34, 1 , 0) q <- gstat(id="c1", formula=c1~1, data=mt) v.fit <- fit.variogram(variogram(q), vgm(psill=0.2,"Wav",nugget=0, range=12)) plot(variogram(q),v.fit) but receiving a vary poor model fit. On any other model and parameter values receiving this error Warning message: In fit.variogram(variogram(q), vgm(psill = 0.2, "Sph", nugget = 0, : Warning: singular model in variogram fit Regards Adeela -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: variogram.pdf Type: application/pdf Size: 2774 bytes Desc: not available URL: From edzer.pebesma at uni-muenster.de Wed Sep 9 21:46:39 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Wed, 9 Sep 2015 21:46:39 +0200 Subject: [R-sig-Geo] fix the value of nugget In-Reply-To: References: Message-ID: <55F08C9F.1020706@uni-muenster.de> On 09/09/2015 01:09 PM, Sherien Al-Azerji wrote: > Dear All, > > I'm running Universal kriking method and I need to set the value of nugget > in the variogram model to zero even after fitting a variogram, I need the > fitted variogram to have a zero nugget. How can I do this please. Showing what you've tried would help. Assuming you use package gstat, you can pass a variogram model without nugget (e.g. vgm(1, "Exp", 300) ) to fit.variogram, and no (=zero) nugget will be fitted. > > another question please, some times when I run my code I get this error > message (LDL factor) what this mean? and how can I solve it. It means the covariance matrix is (too close to) singular; this happens if you have (nearly) duplicate observations, or a variogram model that gives rise to (nearly) perfectly correlated observations, such as the Gaussian model. > > Best Regards > Sherien > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info From edzer.pebesma at uni-muenster.de Wed Sep 9 21:53:47 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Wed, 9 Sep 2015 21:53:47 +0200 Subject: [R-sig-Geo] Filtering out measurement error with krigeST In-Reply-To: <1441720051699.20806@uow.edu.au> References: <1441720051699.20806@uow.edu.au> Message-ID: <55F08E4B.9030905@uni-muenster.de> On 09/08/2015 03:47 PM, Andrew Zammit Mangion wrote: > I wish to check whether I'm missing something obvious or whether what I need is still not implemented. I like to assume that my observations (Z) are different from my underlying process (Y) and that Z = Y + e. I also want to predict Y and and not Z. > > > I know there is a way to do this with krige(), namely by using a variogram defined with an Err() component instead of a Nug() component. That seems to work fine. For example if I do > > > library(gstat) > library(sp) > data(meuse) > coordinates(meuse) = ~x+y > data(meuse.grid) > gridded(meuse.grid) = ~x+y > m <- vgm(.59, "Sph", 874, .04) > x1 <- krige(log(zinc)~1, meuse, meuse.grid, model = m) > m <- vgm(.59, "Sph", 874, Err=.04) > x2 <- krige(log(zinc)~1, meuse, meuse.grid, model = m) > > then the predictive variance of x1 and x2 are different as expected. However I don't see where I can define an Err() component when constructing a spatio-temporal variogram with vgmST (the help doesn't seem to indicate that this is possible). If I do specify and "Err" parameter in one or both of the space-time variograms (which is undoubtedly wrong, as this should be a parameter to the vgmST function if anything), no error is thrown, but the prediction variances from krigeST are unchanged, suggesting that predictions are still being carried out on Z and not on Y. Any ideas? > It is indeed not possible with krigeST, and I will also not implement it. The difficulty of doing so, and the need to maintain messy code resulting from it is not worth it -- it is pretty trivial to get the result you want by doing the following: 1. Use a model with a nugget effect, equal to (or larger than) the error component, 2. for cases where the prediction error is zero (prediction location coincides with observation location) shift the prediction location with a very small amount such that they no longer coincide, prior to kriging, 3. after kriging, subtract the error component from the prediction variance. > Thanks for your help, > Andrew > > > -- > Andrew Zammit Mangion > School of Mathematics and Applied Statistics, > University of Wollongong, Australia > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info From azm at uow.edu.au Thu Sep 10 06:08:14 2015 From: azm at uow.edu.au (Andrew Zammit Mangion) Date: Thu, 10 Sep 2015 04:08:14 +0000 Subject: [R-sig-Geo] Filtering out measurement error with krigeST Message-ID: <1441858094606.63911@uow.edu.au> Thank you Edzer, yes that will work. ? Andrew -- Andrew Zammit Mangion School of Mathematics and Applied Statistics, University of Wollongong, Australia [[alternative HTML version deleted]] From Roger.Bivand at nhh.no Thu Sep 10 13:08:24 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Thu, 10 Sep 2015 13:08:24 +0200 Subject: [R-sig-Geo] Plot street "Name" for city streets (lines) in a SpatialLinesDataFrame In-Reply-To: References: Message-ID: On Wed, 9 Sep 2015, Roger Bivand wrote: > On Wed, 9 Sep 2015, Jim Burke wrote: > >> Given a SpatialLinesDataFrame like below. How might I print the street >> "Name" adjacent to these many streets in the SpatialLinesDataFrame? Just >> what in the line class can I attach its "Name" to? I want to add this plot >> as a layer to my other plots. >> > > Please no HTML mail. It is (much) bulkier, and can contain payloads, so all > the R lists strip HTML copies/markup, often leading to garbled content. > > Please provide a reproducible example, possibly with a small subset of OSM > data or similar (by URL). Guessing from the structure below with 125K Lines > objects would be hard, start small and scale up from there. Find a > representative point, possibly a midpoint, for each "street" - probably Lines > object - find its angle, and try to offset and rotate the inserted text. > > In regular cartography, the placement of labels is generally considered hard. > There are functions in the maptools package for label placement for point > support to avoid overlapping, but these do not accommodate rotation. There is a good deal of code in src/library/graphics/src/plot3d.c, used in plotting labels when drawing contour plots. That code is embedded in finding the contour locations, rather than being a general solution. It may, though, give some helpful ideas. Roger > > Since you didn't say why you need this, it is hard to provide sensible > advice. An affiliation would give an indication of the motivation. > > Roger > >> And I cannot post an code snippet example because I don't get that far >> here. This is more basic. I want some thoughts on how to plot a tiny street >> name near each street in the SpatialLinesDataFrame. >> >>> str(DC_Roads1_sp) >> Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots >> ..@ data :'data.frame': 125059 obs. of 31 variables: >> .. ..$ DC_ID : num [1:125059] 843772 843773 844139 844140 844141 ... >> .. ..$ Prefix : chr [1:125059] NA NA NA "N" ... >> .. ..$ Pretype : chr [1:125059] NA NA "STHY" NA ... >> .. ..$ Name : chr [1:125059] "Freeport" "Freeport" "183" "Valley >> View" ... >> >> Then the line class looks like below (first two are shown) >> >> ..@ lines :List of 125059 >> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots >> .. .. .. ..@ Lines:List of 1 >> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot >> .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 >> .. .. .. ..@ ID : chr "0" >> .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots >> .. .. .. ..@ Lines:List of 1 >> .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot >> .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9 >> .. .. .. ..@ ID : chr "1" >> >> >> Any and all advice/suggestions/hints/examples is appreciated. >> >> Thanks, >> Jim Burke >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From edzer.pebesma at uni-muenster.de Thu Sep 10 16:38:28 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Thu, 10 Sep 2015 16:38:28 +0200 Subject: [R-sig-Geo] sp 1.2-0 Message-ID: <55F195E4.3020509@uni-muenster.de> I released sp 1.2-0 to CRAN. Changes are: - there is now support for SpatialMultiPoints and SpatialMultiPointsDataFrame objects. If you never heard of multipoints, you might not need them. - control of "over" methods handled by rgeos is now finer grained, e.g. allowing to exclude intersecting polygons that only touch in a point, or line. - plot and spplot methods now accept OpenStreetMaps or Google map background maps obtained by RgoogleMaps or ggmap. https://cran.uni-muenster.de/web/packages/sp/news.html contains a news file with more detail. If you use package raster, make sure that you run update.packages(), or else make sure you update/reinstall raster AFTER you update sp. -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From uzzal at gist.ac.kr Fri Sep 11 14:15:15 2015 From: uzzal at gist.ac.kr (Uzzal) Date: Fri, 11 Sep 2015 21:15:15 +0900 (KST) Subject: [R-sig-Geo] Small problem in extraction of a table of range, sill and nugget in loop Message-ID: <1975097684.1441973715086.JavaMail.root@eunhasu> Hello, I have a csv file named "seoul1to7" contains hourly pm10 concentration for around 105 sites collected for 7 days. Please download from here By using this dataset, I have plotted variogram for every hour of 7 days (total 161 variogram) using automap package in R. From every variogram, I can see that the range, sill and nugget value is written on the variogram plot. But I want to extract all the psill,range and nugget value in a table for every individual variogram (hour). Is it possible in R? [Actually, in future I want to make some graph using those range, sill and nugget to compare the changes]. I wrote the following code to plot 161 variogram : library(sp) library(gstat) library(rgdal) library(automap) library(latticeExtra) library(ggplot2)seoul1to7hoursvars.. vars[[161]] my problem starts from here: Now I want to extract the table of sill, range and Nugget.So I wrote this code table But as output here I got this type of table below sill range nugget Sill.1 Range.1 Nugget.1 Sill.2 Range.2 Nugget.2 ??? But I want this type of table below. hours Psill Range Nugget 2012030101 2012030102 . . . 2012030731 What correction I should do in my loop? If you have any further query please let me know. Thanks in advance. Orpheus -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.appelhans at gmail.com Fri Sep 11 14:31:13 2015 From: tim.appelhans at gmail.com (Tim Appelhans) Date: Fri, 11 Sep 2015 14:31:13 +0200 Subject: [R-sig-Geo] Small problem in extraction of a table of range, sill and nugget in loop In-Reply-To: <1975097684.1441973715086.JavaMail.root@eunhasu> References: <1975097684.1441973715086.JavaMail.root@eunhasu> Message-ID: <55F2C991.2010002@gmail.com> Uzzal, if you wrap a do.call("rbind", ... around you lapply statement, I think you get what you want: table<-do.call("rbind", lapply(seq(seoul1to7_splt), function(i) { dat<-seoul1to7_splt[[i]] coordinates(dat)<-~LON+LAT proj4string(dat) <- "+proj=longlat +datum=WGS84" dat <- spTransform(dat, CRS("+proj=utm +north +zone=52 +datum=WGS84")) variogram<-autofitVariogram(log(PM10)~1,dat) nug=variogram$var_model$psill[1] sill = variogram$var_model$psill[2] + nug range = variogram$var_model$range[2] table<-data.frame(sill=sill,range=range,nugget=nug) return(table) })) after this, you can simply add your datetimes in a further column and rearrange the columns as you wish HTH Tim On 11.09.2015 14:15, Uzzal wrote: > > Hello, I have a csv file named "seoul1to7" contains hourly pm10 > concentration for around 105 sites collected for 7 days. Please > download from here > > > By using this dataset, I have plotted variogram for every hour of 7 > days (total 161 variogram) using automap package in R. From every > variogram, I can see that the range, sill and nugget value is written > on the variogram plot. But I want to extract all the psill,range and > nugget value in a table for every individual variogram (hour). Is it > possible in R? > > [Actually, in future I want to make some graph using those range, > sill and nugget to compare the changes]. I wrote the following code to > plot 161 variogram : > > library(sp) > library(gstat) > library(rgdal) > library(automap) > library(latticeExtra) > library(ggplot2) > > seoul1to7<-read.csv("seoul1to7.csv") > seoul1to7[seoul1to7==0] <-NA > seoul1to7 <- na.omit(seoul1to7) > seoul1to7_splt<-split(seoul1to7,seoul1to7$time) #a list contain 161 > dataframe > seq(seoul1to7_splt) > names(seoul1to7_splt) > > hours<-as.POSIXct(names(seoul1to7_splt), format="%Y%m%d%H") > hours > > vars<-lapply(seq(seoul1to7_splt), function(i) > { > dat<-seoul1to7_splt[[i]] > coordinates(dat)<-~LON+LAT > proj4string(dat) <- "+proj=longlat +datum=WGS84" > dat <- spTransform(dat, CRS("+proj=utm +north +zone=52 +datum=WGS84")) > variogram<-autofitVariogram(log(PM10)~1,dat, model="Sph") > plt<- plot(variogram,plotit=F,asp=1) > plt<- update(plt, main=paste("Variogram for", as.character(hours)[i])) > > return(plt) > }) > vars[[1]] > > . > > . > > > vars[[161]] > > *my problem starts from here: *Now I want to extract the table of > sill, range and Nugget.So I wrote this code > > table<-lapply(seq(seoul1to7_splt), function(i) > { > dat<-seoul1to7_splt[[i]] > coordinates(dat)<-~LON+LAT > proj4string(dat) <- "+proj=longlat +datum=WGS84" > dat <- spTransform(dat, CRS("+proj=utm +north +zone=52 +datum=WGS84")) > variogram<-autofitVariogram(log(PM10)~1,dat) > > nug=variogram$var_model$psill[1] > sill = variogram$var_model$psill[2] + nug > range = variogram$var_model$range[2] > table<-data.frame(sill=sill,range=range,nugget=nug) > > return(table) > }) > table<-as.data.frame (table)) > > But as output here I got this type of table below > > sill > > > > range > > > > nugget > > > > Sill.1 > > > > Range.1 > > > > Nugget.1 > > > > Sill.2 > > > > Range.2 > > > > Nugget.2 > > > > ??? > > > > > > > > > > > > > > > > > > > > But I want this type of table below. > > hours > > > > Psill > > > > Range > > > > Nugget > > 2012030101 > > > > > > > > 2012030102 > > > > > > > > . > > > > > > > > . > > > > > > > > . > > > > > > > > 2012030731 > > > > > > > > What correction I should do in my loop? > > If you have any further query please let me know. Thanks in advance. > > Orpheus > > > > > > -- ##################################### Tim Appelhans Department of Geography Environmental Informatics Philipps Universit?t Marburg Deutschhausstra?e 12 35032 Marburg (Paketpost: 35037 Marburg) Germany Tel +49 (0) 6421 28-25957 http://environmentalinformatics-marburg.de/ [[alternative HTML version deleted]] From sh_didar62 at yahoo.com Sun Sep 13 11:26:02 2015 From: sh_didar62 at yahoo.com (shohre didari) Date: Sun, 13 Sep 2015 09:26:02 +0000 (UTC) Subject: [R-sig-Geo] problem with krigeST Message-ID: <1762377215.1832954.1442136362540.JavaMail.yahoo@mail.yahoo.com> Dear all,I'm new in R and Spatiotemporalkriging. I am trying to estimate my data with krigeST. I fit sum metricvariogram model. Then I used fitted STvariogram for a new dataset in order topredict them with krigeST. But the prediction result is strange. After date 8the prediction is the same for each station through the rest of dates. I?attach a reproducibleexample.??predicted.Residual <-krigeST(ResidualData~1, data, newdata, modelList= sum.metric, nmax = 5 ,computeVar = TRUE)?I try to rescale the time tosecond as:vgmf.sum.metric$time$range <-vgmf.sum.metric$time$range*24*3600vgmf.sum.metric$stAni <-vgmf.sum.metric$stAni/(24*3600)and then use it as model list inkrigeST but the result did not change. I don?t know which part is wrong andwhat should I do to correct it. I get stuck in this part and could not solveit. I really need help and would appreciate for any help or suggestion.?Thank? you in advance RegardsShohreh -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: data.RData Type: application/octet-stream Size: 3229 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: newdata.RData Type: application/octet-stream Size: 2104 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: sum.metric.RData Type: application/octet-stream Size: 793 bytes Desc: not available URL: From tim.appelhans at gmail.com Sun Sep 13 12:42:02 2015 From: tim.appelhans at gmail.com (Tim Appelhans) Date: Sun, 13 Sep 2015 12:42:02 +0200 Subject: [R-sig-Geo] mapview 0.5.0 Message-ID: <55F552FA.7060404@gmail.com> Dear all, I have put some more effort into mapview. The current version 0.5.0 has some new features which make the whole experience much more user-friendly. In a nutshell, changes/additions are as follows: - mapView() is now also defined for SpatialPixelsDataFrame - all Spatial * DataFrame methods have gained argument 'zcol' to select specific columns from the attribute table - SpatialPointsDataFrame method has gained argument 'radius' to scale the circles according to another variable - added viewRGB() to render true-/false-color images of RatserStacks/Bricks (like raster::plotRGB) - added viewExtent() to view the extent/bbox of Raster*/Spatial* objects. This is useful for large objects as only the four corners of the extent need to be reprojected (using raster::projectExtent) - defined '+'-method to easily add layers to a leaflet/mapview map or combine existing maps - defined class 'mapview' which has two slots - @object - a list with all objects that are shown on the map - @map - the map - Raster* methods have gained argument 'maxpixels' to avoid long rendering times (by default set to 500000 pixels which produces acceptable times on my machine) - enhanced leaflet integration so that you can use leaflet maps and add features using mapview (e.g. '+') or use mapview to create maps and add functionality provided by leaflet (using e.g. %>%) As an example, this means that you can now do things like mapView(meuse.grid, zcol = "soil") + viewExtent(meuse) + meuse to view all points of meuse plus their extent on top of a raster layer of meuse.grid$soil All new functionality is highlighted in detail in the demo at http://environmentalinformatics-marburg.github.io/web-presentations/20150723_mapView.html (the .Rmd source of which is now also included as a vignette in the package) The package repository can be found at https://github.com/environmentalinformatics-marburg/mapview To install the package use library(devtools) install_github("environmentalinformatics-marburg/mapview") I hope this update will prove useful for some of you. Don't hesitate to send me feedback and/or suggestions. Formal bug reports and feature requests should be filed at https://github.com/environmentalinformatics-marburg/mapview/issues Best Tim -- ##################################### Tim Appelhans Department of Geography Environmental Informatics Philipps Universit?t Marburg Deutschhausstra?e 12 35032 Marburg (Paketpost: 35037 Marburg) Germany Tel +49 (0) 6421 28-25957 http://environmentalinformatics-marburg.de/ From bernd.vogelgesang at gmx.de Sun Sep 13 15:04:18 2015 From: bernd.vogelgesang at gmx.de (Bernd Vogelgesang) Date: Sun, 13 Sep 2015 15:04:18 +0200 Subject: [R-sig-Geo] mapview 0.5.0 In-Reply-To: <55F552FA.7060404@gmail.com> References: <55F552FA.7060404@gmail.com> Message-ID: Many thanks for your work and special thanks for mentioning franconian breweries in your documentation ;) Bernd Am 13.09.2015, 12:42 Uhr, schrieb Tim Appelhans : > Dear all, > > I have put some more effort into mapview. > The current version 0.5.0 has some new features which make the whole > experience much more user-friendly. > > In a nutshell, changes/additions are as follows: > > - mapView() is now also defined for SpatialPixelsDataFrame > - all Spatial * DataFrame methods have gained argument 'zcol' to select > specific columns from the attribute table > - SpatialPointsDataFrame method has gained argument 'radius' to scale > the circles according to another variable > - added viewRGB() to render true-/false-color images of > RatserStacks/Bricks (like raster::plotRGB) > - added viewExtent() to view the extent/bbox of Raster*/Spatial* > objects. This is useful for large objects as only the four corners of > the extent need to be reprojected (using raster::projectExtent) > - defined '+'-method to easily add layers to a leaflet/mapview map or > combine existing maps > - defined class 'mapview' which has two slots > - @object - a list with all objects that are shown on the map > - @map - the map > - Raster* methods have gained argument 'maxpixels' to avoid long > rendering times (by default set to 500000 pixels which produces > acceptable times on my machine) > - enhanced leaflet integration so that you can use leaflet maps and add > features using mapview (e.g. '+') or use mapview to create maps and add > functionality provided by leaflet (using e.g. %>%) > > As an example, this means that you can now do things like > > mapView(meuse.grid, zcol = "soil") + viewExtent(meuse) + meuse > > to view all points of meuse plus their extent on top of a raster layer > of meuse.grid$soil > > All new functionality is highlighted in detail in the demo at > > http://environmentalinformatics-marburg.github.io/web-presentations/20150723_mapView.html > (the .Rmd source of which is now also included as a vignette in the > package) > > The package repository can be found at > https://github.com/environmentalinformatics-marburg/mapview > > To install the package use > > library(devtools) > install_github("environmentalinformatics-marburg/mapview") > > I hope this update will prove useful for some of you. > Don't hesitate to send me feedback and/or suggestions. > > Formal bug reports and feature requests should be filed at > https://github.com/environmentalinformatics-marburg/mapview/issues > > Best > Tim > -- Bernd Vogelgesang Siedlerstra?e 2 91083 Baiersdorf/Igelsdorf Tel: 09133-825374 From matzke at nimbios.org Mon Sep 14 06:51:25 2015 From: matzke at nimbios.org (Nick Matzke) Date: Mon, 14 Sep 2015 14:51:25 +1000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Message-ID: Hi all, I would like to plot wrld_simpl, but have the left and right edges of the map be at something like 100 degrees longitude, rather than (-180, 180). I tried messing with the bounding box with no luck. I can imagine something like burrowing into the object and subtracting 80 degrees from all the longitudes, but I suspect there must be a better way? Any help appreciated! Nick [[alternative HTML version deleted]] From frtog at vestas.com Mon Sep 14 07:38:22 2015 From: frtog at vestas.com (=?iso-8859-1?Q?Frede_Aakmann_T=F8gersen?=) Date: Mon, 14 Sep 2015 05:38:22 +0000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: Hi Nick To be honest I do not understand your question so I am guessing that you probably only need to set the xlim to c(-100, 100). Here is an example: > data(wrld_simpl) > plot(wrld_simpl) > plot(wrld_simpl, xlim = c(-100, 100)) Why would one wants to redefine the longitudes from the interval (-180, 180) to (-100, 100)? Yours sincerely / Med venlig hilsen Frede Aakmann T?gersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547 6050 frtog at vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Nick Matzke Sent: 14. september 2015 06:51 To: r-sig-geo at stat.math.ethz.ch Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Hi all, I would like to plot wrld_simpl, but have the left and right edges of the map be at something like 100 degrees longitude, rather than (-180, 180). I tried messing with the bounding box with no luck. I can imagine something like burrowing into the object and subtracting 80 degrees from all the longitudes, but I suspect there must be a better way? Any help appreciated! Nick [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo From englishchristophera at gmail.com Mon Sep 14 07:46:19 2015 From: englishchristophera at gmail.com (englishchristophera at gmail.com) Date: Mon, 14 Sep 2015 07:46:19 +0200 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Message-ID: <91lrsrfi7lp9e6klk6lrmmte.1442209579029@email.lge.com> Nick:Have a look at stackoverflow.com/questions/13982773/crop-for-spatialpolygonsdataframe as it might address your case.HTHchris------ Original message------From: Nick MatzkeDate: Mon, Sep 14, 2015 6:52 AMTo: r-sig-geo at stat.math.ethz.ch;Cc: Subject:[R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Hi all,I would like to plot wrld_simpl, but have the left and right edges of themap be at something like 100 degrees longitude, rather than (-180, 180).I tried messing with the bounding box with no luck.I can imagine something like burrowing into the object and subtracting 80degrees from all the longitudes, but I suspect there must be a better way?Any help appreciated!Nick [[alternative HTML version deleted]]_______________________________________________R-sig-Geo mailing listR-sig-Geo at r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From matzke at nimbios.org Mon Sep 14 07:46:46 2015 From: matzke at nimbios.org (Nick Matzke) Date: Mon, 14 Sep 2015 15:46:46 +1000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: Apologies, I got my wires crossed. What I meant was, how would I make a map where the left edge was at longitude 100 (e.g. Thailand), and the right edge is at, say 99 (again Thailand). The Pacific Ocean, and the International Dateline, would be in the middle of this map. I tried the obvious thing: plot(wrld_simpl, xlim = c(100, 99)) ...but that produces a flipped map... Cheers! Nick On Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen wrote: > Hi Nick > > To be honest I do not understand your question so I am guessing that you > probably only need to set the xlim to c(-100, 100). Here is an example: > > > data(wrld_simpl) > > plot(wrld_simpl) > > plot(wrld_simpl, xlim = c(-100, 100)) > > Why would one wants to redefine the longitudes from the interval (-180, > 180) to (-100, 100)? > > > Yours sincerely / Med venlig hilsen > > Frede Aakmann T?gersen > Specialist, M.Sc., Ph.D. > Plant Performance & Modeling > > Technology & Service Solutions > T +45 9730 5135 > M +45 2547 6050 > frtog at vestas.com > http://www.vestas.com > > Company reg. name: Vestas Wind Systems A/S > This e-mail is subject to our e-mail disclaimer statement. > Please refer to www.vestas.com/legal/notice > If you have received this e-mail in error please contact the sender. > > > -----Original Message----- > From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of > Nick Matzke > Sent: 14. september 2015 06:51 > To: r-sig-geo at stat.math.ethz.ch > Subject: [R-sig-Geo] making wrld_simpl longitude borders something other > than (-180, 180) > > Hi all, > > I would like to plot wrld_simpl, but have the left and right edges of the > map be at something like 100 degrees longitude, rather than (-180, 180). > > I tried messing with the bounding box with no luck. > > I can imagine something like burrowing into the object and subtracting 80 > degrees from all the longitudes, but I suspect there must be a better way? > > Any help appreciated! > Nick > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] From matzke at nimbios.org Mon Sep 14 08:04:32 2015 From: matzke at nimbios.org (Nick Matzke) Date: Mon, 14 Sep 2015 16:04:32 +1000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: Ah, this did it: http://stackoverflow.com/questions/17718928/how-to-switch-to-a-map-that-is-centered-on-the-china-instead-of-the-default-set (plotting to PDF helps speed it up) library(geosphere) library(gdata) # for read.xls library(maptools) # for e.g. wrld_simpl library(rgdal) library(gpclib) # for polygon clipping pdffn = "wrld_simpl.pdf" pdf(file=pdffn, width=12, height=6) data(wrld_simpl) #The world as a SpatialPolygonsDataFrame #To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break: w <- nowrapRecenter(wrld_simpl, offset = 180-100, avoidGEOS=TRUE) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) wrld_reCentered <- spTransform(w, CRS("+proj=moll +lon_0=-100")) plot(wrld_reCentered, border="grey", lwd=0.5) dev.off() cmdstr = paste0("open ", pdffn) system(cmdstr) On Mon, Sep 14, 2015 at 3:46 PM, Nick Matzke wrote: > Apologies, I got my wires crossed. > > What I meant was, how would I make a map where the left edge was at > longitude 100 (e.g. Thailand), and the right edge is at, say 99 > (again Thailand). The Pacific Ocean, and the International Dateline, would > be in the middle of this map. > > I tried the obvious thing: > plot(wrld_simpl, xlim = c(100, 99)) > > ...but that produces a flipped map... > > Cheers! > Nick > > > On Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen > wrote: > >> Hi Nick >> >> To be honest I do not understand your question so I am guessing that you >> probably only need to set the xlim to c(-100, 100). Here is an example: >> >> > data(wrld_simpl) >> > plot(wrld_simpl) >> > plot(wrld_simpl, xlim = c(-100, 100)) >> >> Why would one wants to redefine the longitudes from the interval (-180, >> 180) to (-100, 100)? >> >> >> Yours sincerely / Med venlig hilsen >> >> Frede Aakmann T?gersen >> Specialist, M.Sc., Ph.D. >> Plant Performance & Modeling >> >> Technology & Service Solutions >> T +45 9730 5135 >> M +45 2547 6050 >> frtog at vestas.com >> http://www.vestas.com >> >> Company reg. name: Vestas Wind Systems A/S >> This e-mail is subject to our e-mail disclaimer statement. >> Please refer to www.vestas.com/legal/notice >> If you have received this e-mail in error please contact the sender. >> >> >> -----Original Message----- >> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of >> Nick Matzke >> Sent: 14. september 2015 06:51 >> To: r-sig-geo at stat.math.ethz.ch >> Subject: [R-sig-Geo] making wrld_simpl longitude borders something other >> than (-180, 180) >> >> Hi all, >> >> I would like to plot wrld_simpl, but have the left and right edges of the >> map be at something like 100 degrees longitude, rather than (-180, 180). >> >> I tried messing with the bounding box with no luck. >> >> I can imagine something like burrowing into the object and subtracting 80 >> degrees from all the longitudes, but I suspect there must be a better way? >> >> Any help appreciated! >> Nick >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > [[alternative HTML version deleted]] From sanctavega at gmail.com Mon Sep 14 08:23:07 2015 From: sanctavega at gmail.com (Sancta Vega) Date: Mon, 14 Sep 2015 06:23:07 +0000 Subject: [R-sig-Geo] Using R to plot a map and Times Series using Netcdf4 data Message-ID: Hi, I'm new in R, I would like to plot a map of my netcdf4 hourly temperatures data (about 5 dimensions,) and after plot a times series of only 2 months of a specific year of my data. I really need help and would appreciate any help or suggestion. Thank you in advance. [[alternative HTML version deleted]] From matzke at nimbios.org Mon Sep 14 08:24:03 2015 From: matzke at nimbios.org (Nick Matzke) Date: Mon, 14 Sep 2015 16:24:03 +1000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: Although, unfortunately, the exact code, but switching "moll" to "latlong", produces screwups (horizontal lines throughout the plot). Any advice? Works: ==================== pdffn = "wrld_simpl_moll.pdf" pdf(file=pdffn, width=12, height=6) data(wrld_simpl) #The world as a SpatialPolygonsDataFrame #To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break: w <- nowrapRecenter(wrld_simpl, offset = 180-90, avoidGEOS=TRUE) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) wrld_reCentered <- spTransform(w, CRS("+proj=moll +lon_0=-90")) plot(wrld_reCentered, border="grey", lwd=0.5) dev.off() cmdstr = paste0("open ", pdffn) system(cmdstr) ==================== Produces screwups: ==================== pdffn = "wrld_simpl_latlong.pdf" pdf(file=pdffn, width=12, height=6) data(wrld_simpl) #The world as a SpatialPolygonsDataFrame #To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break: w <- nowrapRecenter(wrld_simpl, offset = 180-90, avoidGEOS=TRUE) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) wrld_reCentered <- spTransform(w, CRS("+proj=longlat +lon_0=-90")) plot(wrld_reCentered, border="grey", lwd=0.5) dev.off() cmdstr = paste0("open ", pdffn) system(cmdstr) ==================== On Mon, Sep 14, 2015 at 4:04 PM, Nick Matzke wrote: > Ah, this did it: > http://stackoverflow.com/questions/17718928/how-to-switch-to-a-map-that-is-centered-on-the-china-instead-of-the-default-set > > (plotting to PDF helps speed it up) > > library(geosphere) > library(gdata) # for read.xls > library(maptools) # for e.g. wrld_simpl > library(rgdal) > library(gpclib) # for polygon clipping > > pdffn = "wrld_simpl.pdf" > pdf(file=pdffn, width=12, height=6) > > data(wrld_simpl) #The world as a SpatialPolygonsDataFrame > #To avoid the lines crossing the map after reprojection we need to cut the > polygons at the new break: > w <- nowrapRecenter(wrld_simpl, offset = 180-100, avoidGEOS=TRUE) > #Then proceed with the reprojection (note the proj4 string for a mollweide > projection with 150?E as the new center) > wrld_reCentered <- spTransform(w, CRS("+proj=moll +lon_0=-100")) > plot(wrld_reCentered, border="grey", lwd=0.5) > > > dev.off() > cmdstr = paste0("open ", pdffn) > system(cmdstr) > > > > > On Mon, Sep 14, 2015 at 3:46 PM, Nick Matzke wrote: > >> Apologies, I got my wires crossed. >> >> What I meant was, how would I make a map where the left edge was at >> longitude 100 (e.g. Thailand), and the right edge is at, say 99 >> (again Thailand). The Pacific Ocean, and the International Dateline, would >> be in the middle of this map. >> >> I tried the obvious thing: >> plot(wrld_simpl, xlim = c(100, 99)) >> >> ...but that produces a flipped map... >> >> Cheers! >> Nick >> >> >> On Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen > > wrote: >> >>> Hi Nick >>> >>> To be honest I do not understand your question so I am guessing that you >>> probably only need to set the xlim to c(-100, 100). Here is an example: >>> >>> > data(wrld_simpl) >>> > plot(wrld_simpl) >>> > plot(wrld_simpl, xlim = c(-100, 100)) >>> >>> Why would one wants to redefine the longitudes from the interval (-180, >>> 180) to (-100, 100)? >>> >>> >>> Yours sincerely / Med venlig hilsen >>> >>> Frede Aakmann T?gersen >>> Specialist, M.Sc., Ph.D. >>> Plant Performance & Modeling >>> >>> Technology & Service Solutions >>> T +45 9730 5135 >>> M +45 2547 6050 >>> frtog at vestas.com >>> http://www.vestas.com >>> >>> Company reg. name: Vestas Wind Systems A/S >>> This e-mail is subject to our e-mail disclaimer statement. >>> Please refer to www.vestas.com/legal/notice >>> If you have received this e-mail in error please contact the sender. >>> >>> >>> -----Original Message----- >>> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of >>> Nick Matzke >>> Sent: 14. september 2015 06:51 >>> To: r-sig-geo at stat.math.ethz.ch >>> Subject: [R-sig-Geo] making wrld_simpl longitude borders something other >>> than (-180, 180) >>> >>> Hi all, >>> >>> I would like to plot wrld_simpl, but have the left and right edges of the >>> map be at something like 100 degrees longitude, rather than (-180, 180). >>> >>> I tried messing with the bounding box with no luck. >>> >>> I can imagine something like burrowing into the object and subtracting 80 >>> degrees from all the longitudes, but I suspect there must be a better >>> way? >>> >>> Any help appreciated! >>> Nick >>> >>> [[alternative HTML version deleted]] >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> R-sig-Geo at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>> >> >> > [[alternative HTML version deleted]] From benjamin.leutner at uni-wuerzburg.de Mon Sep 14 08:36:04 2015 From: benjamin.leutner at uni-wuerzburg.de (Benjamin Leutner) Date: Mon, 14 Sep 2015 08:36:04 +0200 Subject: [R-sig-Geo] New package > RStoolbox: Remote Sensing Data Analysis in R Message-ID: <55F66AD4.1070001@uni-wuerzburg.de> Dear list members, We are happy to announce the initial release of our *RStoolbox* package. RStoolbox provides various tools for remote sensing data analysis and is now available from CRAN: https://cran.r-project.org/web/packages/RStoolbox The main focus of RStoolbox is to provide a set of high-level remote sensing tools for various classification tasks. This includes unsupervised and supervised classification with different classifiers, fractional cover analysis and a spectral angle mapper. Furthermore, several spectral transformations like vegetation indices, principal component analysis or tasseled cap transformation are available as well. Besides that, we provide a set of data import and pre-processing functions. These include reading and tidying Landsat meta-data, importing ENVI spectral libraries, histogram matching, automatic image co-registration, topographic illumination correction and so on. Last but not least, RStoolbox ships with two functions dedicated to plotting remote sensing data (*raster* objects) with *ggplot2* including RGB color compositing with various contrast stretching options. RStoolbox is built on top of the *raster* package. To improve performance some functions use embedded C++ code via the *Rcpp* package. Moreover, most functions have built-in support for parallel processing, which is activated by running raster::beginCluster() beforehand RStoolbox is hosted at www.github.com/bleutner/RStoolbox For a more details, including executed examples, please see http://bleutner.github.io/RStoolbox/rstbx-docu/ We sincerely hope that this package may be helpful for some people and are looking forward to any feedback, suggestions and bug reports. -- Benjamin Leutner Ned Horning -- ------------------------------------------------- Benjamin Leutner M.Sc. Julius-Maximilians-Universit?t W?rzburg Institut f?r Geographie und Geologie Lehrstuhl f?r Fernerkundung Campus Hubland Nord -86- 97074 W?rzburg --- Tel: +49-(0)931-31 89594 Fax: +49-(0)931-31 89594-0 eMail: benjamin.leutner at uni-wuerzburg.de Web: http://www.fernerkundung.uni-wuerzburg.de From mdsumner at gmail.com Mon Sep 14 08:42:31 2015 From: mdsumner at gmail.com (Michael Sumner) Date: Mon, 14 Sep 2015 06:42:31 +0000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: I get reasonable results with this: library(maptools) data(wrld_simpl) library(raster) library(rgeos) ## this crop needs a buffer to work w1 <- intersect(gBuffer(wrld_simpl, width = 0.00001), as(extent(-180, 100, -90, 90), "SpatialPolygons")) w2 <- intersect(wrld_simpl, as(extent(100,180, -90, 90), "SpatialPolygons")) shiftw1 <- elide(w1, shift = c(360, 0)) plot(shiftw1, xlim = c(100, 100 + 360), col = "grey", border = NA) plot(w2, add = TRUE, col = "grey", border = NA) Sometimes rgeos needs a small buffer - I think it comes down to alignment of segments when the numeric precision is not sufficient. If you need borders you need to carefully re-construct the pieces. and how best to do that depends on your actual data (wrld_simpl is but one data set, not perfect for all) and your actual map. I just smashed the "DataFrame" part here, it's possible to keep it all but you might not need that. Cheers, Mike. On Mon, 14 Sep 2015 at 16:25 Nick Matzke wrote: > Although, unfortunately, the exact code, but switching "moll" to "latlong", > produces screwups (horizontal lines throughout the plot). Any advice? > > Works: > ==================== > pdffn = "wrld_simpl_moll.pdf" > pdf(file=pdffn, width=12, height=6) > > data(wrld_simpl) #The world as a SpatialPolygonsDataFrame > #To avoid the lines crossing the map after reprojection we need to cut the > polygons at the new break: > w <- nowrapRecenter(wrld_simpl, offset = 180-90, avoidGEOS=TRUE) > #Then proceed with the reprojection (note the proj4 string for a mollweide > projection with 150?E as the new center) > wrld_reCentered <- spTransform(w, CRS("+proj=moll +lon_0=-90")) > plot(wrld_reCentered, border="grey", lwd=0.5) > > > dev.off() > cmdstr = paste0("open ", pdffn) > system(cmdstr) > ==================== > > > Produces screwups: > ==================== > pdffn = "wrld_simpl_latlong.pdf" > pdf(file=pdffn, width=12, height=6) > > data(wrld_simpl) #The world as a SpatialPolygonsDataFrame > #To avoid the lines crossing the map after reprojection we need to cut the > polygons at the new break: > w <- nowrapRecenter(wrld_simpl, offset = 180-90, avoidGEOS=TRUE) > #Then proceed with the reprojection (note the proj4 string for a mollweide > projection with 150?E as the new center) > wrld_reCentered <- spTransform(w, CRS("+proj=longlat +lon_0=-90")) > plot(wrld_reCentered, border="grey", lwd=0.5) > > > dev.off() > cmdstr = paste0("open ", pdffn) > system(cmdstr) > ==================== > > On Mon, Sep 14, 2015 at 4:04 PM, Nick Matzke wrote: > > > Ah, this did it: > > > http://stackoverflow.com/questions/17718928/how-to-switch-to-a-map-that-is-centered-on-the-china-instead-of-the-default-set > > > > (plotting to PDF helps speed it up) > > > > library(geosphere) > > library(gdata) # for read.xls > > library(maptools) # for e.g. wrld_simpl > > library(rgdal) > > library(gpclib) # for polygon clipping > > > > pdffn = "wrld_simpl.pdf" > > pdf(file=pdffn, width=12, height=6) > > > > data(wrld_simpl) #The world as a SpatialPolygonsDataFrame > > #To avoid the lines crossing the map after reprojection we need to cut > the > > polygons at the new break: > > w <- nowrapRecenter(wrld_simpl, offset = 180-100, avoidGEOS=TRUE) > > #Then proceed with the reprojection (note the proj4 string for a > mollweide > > projection with 150?E as the new center) > > wrld_reCentered <- spTransform(w, CRS("+proj=moll +lon_0=-100")) > > plot(wrld_reCentered, border="grey", lwd=0.5) > > > > > > dev.off() > > cmdstr = paste0("open ", pdffn) > > system(cmdstr) > > > > > > > > > > On Mon, Sep 14, 2015 at 3:46 PM, Nick Matzke wrote: > > > >> Apologies, I got my wires crossed. > >> > >> What I meant was, how would I make a map where the left edge was at > >> longitude 100 (e.g. Thailand), and the right edge is at, say 99 > >> (again Thailand). The Pacific Ocean, and the International Dateline, > would > >> be in the middle of this map. > >> > >> I tried the obvious thing: > >> plot(wrld_simpl, xlim = c(100, 99)) > >> > >> ...but that produces a flipped map... > >> > >> Cheers! > >> Nick > >> > >> > >> On Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen < > frtog at vestas.com > >> > wrote: > >> > >>> Hi Nick > >>> > >>> To be honest I do not understand your question so I am guessing that > you > >>> probably only need to set the xlim to c(-100, 100). Here is an example: > >>> > >>> > data(wrld_simpl) > >>> > plot(wrld_simpl) > >>> > plot(wrld_simpl, xlim = c(-100, 100)) > >>> > >>> Why would one wants to redefine the longitudes from the interval (-180, > >>> 180) to (-100, 100)? > >>> > >>> > >>> Yours sincerely / Med venlig hilsen > >>> > >>> Frede Aakmann T?gersen > >>> Specialist, M.Sc., Ph.D. > >>> Plant Performance & Modeling > >>> > >>> Technology & Service Solutions > >>> T +45 9730 5135 > >>> M +45 2547 6050 > >>> frtog at vestas.com > >>> http://www.vestas.com > >>> > >>> Company reg. name: Vestas Wind Systems A/S > >>> This e-mail is subject to our e-mail disclaimer statement. > >>> Please refer to www.vestas.com/legal/notice > >>> If you have received this e-mail in error please contact the sender. > >>> > >>> > >>> -----Original Message----- > >>> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of > >>> Nick Matzke > >>> Sent: 14. september 2015 06:51 > >>> To: r-sig-geo at stat.math.ethz.ch > >>> Subject: [R-sig-Geo] making wrld_simpl longitude borders something > other > >>> than (-180, 180) > >>> > >>> Hi all, > >>> > >>> I would like to plot wrld_simpl, but have the left and right edges of > the > >>> map be at something like 100 degrees longitude, rather than (-180, > 180). > >>> > >>> I tried messing with the bounding box with no luck. > >>> > >>> I can imagine something like burrowing into the object and subtracting > 80 > >>> degrees from all the longitudes, but I suspect there must be a better > >>> way? > >>> > >>> Any help appreciated! > >>> Nick > >>> > >>> [[alternative HTML version deleted]] > >>> > >>> _______________________________________________ > >>> R-sig-Geo mailing list > >>> R-sig-Geo at r-project.org > >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo > >>> > >> > >> > > > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] From englishchristophera at gmail.com Mon Sep 14 10:58:49 2015 From: englishchristophera at gmail.com (englishchristophera at gmail.com) Date: Mon, 14 Sep 2015 10:58:49 +0200 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Message-ID: There is the minus sign part to enter. Though knowing what you are ultimately seeking would help clarify. That being said- dancing around the dateline is conspicuous for the difficulties that can present.Chris ------ Original message------From: Nick MatzkeDate: Mon, Sep 14, 2015 7:47 AMTo: Frede Aakmann T?gersen;Cc: r-sig-geo at stat.math.ethz.ch;Subject:Re: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) Apologies, I got my wires crossed.What I meant was, how would I make a map where the left edge was atlongitude 100 (e.g. Thailand), and the right edge is at, say 99(again Thailand). The Pacific Ocean, and the International Dateline, wouldbe in the middle of this map.I tried the obvious thing:plot(wrld_simpl, xlim = c(100, 99))...but that produces a flipped map...Cheers!NickOn Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen wrote:> Hi Nick>> To be honest I do not understand your question so I am guessing that you> probably only need to set the xlim to c(-100, 100). Here is an example:>> > data(wrld_simpl)> > plot(wrld_simpl)> > plot(wrld_simpl, xlim = c(-100, 100))>> Why would one wants to redefine the longitudes from the interval (-180,> 180) to (-100, 100)?>>> Yours sincerely / Med venlig hilsen>> Frede Aakmann T?gersen> Specialist, M.Sc., Ph.D.> Plant Performance & Modeling>> Technology & Service Solutions> T +45 9730 5135> M +45 2547 6050> frtog at vestas.com> http://www.vestas.com>> Company reg. name: Vestas Wind Systems A/S> This e-mail is subject to our e-mail disclaimer statement.> Please refer to www.vestas.com/legal/notice> If you have received this e-mail in error please contact the sender.>>> -----Original Message-----> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of> Nick Matzke> Sent: 14. september 2015 06:51> To: r-sig-geo at stat.math.ethz.ch> Subject: [R-sig-Geo] making wrld_simpl longitude borders something other> than (-180, 180)>> Hi all,>> I would like to plot wrld_simpl, but have the left and right edges of the> map be at something like 100 degrees longitude, rather than (-180, 180).>> I tried messing with the bounding box with no luck.>> I can imagine something like burrowing into the object and subtracting 80> degrees from all the longitudes, but I suspect there must be a better way?>> Any help appreciated!> Nick>> [[alternative HTML version deleted]]>> _______________________________________________> R-sig-Geo mailing list> R-sig-Geo at r-project.org> https://stat.ethz.ch/mailman/listinfo/r-sig-geo> [[alternative HTML version deleted]]_______________________________________________R-sig-Geo mailing listR-sig-Geo at r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From btupper at bigelow.org Mon Sep 14 13:36:41 2015 From: btupper at bigelow.org (Ben Tupper) Date: Mon, 14 Sep 2015 07:36:41 -0400 Subject: [R-sig-Geo] mapview 0.5.0 In-Reply-To: <55F552FA.7060404@gmail.com> References: <55F552FA.7060404@gmail.com> Message-ID: <5CACEA92-9DAA-46B6-8ABD-53CBE9C9C5C0@bigelow.org> Sweet! Thanks for sharing! On Sep 13, 2015, at 6:42 AM, Tim Appelhans wrote: > Dear all, > > I have put some more effort into mapview. > The current version 0.5.0 has some new features which make the whole experience much more user-friendly. > > In a nutshell, changes/additions are as follows: > > - mapView() is now also defined for SpatialPixelsDataFrame > - all Spatial * DataFrame methods have gained argument 'zcol' to select specific columns from the attribute table > - SpatialPointsDataFrame method has gained argument 'radius' to scale the circles according to another variable > - added viewRGB() to render true-/false-color images of RatserStacks/Bricks (like raster::plotRGB) > - added viewExtent() to view the extent/bbox of Raster*/Spatial* objects. This is useful for large objects as only the four corners of the extent need to be reprojected (using raster::projectExtent) > - defined '+'-method to easily add layers to a leaflet/mapview map or combine existing maps > - defined class 'mapview' which has two slots > - @object - a list with all objects that are shown on the map > - @map - the map > - Raster* methods have gained argument 'maxpixels' to avoid long rendering times (by default set to 500000 pixels which produces acceptable times on my machine) > - enhanced leaflet integration so that you can use leaflet maps and add features using mapview (e.g. '+') or use mapview to create maps and add functionality provided by leaflet (using e.g. %>%) > > As an example, this means that you can now do things like > > mapView(meuse.grid, zcol = "soil") + viewExtent(meuse) + meuse > > to view all points of meuse plus their extent on top of a raster layer of meuse.grid$soil > > All new functionality is highlighted in detail in the demo at > > http://environmentalinformatics-marburg.github.io/web-presentations/20150723_mapView.html > (the .Rmd source of which is now also included as a vignette in the package) > > The package repository can be found at https://github.com/environmentalinformatics-marburg/mapview > > To install the package use > > library(devtools) > install_github("environmentalinformatics-marburg/mapview") > > I hope this update will prove useful for some of you. > Don't hesitate to send me feedback and/or suggestions. > > Formal bug reports and feature requests should be filed at > https://github.com/environmentalinformatics-marburg/mapview/issues > > Best > Tim > > -- > ##################################### > Tim Appelhans > Department of Geography > Environmental Informatics > Philipps Universit?t Marburg > Deutschhausstra?e 12 > 35032 Marburg (Paketpost: 35037 Marburg) > Germany > > Tel +49 (0) 6421 28-25957 > > http://environmentalinformatics-marburg.de/ > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org From asookun at gmail.com Mon Sep 14 16:07:52 2015 From: asookun at gmail.com (Anand Sookun) Date: Mon, 14 Sep 2015 18:07:52 +0400 Subject: [R-sig-Geo] New package > RStoolbox: Remote Sensing Data Analysis in R In-Reply-To: <55F66AD4.1070001@uni-wuerzburg.de> References: <55F66AD4.1070001@uni-wuerzburg.de> Message-ID: Hi Thanks for theis. I needed this for land cover claasification for landsat 8 and hope it will be useful. I may contact you for help if required. Cheers Anand University of Mauritius On Mon, Sep 14, 2015 at 10:36 AM, Benjamin Leutner < benjamin.leutner at uni-wuerzburg.de> wrote: > Dear list members, > > We are happy to announce the initial release of our *RStoolbox* package. > RStoolbox provides various tools for remote sensing data analysis and is > now available from CRAN: > https://cran.r-project.org/web/packages/RStoolbox > > The main focus of RStoolbox is to provide a set of high-level remote > sensing tools for various classification tasks. This includes unsupervised > and supervised classification with different classifiers, fractional cover > analysis and a spectral angle mapper. Furthermore, several spectral > transformations like vegetation indices, principal component analysis or > tasseled cap transformation are available as well. > > Besides that, we provide a set of data import and pre-processing > functions. These include reading and tidying Landsat meta-data, importing > ENVI spectral libraries, histogram matching, automatic image > co-registration, topographic illumination correction and so on. > > Last but not least, RStoolbox ships with two functions dedicated to > plotting remote sensing data (*raster* objects) with *ggplot2* including > RGB color compositing with various contrast stretching options. > > RStoolbox is built on top of the *raster* package. To improve performance > some functions use embedded C++ code via the *Rcpp* package. Moreover, most > functions have built-in support for parallel processing, which is activated > by running raster::beginCluster() beforehand > > RStoolbox is hosted at www.github.com/bleutner/RStoolbox > > For a more details, including executed examples, please see > http://bleutner.github.io/RStoolbox/rstbx-docu/ > > We sincerely hope that this package may be helpful for some people and are > looking forward to any feedback, suggestions and bug reports. > > -- > Benjamin Leutner > Ned Horning > > -- > ------------------------------------------------- > Benjamin Leutner M.Sc. > > Julius-Maximilians-Universit?t W?rzburg > Institut f?r Geographie und Geologie > Lehrstuhl f?r Fernerkundung > Campus Hubland Nord -86- > 97074 W?rzburg > > --- > Tel: +49-(0)931-31 89594 > Fax: +49-(0)931-31 89594-0 > eMail: benjamin.leutner at uni-wuerzburg.de > Web: http://www.fernerkundung.uni-wuerzburg.de > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- ------------------------------------------------------- [[alternative HTML version deleted]] From denn2duk at yahoo.com Mon Sep 14 19:39:36 2015 From: denn2duk at yahoo.com (Denys Dukhovnov) Date: Mon, 14 Sep 2015 17:39:36 +0000 (UTC) Subject: [R-sig-Geo] More efficient raster extraction Message-ID: <1225733380.2295118.1442252376829.JavaMail.yahoo@mail.yahoo.com> Hello, I am trying to extract 300 meter raster cell values over Census block polygons for each of the US states. Because 300m cells are much larger than typical urban blocks, I had to specify "small" option (as shown below) so that no polygon will remain "blank" without a corresponding raster value(s). Blocks shapefile for District Columbia with about 6,500 blocks, for example, being the smallest state, takes 15 minutes to complete, but New York with almost 350,000 block polygons would not complete even in 4 days. On a separate occasion I also tried using parallel processing (foreach), but this only appears to slow down the extract function, rather than speeding it up. I clipped the main raster to the extent of each state, but this doesn't help (not much, anyway). In this case the vector data are huge, so I would expect any improvement in efficiency to come from reducing its burden on the process. Please share any advice as to how I can make the extract function faster and more efficient. Thank you very much! Faster method: Without parallel processing: BlockIndex <- extract(Raster_300m, Blocks, df=TRUE, small=TRUE) Indefinitely slow: With parallel processing (8 registered cores): BlockIndex <- foreach (i=1:length(Blocks$GEOID10), .combine='c', .packages="raster") %dopar% { ??? ??? extract(Raster_300m, Blocks[i], df=TRUE, small=TRUE)} Regards, Denys Dukhovnov [[alternative HTML version deleted]] From timjp at unimelb.edu.au Tue Sep 15 02:19:54 2015 From: timjp at unimelb.edu.au (Tim Peterson) Date: Tue, 15 Sep 2015 10:19:54 +1000 Subject: [R-sig-Geo] Gstat 'polylines' implemented in R? In-Reply-To: <55E95B3B.20504@uni-muenster.de> References: <55E91EB1.2030803@unimelb.edu.au> <55E95B3B.20504@uni-muenster.de> Message-ID: <55F7642A.6000309@unimelb.edu.au> On 04/09/15 18:50, Edzer Pebesma wrote: > > On 09/04/2015 06:31 AM, Tim Peterson wrote: >> Hi all, >> >> I'm keen to use the gstat feature 'polylines' (appendix B in >> http://www.gstat.org/gstat.pdf) to restrict the point sample selection >> to within a polygon. That is, when undertaking localised kriging at a >> grid cell, samples are only used in the estimation if a line between the >> sample and grid cell does not cross a polygon boundary. The polylines >> feature appears to be implemented within the c-code for gstat >> (polygon.c) but I cannot find any means to use it within R-gstat nor any >> mention on lists. Any tips would be most welcome. > That is correct, it has not been interfaced from the R code. > > The idea is nice, but if you work with it you see very very much > unwanted features in the interpolated surface: sharp edges that follow > the "shadow" of the polygon, as seen from an observation with an extreme > value. Back then we thought about a work-around for this using distances > measured "around" the obstacles, but that leads to non-positive definite > covariance functions. Thanks the background - and thanks again for your contribution to the list. I suspect my application is considerably simpler than those for which polylines was tested on. I'm trying to take account of coastlines whereby I do not want observations that are on one side of a bay (as in coastline) to be used in the kriging estimation of the adjacent side of the bay. Code I've written in GSLib and application to mapping the watertable of greater Melbourne did not show artefacts. Anyway, it seems to me that get_n_edges() is the C function called within select.c for achieving such a restriction on the point selection. If I get the time, I'll investigate using a 'set' command for controlling polylines within R. >> Thanks, >> >> Tim >> >> ---------------------- >> Dr. Tim Peterson >> >> The Department of Infrastructure Engineering >> The University of Melbourne, 3010 Australia >> T: +61 3 8344 9950 , M: +61 0438 385 937 >> >> >> Dept. profile : >> http://www.ie.unimelb.edu.au/people/staff.php?person_ID=141135 >> Research Gate : https://www.researchgate.net/profile/Tim_Peterson7 >> Google Scholar: >> http://scholar.google.com.au/citations?user=kkYJLF4AAAAJ&hl=en&oi=ao >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- ---------------------- Dr. Tim Peterson The Department of Infrastructure Engineering The University of Melbourne, 3010 Australia T: +61 3 8344 9950 , M: +61 0438 385 937 Dept. profile : http://www.ie.unimelb.edu.au/people/staff.php?person_ID=141135 Research Gate : https://www.researchgate.net/profile/Tim_Peterson7 Google Scholar: http://scholar.google.com.au/citations?user=kkYJLF4AAAAJ&hl=en&oi=ao [[alternative HTML version deleted]] From jorge.jesus at gmail.com Tue Sep 15 09:40:24 2015 From: jorge.jesus at gmail.com (Jorge de Jesus) Date: Tue, 15 Sep 2015 09:40:24 +0200 Subject: [R-sig-Geo] No installations match error from gdalwarp (gdalUtils) Message-ID: Hi to all I am posting a problem concerning gdalUtils amd a gdalwarp. I dont tend to use R so even basic help/explanation maybe be requires I have made a new install based on gdal2.0.0 > library(rgdal) Loading required package: sp rgdal: version: 1.0-7, (SVN revision 559) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.0, released 2015/06/14 Path to GDAL shared files: /usr/local/share/gdal Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491] Path to PROJ.4 shared files: (autodetected) Linking to sp version: 1.1-1 Loding gdalUtils is not a problem getOption("gdalUtils_gdalPath") http://pastebin.com/DJCMxaci > gdal_chooseInstallation() [1] 1 *Problem:* When I try gdalwarp with/without arguments I always get: > gdalwarp() Error in gdal_chooseInstallation(hasDrivers = of) : No installations match. I also tried the following: > gdal_chooseInstallation(hasDrivers=c("VRT")) Error in gdal_chooseInstallation(hasDrivers = c("VRT")) : No installations match. >From the getOptions above I can see that my installation supports VRT So, any suggestions or comments THank you in advance -- OpenPGP Key: 0x7212572C [[alternative HTML version deleted]] From grothered at gmail.com Tue Sep 15 12:14:45 2015 From: grothered at gmail.com (Gareth Davies) Date: Tue, 15 Sep 2015 20:14:45 +1000 Subject: [R-sig-Geo] More efficient raster extraction Message-ID: <55F7EF95.1090107@gmail.com> Hi, In the past I had a similar issue (86000 polygons), and found a reasonably efficient approach was to: 1) Take my polygons, and burn a unique ID value for each into a new raster, with the same dimensions/cellsize as the target raster (300m pixels in your case). I did this outside of R, using gdal_rasterize. 2) Use 'crosstab' in the raster package in R to get the values of the target raster associated with each polygon ID. Cheers, Gareth. From englishchristophera at gmail.com Tue Sep 15 12:27:05 2015 From: englishchristophera at gmail.com (englishchristophera at gmail.com) Date: Tue, 15 Sep 2015 12:27:05 +0200 Subject: [R-sig-Geo] No installations match error from gdalwarp (gdalUtils) Message-ID: Jorge:As a WA guess i think it might have to do with write permissions either in the folder where you are writing to or where the intermediate (temporary) ?copy is being attempted.?As i say a guess- but it has that 'you are not a super user' and ?i don't know how to do that for mere you look about it.Hope this is even vaguely useful.Chris ------ Original message------From: Jorge de JesusDate: Tue, Sep 15, 2015 9:41 AMTo: r-sig-geo at r-project.org;Cc: Shangguan, Wei;Subject:[R-sig-Geo] No installations match error from gdalwarp (gdalUtils) Hi to allI am posting a problem concerning gdalUtils amd a gdalwarp. I dont tend touse R so even basic help/explanation maybe be requiresI have made a new install based on gdal2.0.0> library(rgdal)Loading required package: sprgdal: version: 1.0-7, (SVN revision 559) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.0, released 2015/06/14 Path to GDAL shared files: /usr/local/share/gdal Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491] Path to PROJ.4 shared files: (autodetected) Linking to sp version: 1.1-1Loding gdalUtils is not a problemgetOption("gdalUtils_gdalPath")http://pastebin.com/DJCMxaci> gdal_chooseInstallation()[1] 1*Problem:*When I try gdalwarp with/without arguments I always get:> gdalwarp()Error in gdal_chooseInstallation(hasDrivers = of) : No installations match.I also tried the following:> gdal_chooseInstallation(hasDrivers=c("VRT"))Error in gdal_chooseInstallation(hasDrivers = c("VRT")) : No installations match.>From the getOptions above I can see that my installation supports VRTSo, any suggestions or commentsTHank you in advance-- OpenPGP Key: 0x7212572C [[alternative HTML version deleted]]_______________________________________________R-sig-Geo mailing listR-sig-Geo at r-project.orghttps://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From jorge.jesus at gmail.com Tue Sep 15 13:48:23 2015 From: jorge.jesus at gmail.com (Jorge de Jesus) Date: Tue, 15 Sep 2015 13:48:23 +0200 Subject: [R-sig-Geo] No installations match error from gdalwarp (gdalUtils) In-Reply-To: References: Message-ID: Hi to all Chris, thank you for the tip, but I dont think that was the case I have tested things runing as root and on /tmp > getwd() [1] "/tmp" > tempdir() [1] "/tmp/RtmpxoZ0nt" I tested gdalinfo and it works fine but then again this is just reading the file, gdalwarp,gdal_translate give me the same error > gdal_translate("/tmp/J18.hillshade.tiff","/tmp/J18.hillshade2.tiff",t_srs="EPSG:4326") Error in gdal_chooseInstallation(hasDrivers = of) : No installations match. Thank you for the help Cheers Jorge On Tue, Sep 15, 2015 at 12:27 PM, englishchristophera at gmail.com < englishchristophera at gmail.com> wrote: > > > Jorge: > > As a WA guess i think it might have to do with write permissions either in > the folder where you are writing to or where the intermediate (temporary) > copy is being attempted. > > As i say a guess- but it has that 'you are not a super user' and i don't > know how to do that for mere you look about it. > > Hope this is even vaguely useful. > > Chris > > > ------ Original message------ > > *From: *Jorge de Jesus > > *Date: *Tue, Sep 15, 2015 9:41 AM > > *To: *r-sig-geo at r-project.org; > > *Cc: *Shangguan, Wei; > > *Subject:*[R-sig-Geo] No installations match error from gdalwarp > (gdalUtils) > > > Hi to allI am posting a problem concerning gdalUtils amd a gdalwarp. I dont tend touse R so even basic help/explanation maybe be requiresI have made a new install based on gdal2.0.0> library(rgdal)Loading required package: sprgdal: version: 1.0-7, (SVN revision 559) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.0, released 2015/06/14 Path to GDAL shared files: /usr/local/share/gdal Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491] Path to PROJ.4 shared files: (autodetected) Linking to sp version: 1.1-1Loding gdalUtils is not a problemgetOption("gdalUtils_gdalPath")http://pastebin.com/DJCMxaci> gdal_chooseInstallation()[1] 1*Problem:*When I try gdalwarp with/without arguments I always get:> gdalwarp()Error in gdal_chooseInstallation(hasDrivers = of) : No installations match.I also tried the following:> gdal_chooseInstallation(hasDrivers=c("VRT"))Error in gdal_chooseInstallation(hasDrivers = c("VRT")) : No installations match.>From the getOptions above I can see that my installation supports VRTSo, any suggestions or commentsTHank you in advance-- OpenPGP Key: 0x7212572C [[alternative HTML version deleted]]_______________________________________________R-sig-Geo mailing listR-sig-Geo at r-project.orghtt <+listR-sig-Geo at r-project.orghtt>ps://stat.ethz.ch/mailman/listinfo/r-sig-geo > > -- OpenPGP Key: 0x7212572C [[alternative HTML version deleted]] From tim.appelhans at gmail.com Tue Sep 15 19:11:16 2015 From: tim.appelhans at gmail.com (Tim Appelhans) Date: Tue, 15 Sep 2015 19:11:16 +0200 Subject: [R-sig-Geo] New package > RStoolbox: Remote Sensing Data Analysis in R In-Reply-To: <55F66AD4.1070001@uni-wuerzburg.de> References: <55F66AD4.1070001@uni-wuerzburg.de> Message-ID: <55F85134.2030802@gmail.com> Benjamin, I think we should put our heads together at some stage as we have already something very similar on CRAN (released in July) https://cran.r-project.org/web/packages/satellite/index.html The satellite package provides standard class(es) and methods for handling satellite data. We deliberately avoided adding any functionality that goes beyond basic image preparation (i.e. classification or prediction capabilities). The idea is to provide a standard package for remote sensing data handling (satellite) on top of which other packages can be built to provide further functionality (such as the numerous classification algorithms in RStoolbox). Think of it as the 'sp' package for satellite remote sensing data analysis. To get a better idea of how satellite is designed please have a look at the following vignette (which is not quite finished but does provide an overview of how the 'satellite' class is defined). https://github.com/environmentalinformatics-marburg/satellite/blob/develop/vignettes/satellite.Rmd I would appreciate your thoughts (maybe off-list) on how to best arrange our efforts in order to avoid duplication and confusion for other users. Best Tim On 14.09.2015 08:36, Benjamin Leutner wrote: > Dear list members, > > We are happy to announce the initial release of our *RStoolbox* package. > RStoolbox provides various tools for remote sensing data analysis and > is now available from CRAN: > https://cran.r-project.org/web/packages/RStoolbox > > The main focus of RStoolbox is to provide a set of high-level remote > sensing tools for various classification tasks. This includes > unsupervised and supervised classification with different classifiers, > fractional cover analysis and a spectral angle mapper. Furthermore, > several spectral transformations like vegetation indices, principal > component analysis or tasseled cap transformation are available as well. > > Besides that, we provide a set of data import and pre-processing > functions. These include reading and tidying Landsat meta-data, > importing ENVI spectral libraries, histogram matching, automatic image > co-registration, topographic illumination correction and so on. > > Last but not least, RStoolbox ships with two functions dedicated to > plotting remote sensing data (*raster* objects) with *ggplot2* > including RGB color compositing with various contrast stretching options. > > RStoolbox is built on top of the *raster* package. To improve > performance some functions use embedded C++ code via the *Rcpp* > package. Moreover, most functions have built-in support for parallel > processing, which is activated by running raster::beginCluster() > beforehand > > RStoolbox is hosted at www.github.com/bleutner/RStoolbox > > For a more details, including executed examples, please see > http://bleutner.github.io/RStoolbox/rstbx-docu/ > > We sincerely hope that this package may be helpful for some people and > are looking forward to any feedback, suggestions and bug reports. > -- ##################################### Tim Appelhans Department of Geography Environmental Informatics Philipps Universit?t Marburg Deutschhausstra?e 12 35032 Marburg (Paketpost: 35037 Marburg) Germany Tel +49 (0) 6421 28-25957 http://environmentalinformatics-marburg.de/ From sarah.goslee at gmail.com Tue Sep 15 19:23:14 2015 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Tue, 15 Sep 2015 13:23:14 -0400 Subject: [R-sig-Geo] New package > RStoolbox: Remote Sensing Data Analysis in R In-Reply-To: <55F85134.2030802@gmail.com> References: <55F66AD4.1070001@uni-wuerzburg.de> <55F85134.2030802@gmail.com> Message-ID: And also the landsat package, also on CRAN. Sarah On Tue, Sep 15, 2015 at 1:11 PM, Tim Appelhans wrote: > Benjamin, > I think we should put our heads together at some stage as we have already > something very similar on CRAN (released in July) > > https://cran.r-project.org/web/packages/satellite/index.html > > The satellite package provides standard class(es) and methods for handling > satellite data. We deliberately avoided adding any functionality that goes > beyond basic image preparation (i.e. classification or prediction > capabilities). The idea is to provide a standard package for remote sensing > data handling (satellite) on top of which other packages can be built to > provide further functionality (such as the numerous classification > algorithms in RStoolbox). Think of it as the 'sp' package for satellite > remote sensing data analysis. > > To get a better idea of how satellite is designed please have a look at the > following vignette (which is not quite finished but does provide an overview > of how the 'satellite' class is defined). > > https://github.com/environmentalinformatics-marburg/satellite/blob/develop/vignettes/satellite.Rmd > > I would appreciate your thoughts (maybe off-list) on how to best arrange our > efforts in order to avoid duplication and confusion for other users. > > Best > Tim > > On 14.09.2015 08:36, Benjamin Leutner wrote: >> >> Dear list members, >> >> We are happy to announce the initial release of our *RStoolbox* package. >> RStoolbox provides various tools for remote sensing data analysis and is >> now available from CRAN: >> https://cran.r-project.org/web/packages/RStoolbox >> >> The main focus of RStoolbox is to provide a set of high-level remote >> sensing tools for various classification tasks. This includes unsupervised >> and supervised classification with different classifiers, fractional cover >> analysis and a spectral angle mapper. Furthermore, several spectral >> transformations like vegetation indices, principal component analysis or >> tasseled cap transformation are available as well. >> >> Besides that, we provide a set of data import and pre-processing >> functions. These include reading and tidying Landsat meta-data, importing >> ENVI spectral libraries, histogram matching, automatic image >> co-registration, topographic illumination correction and so on. >> >> Last but not least, RStoolbox ships with two functions dedicated to >> plotting remote sensing data (*raster* objects) with *ggplot2* including RGB >> color compositing with various contrast stretching options. >> >> RStoolbox is built on top of the *raster* package. To improve performance >> some functions use embedded C++ code via the *Rcpp* package. Moreover, most >> functions have built-in support for parallel processing, which is activated >> by running raster::beginCluster() beforehand >> >> RStoolbox is hosted at www.github.com/bleutner/RStoolbox >> >> For a more details, including executed examples, please see >> http://bleutner.github.io/RStoolbox/rstbx-docu/ >> >> We sincerely hope that this package may be helpful for some people and are >> looking forward to any feedback, suggestions and bug reports. >> > > -- > ##################################### > Tim Appelhans > Department of Geography > Environmental Informatics > Philipps Universit?t Marburg > Deutschhausstra?e 12 > 35032 Marburg (Paketpost: 35037 Marburg) > Germany > > Tel +49 (0) 6421 28-25957 > > http://environmentalinformatics-marburg.de/ > -- Sarah Goslee http://www.functionaldiversity.org From tbelote at tws.org Tue Sep 15 20:24:24 2015 From: tbelote at tws.org (Travis Belote) Date: Tue, 15 Sep 2015 18:24:24 +0000 Subject: [R-sig-Geo] colored histogram that matches map Message-ID: <67d4c44b39694ffdb3a9f7be4718be86@twsexch12k13.tws.org> Hi all, I would like to use color histograms for map legends. Does anyone have code for creating a map and histogram in R that share the same color ramps (as in examples shown here: https://sites.google.com/site/hamishbowman/grass_color_maps )? I realize this might be a simple question. I appreciate any code or help you might have to get me started. Thank you very much, Travis Travis Belote, Ph.D. Research Ecologist The Wilderness Society | Northern Rockies Regional Office 503 W. Mendenhall, Bozeman, MT 59715 cell: 406.581.3808 From thi_veloso at yahoo.com.br Wed Sep 16 04:51:30 2015 From: thi_veloso at yahoo.com.br (Thiago V. dos Santos) Date: Wed, 16 Sep 2015 02:51:30 +0000 (UTC) Subject: [R-sig-Geo] Conditional operations and rasters Message-ID: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> Hi all, This is probably a silly question, but I could not find an appropriate answer somewhere else. I am trying create a raster based on conditional statements applied on an original raster. This is some sample code: lai <- raster(ncols=360, nrows=180) lai[] <- 1:ncell(lai) if (lai < 1000) { emiss_0 <- 0.95 + (0.01 * lai) emiss_nb <- 0.97 + (0.0033 * lai) } else if (lai >= 1000) { emiss_0 <- 0.95 emiss_nb <- 0.98 } Error in if (lai < 3) { : argument is not interpretable as logical What would be the right way to do that? Greetings, -- Thiago V. dos Santos PhD student Land and Atmospheric Science University of Minnesota From vijaylulla at gmail.com Wed Sep 16 05:30:50 2015 From: vijaylulla at gmail.com (Vijay Lulla) Date: Tue, 15 Sep 2015 23:30:50 -0400 Subject: [R-sig-Geo] Conditional operations and rasters In-Reply-To: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> References: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> Message-ID: I have no idea what you're trying to accomplish with your program logic but I think the below might work for you. R> lai <- raster(ncols=360,nros=180) R> lai[] <- 1:ncell(lai) R> idx <- lai < 1000 R> emiss_0 <- lai R> emiss_0[] <- 0.95 R> emiss_0[idx] <- 0.95 + (lai[idx]*0.01) R> emiss_nb <- lai R> emiss_nb[] <- 0.98 R> emiss_nb[!idx] <- 0.97+(lai[!idx]*0.0033) R> ?Which # from raster package Other gurus on the list might suggest more efficient way[s] of doing this. HTH, Vijay. On Tue, Sep 15, 2015 at 10:51 PM, Thiago V. dos Santos wrote: > Hi all, > > This is probably a silly question, but I could not find an appropriate answer somewhere else. > > I am trying create a raster based on conditional statements applied on an original raster. > > This is some sample code: > > lai <- raster(ncols=360, nrows=180) > lai[] <- 1:ncell(lai) > > if (lai < 1000) { > > emiss_0 <- 0.95 + (0.01 * lai) > emiss_nb <- 0.97 + (0.0033 * lai) > > > } else if (lai >= 1000) { > > > emiss_0 <- 0.95 > emiss_nb <- 0.98 > > > } > > Error in if (lai < 3) { : argument is not interpretable as logical > > > What would be the right way to do that? > Greetings, > -- Thiago V. dos Santos > > PhD student > Land and Atmospheric Science > University of Minnesota > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From vitale232 at gmail.com Wed Sep 16 05:47:32 2015 From: vitale232 at gmail.com (Andrew Vitale) Date: Tue, 15 Sep 2015 20:47:32 -0700 Subject: [R-sig-Geo] Conditional operations and rasters In-Reply-To: References: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> Message-ID: I would do something like the following: library(raster) lai <- raster(ncols=50, nrows=50) lai[] <- 1:ncell(lai) emmiss_0_func <- function(lai) { emmiss_0 <- ifelse((lai < 1000), (0.95 + (0.01 * lai)), 0.95) return(emmiss_0) } emmiss_nb_func <- function(lai) { emmiss_nb <- ifelse((lai < 1000), (0.97 + (0.0033 * lai)), 0.98) return(emmiss_nb) } emiss <- stack(calc(lai, emmiss_0_func), calc(lai, emmiss_nb_func)) plot(emiss) On Tue, Sep 15, 2015 at 8:30 PM, Vijay Lulla wrote: > I have no idea what you're trying to accomplish with your program > logic but I think the below might work for you. > > R> lai <- raster(ncols=360,nros=180) > R> lai[] <- 1:ncell(lai) > > R> idx <- lai < 1000 > R> emiss_0 <- lai > R> emiss_0[] <- 0.95 > R> emiss_0[idx] <- 0.95 + (lai[idx]*0.01) > > R> emiss_nb <- lai > R> emiss_nb[] <- 0.98 > R> emiss_nb[!idx] <- 0.97+(lai[!idx]*0.0033) > R> ?Which # from raster package > > Other gurus on the list might suggest more efficient way[s] of doing this. > > HTH, > Vijay. > > On Tue, Sep 15, 2015 at 10:51 PM, Thiago V. dos Santos > wrote: > > Hi all, > > > > This is probably a silly question, but I could not find an appropriate > answer somewhere else. > > > > I am trying create a raster based on conditional statements applied on > an original raster. > > > > This is some sample code: > > > > lai <- raster(ncols=360, nrows=180) > > lai[] <- 1:ncell(lai) > > > > if (lai < 1000) { > > > > emiss_0 <- 0.95 + (0.01 * lai) > > emiss_nb <- 0.97 + (0.0033 * lai) > > > > > > } else if (lai >= 1000) { > > > > > > emiss_0 <- 0.95 > > emiss_nb <- 0.98 > > > > > > } > > > > Error in if (lai < 3) { : argument is not interpretable as logical > > > > > > What would be the right way to do that? > > Greetings, > > -- Thiago V. dos Santos > > > > PhD student > > Land and Atmospheric Science > > University of Minnesota > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo at r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- *Andrew P. Vitale* Staff Research Scientist Desert Research Institute 2215 Raggio Pkwy Reno, NV 89512 [[alternative HTML version deleted]] From benjamin.leutner at uni-wuerzburg.de Wed Sep 16 10:36:52 2015 From: benjamin.leutner at uni-wuerzburg.de (Benjamin Leutner) Date: Wed, 16 Sep 2015 10:36:52 +0200 Subject: [R-sig-Geo] New package > RStoolbox: Remote Sensing Data Analysis in R In-Reply-To: References: <55F66AD4.1070001@uni-wuerzburg.de> <55F85134.2030802@gmail.com> Message-ID: <55F92A24.2030100@uni-wuerzburg.de> Hi, @Tim: good to know of your package. I am checking it out right now and will get back to you off-list. The satellite class seems to be exactly what we need and I think we could build on top of it. @Sarah: of course we're aware of the landsat package. However, our students working with smaller workstations frequently encountered memory limitations due to the lack of raster support. Therefore we added a few functions which could be achieved similarly with SpatialPixelsDataFrames and the landsat package if you had enough memory. Benjamin On 15.09.2015 19:23, Sarah Goslee wrote: > And also the landsat package, also on CRAN. > > Sarah > > On Tue, Sep 15, 2015 at 1:11 PM, Tim Appelhans wrote: >> Benjamin, >> I think we should put our heads together at some stage as we have already >> something very similar on CRAN (released in July) >> >> https://cran.r-project.org/web/packages/satellite/index.html >> >> The satellite package provides standard class(es) and methods for handling >> satellite data. We deliberately avoided adding any functionality that goes >> beyond basic image preparation (i.e. classification or prediction >> capabilities). The idea is to provide a standard package for remote sensing >> data handling (satellite) on top of which other packages can be built to >> provide further functionality (such as the numerous classification >> algorithms in RStoolbox). Think of it as the 'sp' package for satellite >> remote sensing data analysis. >> >> To get a better idea of how satellite is designed please have a look at the >> following vignette (which is not quite finished but does provide an overview >> of how the 'satellite' class is defined). >> >> https://github.com/environmentalinformatics-marburg/satellite/blob/develop/vignettes/satellite.Rmd >> >> I would appreciate your thoughts (maybe off-list) on how to best arrange our >> efforts in order to avoid duplication and confusion for other users. >> >> Best >> Tim >> >> On 14.09.2015 08:36, Benjamin Leutner wrote: >>> Dear list members, >>> >>> We are happy to announce the initial release of our *RStoolbox* package. >>> RStoolbox provides various tools for remote sensing data analysis and is >>> now available from CRAN: >>> https://cran.r-project.org/web/packages/RStoolbox >>> >>> The main focus of RStoolbox is to provide a set of high-level remote >>> sensing tools for various classification tasks. This includes unsupervised >>> and supervised classification with different classifiers, fractional cover >>> analysis and a spectral angle mapper. Furthermore, several spectral >>> transformations like vegetation indices, principal component analysis or >>> tasseled cap transformation are available as well. >>> >>> Besides that, we provide a set of data import and pre-processing >>> functions. These include reading and tidying Landsat meta-data, importing >>> ENVI spectral libraries, histogram matching, automatic image >>> co-registration, topographic illumination correction and so on. >>> >>> Last but not least, RStoolbox ships with two functions dedicated to >>> plotting remote sensing data (*raster* objects) with *ggplot2* including RGB >>> color compositing with various contrast stretching options. >>> >>> RStoolbox is built on top of the *raster* package. To improve performance >>> some functions use embedded C++ code via the *Rcpp* package. Moreover, most >>> functions have built-in support for parallel processing, which is activated >>> by running raster::beginCluster() beforehand >>> >>> RStoolbox is hosted at www.github.com/bleutner/RStoolbox >>> >>> For a more details, including executed examples, please see >>> http://bleutner.github.io/RStoolbox/rstbx-docu/ >>> >>> We sincerely hope that this package may be helpful for some people and are >>> looking forward to any feedback, suggestions and bug reports. >>> >> -- >> ##################################### >> Tim Appelhans >> Department of Geography >> Environmental Informatics >> Philipps Universit?t Marburg >> Deutschhausstra?e 12 >> 35032 Marburg (Paketpost: 35037 Marburg) >> Germany >> >> Tel +49 (0) 6421 28-25957 >> >> http://environmentalinformatics-marburg.de/ >> > -- Benjamin Leutner M.Sc. Department of Remote Sensing University of Wuerzburg Campus Hubland Nord 86 97074 Wuerzburg, Germany Tel: +49-(0)931-31 89594 Fax: +49-(0)931-31 89594-0 Email: benjamin.leutner at uni-wuerzburg.de Web: http://www.fernerkundung.uni-wuerzburg.de From juamecos at gmail.com Wed Sep 16 17:14:37 2015 From: juamecos at gmail.com (juan jose mena) Date: Wed, 16 Sep 2015 17:14:37 +0200 Subject: [R-sig-Geo] Landscape metrics: SDMTools. Error installation Message-ID: Dear all, I am Juan Jos? Mena, this is my first post but I need some help because I need to compute patch and class metrics and the SDMTools package failed in the installation. Does anyone know how to install it? Is there any alternative? thanks in advance Juan > install.packages('SDMTools',,'http://www.rforge.net/') Error in install.packages : argument is missing, with no default > library(SDMTools) Error: package ?SDMTools? was built before R 3.0.0: please re-install it > library("SDMTools", lib.loc="C:/Program Files/R/R-3.1.3/library") Error: package ?SDMTools? was built before R 3.0.0: please re-install it > install.packages("C:/Program Files/R/SDMTools_1.1-14.zip", repos = NULL) package ?SDMTools? successfully unpacked and MD5 sums checked Warning messages: 1: display list redraw incomplete 2: display list redraw incomplete > library(SDMTools) Error: package ?SDMTools? was built before R 3.0.0: please re-install it [[alternative HTML version deleted]] From sarah.goslee at gmail.com Wed Sep 16 17:21:54 2015 From: sarah.goslee at gmail.com (Sarah Goslee) Date: Wed, 16 Sep 2015 11:21:54 -0400 Subject: [R-sig-Geo] Landscape metrics: SDMTools. Error installation In-Reply-To: References: Message-ID: >> install.packages('SDMTools',,'http://www.rforge.net/') > Error in install.packages : argument is missing, with no default I'd start by rerunning this command without the extra comma. On Wed, Sep 16, 2015 at 11:14 AM, juan jose mena wrote: > Dear all, > > I am Juan Jos? Mena, this is my first post but I need some help because I > need to compute patch and class metrics and the SDMTools package failed in > the installation. Does anyone know how to install it? Is there any > alternative? > thanks in advance > > Juan > >> install.packages('SDMTools',,'http://www.rforge.net/') > Error in install.packages : argument is missing, with no default >> library(SDMTools) > Error: package ?SDMTools? was built before R 3.0.0: please re-install it >> library("SDMTools", lib.loc="C:/Program Files/R/R-3.1.3/library") > Error: package ?SDMTools? was built before R 3.0.0: please re-install it >> install.packages("C:/Program Files/R/SDMTools_1.1-14.zip", repos = NULL) > package ?SDMTools? successfully unpacked and MD5 sums checked > Warning messages: > 1: display list redraw incomplete > 2: display list redraw incomplete >> library(SDMTools) > Error: package ?SDMTools? was built before R 3.0.0: please re-install it > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Sarah Goslee http://www.functionaldiversity.org From SWalbridge at esri.com Wed Sep 16 17:21:57 2015 From: SWalbridge at esri.com (Shaun Walbridge) Date: Wed, 16 Sep 2015 15:21:57 +0000 Subject: [R-sig-Geo] Landscape metrics: SDMTools. Error installation In-Reply-To: References: Message-ID: Try installing it from CRAN instead: # R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk" # Platform: i386-w64-mingw32/i386 (32-bit) install.packages("SDMTools") # le package ?SDMTools? a ?t? d?compress? et les sommes MD5 ont ?t? v?rifi?es avec succ?s -- Shaun Walbridge GIS Developer On 9/16/15, 11:14 AM, "R-sig-Geo on behalf of juan jose mena" wrote: >Dear all, > >I am Juan Jos? Mena, this is my first post but I need some help because I >need to compute patch and class metrics and the SDMTools package failed in >the installation. Does anyone know how to install it? Is there any >alternative? >thanks in advance > >Juan > >> install.packages('SDMTools',,'http://www.rforge.net/') >Error in install.packages : argument is missing, with no default >> library(SDMTools) >Error: package ?SDMTools? was built before R 3.0.0: please re-install it >> library("SDMTools", lib.loc="C:/Program Files/R/R-3.1.3/library") >Error: package ?SDMTools? was built before R 3.0.0: please re-install it >> install.packages("C:/Program Files/R/SDMTools_1.1-14.zip", repos = NULL) >package ?SDMTools? successfully unpacked and MD5 sums checked >Warning messages: >1: display list redraw incomplete >2: display list redraw incomplete >> library(SDMTools) >Error: package ?SDMTools? was built before R 3.0.0: please re-install it > > [[alternative HTML version deleted]] > >_______________________________________________ >R-sig-Geo mailing list >R-sig-Geo at r-project.org >https://stat.ethz.ch/mailman/listinfo/r-sig-geo From juamecos at gmail.com Wed Sep 16 18:07:00 2015 From: juamecos at gmail.com (juan jose mena) Date: Wed, 16 Sep 2015 18:07:00 +0200 Subject: [R-sig-Geo] Landscape metrics: SDMTools. Error installation In-Reply-To: References: Message-ID: Thanks Alexandre for your tips, and all the others for the answers. I updated all the packages and finally I installed from CRAN without doble comma. Now working, thanks 2015-09-16 17:21 GMT+02:00 Shaun Walbridge : > Try installing it from CRAN instead: > > # R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk" > # Platform: i386-w64-mingw32/i386 (32-bit) > > > install.packages("SDMTools") > > # le package ?SDMTools? a ?t? d?compress? et les sommes MD5 ont ?t? > v?rifi?es avec succ?s > -- > Shaun Walbridge > GIS Developer > > > > On 9/16/15, 11:14 AM, "R-sig-Geo on behalf of juan jose mena" > wrote: > > >Dear all, > > > >I am Juan Jos? Mena, this is my first post but I need some help because I > >need to compute patch and class metrics and the SDMTools package failed in > >the installation. Does anyone know how to install it? Is there any > >alternative? > >thanks in advance > > > >Juan > > > >> install.packages('SDMTools',,'http://www.rforge.net/') > >Error in install.packages : argument is missing, with no default > >> library(SDMTools) > >Error: package ?SDMTools? was built before R 3.0.0: please re-install it > >> library("SDMTools", lib.loc="C:/Program Files/R/R-3.1.3/library") > >Error: package ?SDMTools? was built before R 3.0.0: please re-install it > >> install.packages("C:/Program Files/R/SDMTools_1.1-14.zip", repos = NULL) > >package ?SDMTools? successfully unpacked and MD5 sums checked > >Warning messages: > >1: display list redraw incomplete > >2: display list redraw incomplete > >> library(SDMTools) > >Error: package ?SDMTools? was built before R 3.0.0: please re-install it > > > > [[alternative HTML version deleted]] > > > >_______________________________________________ > >R-sig-Geo mailing list > >R-sig-Geo at r-project.org > >https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > [[alternative HTML version deleted]] From sa12372 at bristol.ac.uk Fri Sep 18 12:08:34 2015 From: sa12372 at bristol.ac.uk (Sherien Al-Azerji) Date: Fri, 18 Sep 2015 11:08:34 +0100 Subject: [R-sig-Geo] LDL factor error message Message-ID: Dear All, I'm using Gstat exactly I'm using Universal Kriging to interpolate between two data (radar rainfall and rain gauge data) and I'm running the code for a long time series (1012 days), however the code keep stopping a lot of times and give me this error message (LDL factor) , what does that mean? and how can I solve the problem? Best Regards Sherien [[alternative HTML version deleted]] From tiago.castro.icmbio at gmail.com Fri Sep 18 15:20:09 2015 From: tiago.castro.icmbio at gmail.com (Tiago Castro Silva) Date: Fri, 18 Sep 2015 10:20:09 -0300 Subject: [R-sig-Geo] Rasterize SpatialPolygons in R is ignoring small values Message-ID: I'm trying to convert a polygon shapefile with small values. Values from the colunm propEmp range from 0.000002 to 0.119419. This is my attempt: # Load shapefile emp_planejado <- shapefile("./planejado/7_wgs/emp_planejado.shp") # Load raster model r_bioma<- raster("./_GRID/grid_caatinga_disol_64bit.tif") # List values from tipologia field tipologia<-unique(emp_planejado$tipologia) for (tp in tipologia){# Select features for each value in tipologia tipo<- emp_planejado[emp_planejado$tipologia==tp,] # Rasterize r_pol <- rasterize(tipo,r_bioma,field="propEmp",background=NA,mask=F) # Merge raster_merge <- merge(r_pol,r_bioma) # Save raster writeRaster(raster_merge,filename= paste0("./planejado/8_raster/",tp,"_planejado"),format="GTiff",NAflag=-9999,overwrite=TRUE) } r_bioma is a 64bit with double precision raster with all pixel values equal to 0. There is no overlap between features of this polygon, just boundary touching, so I did not use funas an argument of rasterize. After rasterize, when I check the minValue and maxValue from r_pol, instead of getting 0.000002 and 0.119419, I get 0.08687903 and 0.1140689. I don't know where the problem is. Could you help me? Thanks for your attention. Tiago [[alternative HTML version deleted]] From thierry.onkelinx at inbo.be Fri Sep 18 15:32:33 2015 From: thierry.onkelinx at inbo.be (Thierry Onkelinx) Date: Fri, 18 Sep 2015 15:32:33 +0200 Subject: [R-sig-Geo] Rasterize SpatialPolygons in R is ignoring small values In-Reply-To: References: Message-ID: Please don't post in HTML and don't cross post (http://stackoverflow.com/questions/32652814/rasterize-spatialpolygons-in-r-is-ignoring-small-values). ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2015-09-18 15:20 GMT+02:00 Tiago Castro Silva : > I'm trying to convert a polygon shapefile with small values. Values from > the colunm propEmp range from 0.000002 to 0.119419. This is my attempt: > > # Load shapefile > emp_planejado <- shapefile("./planejado/7_wgs/emp_planejado.shp") > # Load raster model > r_bioma<- raster("./_GRID/grid_caatinga_disol_64bit.tif") > # List values from tipologia field > tipologia<-unique(emp_planejado$tipologia) > > for (tp in tipologia){# Select features for each value in tipologia > tipo<- emp_planejado[emp_planejado$tipologia==tp,] > # Rasterize > r_pol <- rasterize(tipo,r_bioma,field="propEmp",background=NA,mask=F) > # Merge > raster_merge <- merge(r_pol,r_bioma) > # Save raster > writeRaster(raster_merge,filename= > paste0("./planejado/8_raster/",tp,"_planejado"),format="GTiff",NAflag=-9999,overwrite=TRUE) > } > > r_bioma is a 64bit with double precision raster with all pixel values equal > to 0. > > There is no overlap between features of this polygon, just boundary > touching, so I did not use funas an argument of rasterize. > > After rasterize, when I check the minValue and maxValue from r_pol, instead > of getting 0.000002 and 0.119419, I get 0.08687903 and 0.1140689. > > I don't know where the problem is. Could you help me? > > Thanks for your attention. > > Tiago > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From aolinto.lst at gmail.com Fri Sep 18 15:39:53 2015 From: aolinto.lst at gmail.com (Antonio Silva) Date: Fri, 18 Sep 2015 10:39:53 -0300 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R Message-ID: Dear R-Sig-Geo fellows This is my first post to this list. My name is Antonio Olinto and I work as researcher at Fisheries Institute, S?o Paulo, Brazil. Well, I'd like to hear suggestions on how to proceed in R to extract sea surface temperature and chlorophyll concentration data and calculate some statistics from MODIS/AQUA data in a given area. I used to do this in QGIS but available statistical parameters are limited and I had to work with one image at a time. I found a reference to a package named satin ( https://www.r-project.org/conferences/useR-2009/slides/Villalobos+GonzalezRodriguez.pdf) but it seems it's not available anymore. I have several *.L3m_MO_SST_4.bz2 and *.L3m_MO_CHL_chlor_a_4km.bz2 files obtained from http://podaac.jpl.nasa.gov/dataset/MODIS_AQUA_L3_SST_THERMAL_MONTHLY_4KM_DAYTIME and from http://oceandata.sci.gsfc.nasa.gov/MODISA/Mapped/Monthly/4km/chlor/ I also have a shapefile with the boundaries of the area of interest. I'd like to have some statistics (maximum, minimum, mean, quantiles, ect.) of both variables in this area. Any indication of tutorials, sites or packages will be welcome. Thanks in advance. All the best, Ant?nio Olinto [[alternative HTML version deleted]] From btupper at bigelow.org Fri Sep 18 16:08:36 2015 From: btupper at bigelow.org (Ben Tupper) Date: Fri, 18 Sep 2015 10:08:36 -0400 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R In-Reply-To: References: Message-ID: Hi, On Sep 18, 2015, at 9:39 AM, Antonio Silva wrote: > Dear R-Sig-Geo fellows > > > This is my first post to this list. My name is Antonio Olinto and I work as > researcher at Fisheries Institute, S?o Paulo, Brazil. > > > Well, I'd like to hear suggestions on how to proceed in R to extract sea > surface temperature and chlorophyll concentration data and calculate some > statistics from MODIS/AQUA data in a given area. > > > I used to do this in QGIS but available statistical parameters are limited > and I had to work with one image at a time. I found a reference to a > package named satin ( > https://www.r-project.org/conferences/useR-2009/slides/Villalobos+GonzalezRodriguez.pdf) > but it seems it's not available anymore. > > > I have several *.L3m_MO_SST_4.bz2 and *.L3m_MO_CHL_chlor_a_4km.bz2 files > obtained from > http://podaac.jpl.nasa.gov/dataset/MODIS_AQUA_L3_SST_THERMAL_MONTHLY_4KM_DAYTIME > and from http://oceandata.sci.gsfc.nasa.gov/MODISA/Mapped/Monthly/4km/chlor/ > > > I also have a shapefile with the boundaries of the area of interest. I'd > like to have some statistics (maximum, minimum, mean, quantiles, ect.) of > both variables in this area. > > > Any indication of tutorials, sites or packages will be welcome. Thanks in > advance. > > You might give this package a try: https://github.com/btupper/spnc It's essentially a wrapper around ncdf4, sp and raster and we have it configured for a couple of different data sources including Ocean Color's new netcdf files. It won't handle the .bz2 files though, just the .nc. It is very much in it's "beta" stage, but it works well for us. If it works for you, you can also try https://github.com/btupper/obpgcrawler to simplify downloads from the Ocean Color resources using their THREDDS framework. Cheers, Ben > All the best, > > Ant?nio Olinto > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org From mdsumner at gmail.com Fri Sep 18 16:23:04 2015 From: mdsumner at gmail.com (Michael Sumner) Date: Sat, 19 Sep 2015 00:23:04 +1000 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R In-Reply-To: References: Message-ID: The crux is hdf4, the format once you bunzip2 these files, and while geo metadata is unstandard the L3m variants are trivially longlat complete global grids on Atlantic view. Raster/rgdal makes it easy though manual and installing hdf4 for GDAL is easy on ubuntu, but non existent for R on windows, due to zlib license I believe. It sucks, and be apprised NASA is moving to Netcdf4 just to complicate life further. L3m is simplish relatively in the new regime, but on windows you must compile for yourself. M On Friday, September 18, 2015, Antonio Silva wrote: > Dear R-Sig-Geo fellows > > > This is my first post to this list. My name is Antonio Olinto and I work as > researcher at Fisheries Institute, S?o Paulo, Brazil. > > > Well, I'd like to hear suggestions on how to proceed in R to extract sea > surface temperature and chlorophyll concentration data and calculate some > statistics from MODIS/AQUA data in a given area. > > > I used to do this in QGIS but available statistical parameters are limited > and I had to work with one image at a time. I found a reference to a > package named satin ( > https://www.r-project.org/conferences/useR-2009/slides/Villalobos+GonzalezRodriguez.pdf ) > but it seems it's not available anymore. > > > I have several *.L3m_MO_SST_4.bz2 and *.L3m_MO_CHL_chlor_a_4km.bz2 files > obtained from > http://podaac.jpl.nasa.gov/dataset/MODIS_AQUA_L3_SST_THERMAL_MONTHLY_4KM_DAYTIME > and from http://oceandata.sci.gsfc.nasa.gov/MODISA/Mapped/Monthly/4km/chlor/ > > > I also have a shapefile with the boundaries of the area of interest. I'd > like to have some statistics (maximum, minimum, mean, quantiles, ect.) of > both variables in this area. > > > Any indication of tutorials, sites or packages will be welcome. Thanks in > advance. > > > All the best, > > Ant?nio Olinto > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Michael Sumner Software and Database Engineer Australian Antarctic Division Hobart, Australia e-mail: mdsumner at gmail.com [[alternative HTML version deleted]] From edzer.pebesma at uni-muenster.de Fri Sep 18 18:10:47 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 18 Sep 2015 18:10:47 +0200 Subject: [R-sig-Geo] LDL factor error message In-Reply-To: References: Message-ID: <55FC3787.2040509@uni-muenster.de> Please search the archives of this list before you ask; I googled for ldlfactor site:stat.ethz.ch and it gave me lots of hits that should help you forward. On 09/18/2015 12:08 PM, Sherien Al-Azerji wrote: > Dear All, > > I'm using Gstat exactly I'm using Universal Kriging to interpolate between > two data (radar rainfall and rain gauge data) and I'm running the code for > a long time series (1012 days), however the code keep stopping a lot of > times and give me this error message (LDL factor) , what does that mean? > and how can I solve the problem? > > Best Regards > Sherien > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From monika.novac at gmail.com Sat Sep 19 22:17:39 2015 From: monika.novac at gmail.com (monika nov) Date: Sat, 19 Sep 2015 21:17:39 +0100 Subject: [R-sig-Geo] Function stslshac {sphet}: heteroskedasticity and autocorrelation consistent (HAC) estimator Message-ID: Dear R-users, I have quite basic question for econometricians, however I would like to be sure in this. If I use a HAC estimator of the variance-covariance (VC) matrix for a spatial econometric model, do I still need to test the residuals for spatial autocorrelation and heteroscedasticity? (in particular I am using function stslshac available in package sphet. The estimator is based on Kelejian, H.H. and Prucha, I.R. (2007) HAC estimation in a spatial framework, Journal of Econometrics, 140, pages 131?154). What if the residuals from model estimated by stslshac are spatially autocorrelated and (or) heteroscedastic? Can I still use this estimator with HAC estimate of VC matrix or shall I go for different estimator or specification? Do the estimates have required properties (are they unbiased, consistent, efficient)? I would be grateful for any reaction. From edaner_92 at hotmail.com Sun Sep 20 00:24:10 2015 From: edaner_92 at hotmail.com (DANER CASTRO VANEGAS) Date: Sat, 19 Sep 2015 17:24:10 -0500 Subject: [R-sig-Geo] cellular automata and Markov chains in raster images Message-ID: Hello, anyone has used a model of cellular automata and Markov chains in raster images using R, for projecting land cover, similar to the one implemented in IDRISI with the module (CA-Markov)?, If so them appreciate that packages use and functions.Thank you. [[alternative HTML version deleted]] From r.hijmans at gmail.com Sun Sep 20 03:15:43 2015 From: r.hijmans at gmail.com (Robert J. Hijmans) Date: Sat, 19 Sep 2015 18:15:43 -0700 Subject: [R-sig-Geo] Conditional operations and rasters In-Reply-To: References: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> Message-ID: You can also try this: f <- function(lai) { emiss_0 <- 0.95 + (0.01 * lai) emiss_nb <- 0.97 + (0.0033 * lai) i <- lai >= 1000 emiss_0[i] <- 0.95 emiss_nb[i] <- 0.98 cbind(emiss_0, emiss_nb) } library(raster) rlai <- raster(ncols=360, nrows=180) rlai[] <- 1:ncell(rlai) x <- calc(rlai, f) x On Tue, Sep 15, 2015 at 8:47 PM, Andrew Vitale wrote: > I would do something like the following: > > library(raster) > > lai <- raster(ncols=50, nrows=50) > lai[] <- 1:ncell(lai) > > emmiss_0_func <- function(lai) { > emmiss_0 <- ifelse((lai < 1000), (0.95 + (0.01 * lai)), 0.95) > return(emmiss_0) > } > emmiss_nb_func <- function(lai) { > emmiss_nb <- ifelse((lai < 1000), (0.97 + (0.0033 * lai)), 0.98) > return(emmiss_nb) > } > > emiss <- stack(calc(lai, emmiss_0_func), calc(lai, emmiss_nb_func)) > plot(emiss) > > > On Tue, Sep 15, 2015 at 8:30 PM, Vijay Lulla wrote: > >> I have no idea what you're trying to accomplish with your program >> logic but I think the below might work for you. >> >> R> lai <- raster(ncols=360,nros=180) >> R> lai[] <- 1:ncell(lai) >> >> R> idx <- lai < 1000 >> R> emiss_0 <- lai >> R> emiss_0[] <- 0.95 >> R> emiss_0[idx] <- 0.95 + (lai[idx]*0.01) >> >> R> emiss_nb <- lai >> R> emiss_nb[] <- 0.98 >> R> emiss_nb[!idx] <- 0.97+(lai[!idx]*0.0033) >> R> ?Which # from raster package >> >> Other gurus on the list might suggest more efficient way[s] of doing this. >> >> HTH, >> Vijay. >> >> On Tue, Sep 15, 2015 at 10:51 PM, Thiago V. dos Santos >> wrote: >> > Hi all, >> > >> > This is probably a silly question, but I could not find an appropriate >> answer somewhere else. >> > >> > I am trying create a raster based on conditional statements applied on >> an original raster. >> > >> > This is some sample code: >> > >> > lai <- raster(ncols=360, nrows=180) >> > lai[] <- 1:ncell(lai) >> > >> > if (lai < 1000) { >> > >> > emiss_0 <- 0.95 + (0.01 * lai) >> > emiss_nb <- 0.97 + (0.0033 * lai) >> > >> > >> > } else if (lai >= 1000) { >> > >> > >> > emiss_0 <- 0.95 >> > emiss_nb <- 0.98 >> > >> > >> > } >> > >> > Error in if (lai < 3) { : argument is not interpretable as logical >> > >> > >> > What would be the right way to do that? >> > Greetings, >> > -- Thiago V. dos Santos >> > >> > PhD student >> > Land and Atmospheric Science >> > University of Minnesota >> > >> > _______________________________________________ >> > R-sig-Geo mailing list >> > R-sig-Geo at r-project.org >> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > > > -- > *Andrew P. Vitale* > Staff Research Scientist > Desert Research Institute > 2215 Raggio Pkwy > Reno, NV 89512 > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From aolinto.lst at gmail.com Sun Sep 20 15:18:21 2015 From: aolinto.lst at gmail.com (Antonio Silva) Date: Sun, 20 Sep 2015 10:18:21 -0300 Subject: [R-sig-Geo] gdal_translate and gdalwarp question Message-ID: Hello, I have some doubts on the usage of some gdal tools. After converting a hdf file to tif I want to reproject to SIRGAS2000 and clip between lats of 22 to 29 S and lats of 40 to 50 W. HDF file can be downloaded at https://app.box.com/s/16cf7qv6af6gsz1v66staori2mtneu0r Basically I'm following https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ Well to convert HDF file I'm using: gdal_translate("A20080012008031.L3m_MO_SST_4","georef.tif",sd_index=1,a_ullr=c(0,4320,8640,0), a_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 +b=6371007 +units=m +no_defs") Without a_ullr and a_srs options I was getting an error message when using gdalwarp: "ERROR 1: Unable to compute a transformation between pixel/line and georeferenced coordinates" a_ullr and a_srs values I got with GDALinfo("georef.tif") map <- raster("georef.tif") plot(map) My problem now is reproject to SIRGAS2000 and clip the image georef.tif: gdalwarp("georef.tif", "georef2.tif", s_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 +b=6371007 +units=m +no_defs", t_srs="+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs") map2 <- raster("georef2.tif") plot(map2) Map2 is not in SIRGAS2000 projection and clipping option te=c(-50,-29,-40,-22) does not work. Where is my mistake? I hope someone can tell me. Thanks for any help. Antonio Olinto -- Ant?nio Olinto ?vila da Silva Bi?logo / Ocean?grafo Instituto de Pesca (Fisheries Institute) S?o Paulo, Brasil [[alternative HTML version deleted]] From alobolistas at gmail.com Mon Sep 21 10:05:13 2015 From: alobolistas at gmail.com (Agustin Lobo) Date: Mon, 21 Sep 2015 10:05:13 +0200 Subject: [R-sig-Geo] plot extent and/or convert extent to SpatialPolygons Message-ID: Is it possible to plot an extent object (i.e. on top of a raster like it would be done for a polygon with add=TRUE) Or can I just convert the extent object to SpatialPolygons? Thanks Agus From manuel.schneider at agroscope.admin.ch Mon Sep 21 10:29:15 2015 From: manuel.schneider at agroscope.admin.ch (Manuel Schneider) Date: Mon, 21 Sep 2015 08:29:15 +0000 Subject: [R-sig-Geo] plot extent and/or convert extent to SpatialPolygons References: Message-ID: Agustin Lobo gmail.com> writes: > > Is it possible to plot an extent object (i.e. on top of a raster like > it would be done for a polygon with add=TRUE) > Or can I just convert the extent object to SpatialPolygons? > > Thanks > Agus > Try bbox2square <- function(bb) { coord.mat <- data.frame(x=rep(bb[1,],each=2),y=c(bb[2,],bb[2,2:1])) coord.mat <- rbind(coord.mat, coord.mat[1,]) sq <- SpatialPolygons(list(Polygons(list(Polygon(coord.mat)), ID = 1))) return(as(sq, "SpatialPolygonsDataFrame")) } where bb <- bbox(obj) From johnbaums at gmail.com Mon Sep 21 10:31:33 2015 From: johnbaums at gmail.com (John Baumgartner) Date: Mon, 21 Sep 2015 18:31:33 +1000 Subject: [R-sig-Geo] plot extent and/or convert extent to SpatialPolygons In-Reply-To: References: Message-ID: I just realised my reply only went to Agustin - here it is again... You can convert extent e to SpatialPolygons with as(e, 'SpatialPolygons') ... but yes, you can also plot the extent object with plot. e.g. r <- raster(matrix(runif(100), nc=10)) plot(r) e <- extent(0.5, 0.75, 0.5, 0.75) plot(e, add=TRUE) On Mon, Sep 21, 2015 at 6:29 PM, Manuel Schneider < manuel.schneider at agroscope.admin.ch> wrote: > Agustin Lobo gmail.com> writes: > > > > > Is it possible to plot an extent object (i.e. on top of a raster like > > it would be done for a polygon with add=TRUE) > > Or can I just convert the extent object to SpatialPolygons? > > > > Thanks > > Agus > > > > Try > > bbox2square <- function(bb) > { > coord.mat <- data.frame(x=rep(bb[1,],each=2),y=c(bb[2,],bb[2,2:1])) > coord.mat <- rbind(coord.mat, coord.mat[1,]) > sq <- SpatialPolygons(list(Polygons(list(Polygon(coord.mat)), ID = > 1))) > return(as(sq, "SpatialPolygonsDataFrame")) > } > > where bb <- bbox(obj) > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] From alobolistas at gmail.com Mon Sep 21 10:38:45 2015 From: alobolistas at gmail.com (Agustin Lobo) Date: Mon, 21 Sep 2015 10:38:45 +0200 Subject: [R-sig-Geo] plot extent and/or convert extent to SpatialPolygons In-Reply-To: References: Message-ID: Apologies. I had done ext128 <- c(128,1280-128,128,960-128) instead of ext128 <- extent(c(128,1280-128,128,960-128)) This is why plot() and as() were not working for me. Agus On Mon, Sep 21, 2015 at 10:31 AM, John Baumgartner wrote: > I just realised my reply only went to Agustin - here it is again... > > You can convert extent e to SpatialPolygons with > > as(e, 'SpatialPolygons') > > ... but yes, you can also plot the extent object with plot. > > e.g. > > r <- raster(matrix(runif(100), nc=10)) > plot(r) > e <- extent(0.5, 0.75, 0.5, 0.75) > plot(e, add=TRUE) > > On Mon, Sep 21, 2015 at 6:29 PM, Manuel Schneider < > manuel.schneider at agroscope.admin.ch> wrote: > >> Agustin Lobo gmail.com> writes: >> >> > >> > Is it possible to plot an extent object (i.e. on top of a raster like >> > it would be done for a polygon with add=TRUE) >> > Or can I just convert the extent object to SpatialPolygons? >> > >> > Thanks >> > Agus >> > >> >> Try >> >> bbox2square <- function(bb) >> { >> coord.mat <- data.frame(x=rep(bb[1,],each=2),y=c(bb[2,],bb[2,2:1])) >> coord.mat <- rbind(coord.mat, coord.mat[1,]) >> sq <- SpatialPolygons(list(Polygons(list(Polygon(coord.mat)), ID = >> 1))) >> return(as(sq, "SpatialPolygonsDataFrame")) >> } >> >> where bb <- bbox(obj) >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From Roger.Bivand at nhh.no Mon Sep 21 18:04:19 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Mon, 21 Sep 2015 18:04:19 +0200 Subject: [R-sig-Geo] Function stslshac {sphet}: heteroskedasticity and autocorrelation consistent (HAC) estimator In-Reply-To: References: Message-ID: On Sat, 19 Sep 2015, monika nov wrote: > Dear R-users, > > I have quite basic question for econometricians, however I would like > to be sure in this. > > If I use a HAC estimator of the variance-covariance (VC) matrix for a > spatial econometric model, do I still need to test the residuals for > spatial autocorrelation and heteroscedasticity? (in particular I am > using function stslshac available in package sphet. The estimator is > based on Kelejian, H.H. and Prucha, I.R. (2007) HAC estimation in a > spatial framework, Journal of Econometrics, 140, pages 131?154). > > What if the residuals from model estimated by stslshac are spatially > autocorrelated and (or) heteroscedastic? Can I still use this > estimator with HAC estimate of VC matrix or shall I go for different > estimator or specification? Do the estimates have required properties > (are they unbiased, consistent, efficient)? I would be grateful for > any reaction. Does this reference throw any light on the question? I'm not aware of implementations: @article{ year={2015}, issn={1864-4031}, journal={Letters in Spatial and Resource Sciences}, doi={10.1007/s12076-015-0146-2}, title={Critical issues in spatial models: error term specifications, additional endogenous variables, pre-testing, and Bayesian analysis}, url={http://dx.doi.org/10.1007/s12076-015-0146-2}, publisher={Springer Berlin Heidelberg}, keywords={Specifications of spatial models; Additional endogenous variables; Pre-testing; Bayesian analysis; C01; C12; C13}, author={Kelejian, HarryH.}, pages={1-24}, language={English} } Roger > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From venek at gmx.at Tue Sep 22 07:55:28 2015 From: venek at gmx.at (Vv) Date: Tue, 22 Sep 2015 07:55:28 +0200 Subject: [R-sig-Geo] adehabitatHR: grid cell size Message-ID: An HTML attachment was scrubbed... URL: From venek at gmx.at Tue Sep 22 07:55:51 2015 From: venek at gmx.at (Vv) Date: Tue, 22 Sep 2015 07:55:51 +0200 Subject: [R-sig-Geo] adehabitatHR vs. BBMM: utilization distribution Message-ID: An HTML attachment was scrubbed... URL: From venek at gmx.at Tue Sep 22 07:56:51 2015 From: venek at gmx.at (Vv) Date: Tue, 22 Sep 2015 07:56:51 +0200 Subject: [R-sig-Geo] adehabitatHR vs. BBMM: utilization distribution Message-ID: An HTML attachment was scrubbed... URL: From richjh1916 at yahoo.com Tue Sep 22 12:53:47 2015 From: richjh1916 at yahoo.com (richard hewitt) Date: Tue, 22 Sep 2015 10:53:47 +0000 (UTC) Subject: [R-sig-Geo] cellular automata and Markov chains in raster images In-Reply-To: References: Message-ID: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> Hi Daner,We've recently been working on implementing a cellular automata model in R for projecting land use and land cover change. It's not the same as the IDRISI implementation and it doesn't use Markov chains. Rather, it's based on White and Engelen's (1993) classic CA model which I think does a better job than IDRISI (the commercial implementation of this is known as Metronamica). The single land use category version of our model we called SIMLANDER, the new version which works for multiple land uses (much more useful) is called APoLUS. You can find both, as well as some documentation at the website:SIMLANDERIf it is useful in any way, we'd be very keen to have your feedback.Best,Richard | ? | | ? | | ? | ? | ? | ? | ? | | SIMLANDERa cellular automata land use model for the R software environment | | | | Ver en simlander.wordpress... | Vista previa por Yahoo | | | | ? | ? De: DANER CASTRO VANEGAS Para: "r-sig-geo at r-project.org" Enviado: Domingo 20 de septiembre de 2015 0:24 Asunto: [R-sig-Geo] cellular automata and Markov chains in raster images Hello, anyone has used a model of cellular automata and Markov chains in raster images using R, for projecting land cover, similar to the one implemented in IDRISI with the module (CA-Markov)?, If so them appreciate that packages use and functions.Thank you. ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From richjh1916 at yahoo.com Tue Sep 22 13:10:15 2015 From: richjh1916 at yahoo.com (richard hewitt) Date: Tue, 22 Sep 2015 11:10:15 +0000 (UTC) Subject: [R-sig-Geo] cellular automata and Markov chains in raster images In-Reply-To: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> References: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> Message-ID: <472228877.2069153.1442920215092.JavaMail.yahoo@mail.yahoo.com> Hello again Daner, something went wrong with the link I tried to include. Its: https://simlander.wordpress.com/ bestRichard De: richard hewitt via R-sig-Geo Para: DANER CASTRO VANEGAS ; "r-sig-geo at r-project.org" Enviado: Martes 22 de septiembre de 2015 12:53 Asunto: Re: [R-sig-Geo] cellular automata and Markov chains in raster images Hi Daner,We've recently been working on implementing a cellular automata model in R for projecting land use and land cover change. It's not the same as the IDRISI implementation and it doesn't use Markov chains. Rather, it's based on White and Engelen's (1993) classic CA model which I think does a better job than IDRISI (the commercial implementation of this is known as Metronamica). The single land use category version of our model we called SIMLANDER, the new version which works for multiple land uses (much more useful) is called APoLUS. You can find both, as well as some documentation at the website:SIMLANDERIf it is useful in any way, we'd be very keen to have your feedback.Best,Richard | ? | | ? |? | ? | ? | ? | ? | ? | | SIMLANDERa cellular automata land use model for the R software environment | |? | | Ver en simlander.wordpress... | Vista previa por Yahoo | |? | | ? | ? ? ? ? De: DANER CASTRO VANEGAS Para: "r-sig-geo at r-project.org" Enviado: Domingo 20 de septiembre de 2015 0:24 Asunto: [R-sig-Geo] cellular automata and Markov chains in raster images ? Hello, anyone has used a model of cellular automata and Markov chains in raster images using R, for projecting land cover, similar to the one implemented in IDRISI with the module (CA-Markov)?, If so them appreciate that packages use and functions.Thank you. ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo ? ??? [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From Roger.Bivand at nhh.no Tue Sep 22 15:51:23 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Tue, 22 Sep 2015 15:51:23 +0200 Subject: [R-sig-Geo] gdal_translate and gdalwarp question In-Reply-To: References: Message-ID: You posted the same message to R-help at Sun Sep 20 16:52:07 CEST 2015, so less than two hours after this post, cross-posting is bad anyway, and for such a specialised question, you should never expect immediate response. You do not state that this concerns the gdalUtils package, nor what version you are using on what platform. Can you simply use the GDAl command line utility until you figure out what you are doing wrong? Roger On Sun, 20 Sep 2015, Antonio Silva wrote: > Hello, > > I have some doubts on the usage of some gdal tools. > > After converting a hdf file to tif I want to reproject to SIRGAS2000 and > clip between lats of 22 to 29 S and lats of 40 to 50 W. > > HDF file can be downloaded at > https://app.box.com/s/16cf7qv6af6gsz1v66staori2mtneu0r > > Basically I'm following > https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ > > Well to convert HDF file I'm using: > > gdal_translate("A20080012008031.L3m_MO_SST_4","georef.tif",sd_index=1,a_ullr=c(0,4320,8640,0), > a_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 > +b=6371007 +units=m +no_defs") > > Without a_ullr and a_srs options I was getting an error message when using > gdalwarp: "ERROR 1: Unable to compute a transformation between pixel/line > and georeferenced coordinates" > > a_ullr and a_srs values I got with GDALinfo("georef.tif") > > map <- raster("georef.tif") > plot(map) > > My problem now is reproject to SIRGAS2000 and clip the image georef.tif: > > gdalwarp("georef.tif", "georef2.tif", > s_srs="+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 > +b=6371007 +units=m +no_defs", > t_srs="+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs") > > map2 <- raster("georef2.tif") > plot(map2) > > Map2 is not in SIRGAS2000 projection and clipping option > te=c(-50,-29,-40,-22) does not work. > > Where is my mistake? I hope someone can tell me. > > Thanks for any help. > > Antonio Olinto > > > > > > > > > > > > > > > > > > > > -- > Ant?nio Olinto ?vila da Silva > Bi?logo / Ocean?grafo > Instituto de Pesca (Fisheries Institute) > S?o Paulo, Brasil > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From Frederic.Pons at cerema.fr Tue Sep 22 16:25:53 2015 From: Frederic.Pons at cerema.fr (PONS Frederic - CEREMA/DTerMed/DREC/SRILH) Date: Tue, 22 Sep 2015 16:25:53 +0200 Subject: [R-sig-Geo] Problem in EPSG 2154 => 102110 In-Reply-To: <472228877.2069153.1442920215092.JavaMail.yahoo@mail.yahoo.com> References: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> <472228877.2069153.1442920215092.JavaMail.yahoo@mail.yahoo.com> Message-ID: <560164F1.8090002@cerema.fr> Dear R-users, I have a problem when I create a spatialpolygondataframe I want to have an EPSG 2154 but after the export the epsg is 102110. It seems to be the "same" CRS but it is not what I want. A small example to help me Best regards xlla=700000 ylla=6500000 ncolsa=1000 nrowsa=1000 cellsizea=1 tableau <- data.frame(IDENT = 1, ncols = 1000, row.names = 1) crds <- cbind(x=c(xlla,xlla+ncolsa*cellsizea, xlla+ncolsa*cellsizea, xlla, xlla), y=c(ylla, ylla, ylla+nrowsa*cellsizea, ylla+nrowsa*cellsizea, ylla)) Pa <- Polygon (crds) Psa <- Polygons (list ( Pa ), 1) pola <- SpatialPolygons (list ( Psa ), proj4string=CRS("+init=epsg:2154")) SPDFa <- SpatialPolygonsDataFrame(pola, tableau) writeOGR(SPDFa, dsn="C:\\ajeter",layer="toto",driver="ESRI Shapefile",overwrite_layer=TRUE) *Fr?d?ric Pons * *Expert hydraulique sur les inondations et al?as c?tiers **DREC/Service Risques Inondations Littoraux et Hydraulique **- T?l.: (33)4 42 24 76 68 * *Direction Territoriale M?diterran?e * Centre d??tudes et d?expertise sur les risques, l?environnement, la mobilit? et l?am?nagement www.cerema.fr -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: cerema.png Type: image/png Size: 6094 bytes Desc: not available URL: From HodgessE at uhd.edu Tue Sep 22 16:44:18 2015 From: HodgessE at uhd.edu (Hodgess, Erin) Date: Tue, 22 Sep 2015 14:44:18 +0000 Subject: [R-sig-Geo] Problem in EPSG 2154 => 102110 In-Reply-To: <560164F1.8090002@cerema.fr> References: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> <472228877.2069153.1442920215092.JavaMail.yahoo@mail.yahoo.com>, <560164F1.8090002@cerema.fr> Message-ID: Hello! I ran through your example, and brought the OGR file back into R via the readOGR function. > xxx <- readOGR(dsn="C:\\ajeter",layer="toto") OGR data source with driver: ESRI Shapefile Source: "C:\ajeter", layer: "toto" with 1 features It has 2 fields > str(xxx) Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots ..@ data :'data.frame': 1 obs. of 2 variables: .. ..$ IDENT: num 1 .. ..$ ncols: num 1000 ..@ polygons :List of 1 .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots .. .. .. ..@ Polygons :List of 1 .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots .. .. .. .. .. .. ..@ labpt : num [1:2] 700500 6500500 .. .. .. .. .. .. ..@ area : num 1e+06 .. .. .. .. .. .. ..@ hole : logi FALSE .. .. .. .. .. .. ..@ ringDir: int 1 .. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 700000 700000 701000 701000 700000 ... .. .. .. ..@ plotOrder: int 1 .. .. .. ..@ labpt : num [1:2] 700500 6500500 .. .. .. ..@ ID : chr "0" .. .. .. ..@ area : num 1e+06 ..@ plotOrder : int 1 ..@ bbox : num [1:2, 1:2] 700000 6500000 701000 6501000 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "x" "y" .. .. ..$ : chr [1:2] "min" "max" ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot .. .. ..@ projargs: chr "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs" > If you put that big @projagrs into google.com, this is what you get: Proj4js.defs["EPSG:2154"] = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; Is that what you want, please? Thanks, Erin ________________________________ From: R-sig-Geo [r-sig-geo-bounces at r-project.org] on behalf of PONS Frederic - CEREMA/DTerMed/DREC/SRILH [Frederic.Pons at cerema.fr] Sent: Tuesday, September 22, 2015 9:25 AM To: r-sig-geo at r-project.org Subject: [R-sig-Geo] Problem in EPSG 2154 => 102110 Dear R-users, I have a problem when I create a spatialpolygondataframe I want to have an EPSG 2154 but after the export the epsg is 102110. It seems to be the "same" CRS but it is not what I want. A small example to help me Best regards xlla=700000 ylla=6500000 ncolsa=1000 nrowsa=1000 cellsizea=1 tableau <- data.frame(IDENT = 1, ncols = 1000, row.names = 1) crds <- cbind(x=c(xlla,xlla+ncolsa*cellsizea, xlla+ncolsa*cellsizea, xlla, xlla), y=c(ylla, ylla, ylla+nrowsa*cellsizea, ylla+nrowsa*cellsizea, ylla)) Pa <- Polygon (crds) Psa <- Polygons (list ( Pa ), 1) pola <- SpatialPolygons (list ( Psa ), proj4string=CRS("+init=epsg:2154")) SPDFa <- SpatialPolygonsDataFrame(pola, tableau) writeOGR(SPDFa, dsn="C:\\ajeter",layer="toto",driver="ESRI Shapefile",overwrite_layer=TRUE) Fr?d?ric Pons Expert hydraulique sur les inondations et al?as c?tiers DREC/Service Risques Inondations Littoraux et Hydraulique - T?l.: (33)4 42 24 76 68 Direction Territoriale M?diterran?e [cid:part1.04060105.02070900 at cerema.fr] Centre d??tudes et d?expertise sur les risques, l?environnement, la mobilit? et l?am?nagement www.cerema.fr -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: cerema.png Type: image/png Size: 6094 bytes Desc: cerema.png URL: From edaner_92 at hotmail.com Wed Sep 23 05:57:42 2015 From: edaner_92 at hotmail.com (DANER CASTRO VANEGAS) Date: Tue, 22 Sep 2015 22:57:42 -0500 Subject: [R-sig-Geo] cellular automata and Markov chains in raster images In-Reply-To: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> References: , <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> Message-ID: Hi Richard,Thank you very much for the contribution, I will try,, have had experience with IDRISI, but wanted to implement what they have done in R or free software. Date: Tue, 22 Sep 2015 10:53:47 +0000 From: richjh1916 at yahoo.com To: edaner_92 at hotmail.com; r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] cellular automata and Markov chains in raster images Hi Daner,We've recently been working on implementing a cellular automata model in R for projecting land use and land cover change. It's not the same as the IDRISI implementation and it doesn't use Markov chains. Rather, it's based on White and Engelen's (1993) classic CA model which I think does a better job than IDRISI (the commercial implementation of this is known as Metronamica). The single land use category version of our model we called SIMLANDER, the new version which works for multiple land uses (much more useful) is called APoLUS. You can find both, as well as some documentation at the website:SIMLANDERIf it is useful in any way, we'd be very keen to have your feedback.Best,Richard SIMLANDERa cellular automata land use model for the R software environmentVer en simlander.wordpress...Vista previa por Yahoo De: DANER CASTRO VANEGAS Para: "r-sig-geo at r-project.org" Enviado: Domingo 20 de septiembre de 2015 0:24 Asunto: [R-sig-Geo] cellular automata and Markov chains in raster images Hello, anyone has used a model of cellular automata and Markov chains in raster images using R, for projecting land cover, similar to the one implemented in IDRISI with the module (CA-Markov)?, If so them appreciate that packages use and functions.Thank you. [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo [[alternative HTML version deleted]] From thi_veloso at yahoo.com.br Wed Sep 23 06:36:59 2015 From: thi_veloso at yahoo.com.br (Thiago V. dos Santos) Date: Wed, 23 Sep 2015 04:36:59 +0000 (UTC) Subject: [R-sig-Geo] Conditional operations and rasters In-Reply-To: References: <490692155.145664.1442371890651.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1871475301.92631.1442983019044.JavaMail.yahoo@mail.yahoo.com> Thank you all for the suggestions, Robert, Andrew and Vijay. I am still examining all of them to see which one works best for me. Greetings, -- Thiago V. dos Santos PhD student Land and Atmospheric Science University of Minnesota On Saturday, September 19, 2015 8:15 PM, Robert J. Hijmans wrote: You can also try this: f <- function(lai) { emiss_0 <- 0.95 + (0.01 * lai) emiss_nb <- 0.97 + (0.0033 * lai) i <- lai >= 1000 emiss_0[i] <- 0.95 emiss_nb[i] <- 0.98 cbind(emiss_0, emiss_nb) } library(raster) rlai <- raster(ncols=360, nrows=180) rlai[] <- 1:ncell(rlai) x <- calc(rlai, f) x On Tue, Sep 15, 2015 at 8:47 PM, Andrew Vitale wrote: > I would do something like the following: > > library(raster) > > lai <- raster(ncols=50, nrows=50) > lai[] <- 1:ncell(lai) > > emmiss_0_func <- function(lai) { > emmiss_0 <- ifelse((lai < 1000), (0.95 + (0.01 * lai)), 0.95) > return(emmiss_0) > } > emmiss_nb_func <- function(lai) { > emmiss_nb <- ifelse((lai < 1000), (0.97 + (0.0033 * lai)), 0.98) > return(emmiss_nb) > } > > emiss <- stack(calc(lai, emmiss_0_func), calc(lai, emmiss_nb_func)) > plot(emiss) > > > On Tue, Sep 15, 2015 at 8:30 PM, Vijay Lulla wrote: > >> I have no idea what you're trying to accomplish with your program >> logic but I think the below might work for you. >> >> R> lai <- raster(ncols=360,nros=180) >> R> lai[] <- 1:ncell(lai) >> >> R> idx <- lai < 1000 >> R> emiss_0 <- lai >> R> emiss_0[] <- 0.95 >> R> emiss_0[idx] <- 0.95 + (lai[idx]*0.01) >> >> R> emiss_nb <- lai >> R> emiss_nb[] <- 0.98 >> R> emiss_nb[!idx] <- 0.97+(lai[!idx]*0.0033) >> R> ?Which # from raster package >> >> Other gurus on the list might suggest more efficient way[s] of doing this. >> >> HTH, >> Vijay. >> >> On Tue, Sep 15, 2015 at 10:51 PM, Thiago V. dos Santos >> wrote: >> > Hi all, >> > >> > This is probably a silly question, but I could not find an appropriate >> answer somewhere else. >> > >> > I am trying create a raster based on conditional statements applied on >> an original raster. >> > >> > This is some sample code: >> > >> > lai <- raster(ncols=360, nrows=180) >> > lai[] <- 1:ncell(lai) >> > >> > if (lai < 1000) { >> > >> > emiss_0 <- 0.95 + (0.01 * lai) >> > emiss_nb <- 0.97 + (0.0033 * lai) >> > >> > >> > } else if (lai >= 1000) { >> > >> > >> > emiss_0 <- 0.95 >> > emiss_nb <- 0.98 >> > >> > >> > } >> > >> > Error in if (lai < 3) { : argument is not interpretable as logical >> > >> > >> > What would be the right way to do that? >> > Greetings, >> > -- Thiago V. dos Santos >> > >> > PhD student >> > Land and Atmospheric Science >> > University of Minnesota >> > >> > _______________________________________________ >> > R-sig-Geo mailing list >> > R-sig-Geo at r-project.org >> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > > > -- > *Andrew P. Vitale* > Staff Research Scientist > Desert Research Institute > 2215 Raggio Pkwy > Reno, NV 89512 > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo From Frederic.Pons at cerema.fr Wed Sep 23 11:38:25 2015 From: Frederic.Pons at cerema.fr (PONS Frederic - CEREMA/DTerMed/DREC/SRILH) Date: Wed, 23 Sep 2015 11:38:25 +0200 Subject: [R-sig-Geo] Problem in EPSG 2154 => 102110 In-Reply-To: References: <1040320321.2068363.1442919227280.JavaMail.yahoo@mail.yahoo.com> <472228877.2069153.1442920215092.JavaMail.yahoo@mail.yahoo.com>, <560164F1.8090002@cerema.fr> Message-ID: <56027311.6030509@cerema.fr> Hello There is a very small change betwwen 2154 and 102110 +towgs84=0,0,0,0,0,0,0 If I use the small example: library(sp) library(rgdal) xlla=700000 ylla=6500000 ncolsa=1000 nrowsa=1000 cellsizea=1 tableau <- data.frame(IDENT = 1, ncols = 1000, row.names = 1) crds <- cbind(x=c(xlla,xlla+ncolsa*cellsizea, xlla+ncolsa*cellsizea, xlla, xlla), y=c(ylla, ylla, ylla+nrowsa*cellsizea, ylla+nrowsa*cellsizea, ylla)) Pa <- Polygon (crds) Psa <- Polygons (list ( Pa ), 1) pola <- SpatialPolygons (list ( Psa ), proj4string=CRS("+init=epsg:2154")) SPDFa <- SpatialPolygonsDataFrame(pola, tableau) print(SPDFa) writeOGR(SPDFa, dsn="C:\\ajeter",layer="toto",driver="ESRI Shapefile",overwrite_layer=TRUE) xxx <- readOGR(dsn="C:\\ajeter",layer="toto") print(xxx) For SPDFa: there is this projection: Slot "proj4string": CRS arguments: +init=epsg:2154 +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs And for xxx there is this projection: Slot "proj4string": CRS arguments: +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs I don't see the same argument in the CRS, and in 2154, there is this small part: +towgs84=0,0,0,0,0,0,0 I think there is no big problem of shift but when I create a file and I put it in other GIS (Qgis), it is not recognize as 2154. Last comment, with the shapefile, the prj don't give the same things betwwen 2154 and 102110 2154 PROJCS["Lambert_Conformal_Conic",GEOGCS["GCS_GRS 1980(IUGG, 1980)",DATUM["D_unknown",SPHEROID["GRS80",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["Meter",1]] 102110 PROJCS["RGF93_Lambert_93",GEOGCS["GCS_RGF93",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["Meter",1]] GCS_RGF93 don't appear in R! Thanks for your help Fr?d?ric *Fr?d?ric Pons * *Expert hydraulique sur les inondations et al?as c?tiers **DREC/Service Risques Inondations Littoraux et Hydraulique **- T?l.: (33)4 42 24 76 68 * *Direction Territoriale M?diterran?e * Centre d??tudes et d?expertise sur les risques, l?environnement, la mobilit? et l?am?nagement www.cerema.fr Le 22/09/2015 16:44, > Hodgess, Erin (par Internet) a ?crit : > Hello! > > I ran through your example, and brought the OGR file back into R via > the readOGR function. > > > xxx <- readOGR(dsn="C:\\ajeter",layer="toto") > OGR data source with driver: ESRI Shapefile > Source: "C:\ajeter", layer: "toto" > with 1 features > It has 2 fields > > str(xxx) > Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots > ..@ data :'data.frame': 1 obs. of 2 variables: > .. ..$ IDENT: num 1 > .. ..$ ncols: num 1000 > ..@ polygons :List of 1 > .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots > .. .. .. ..@ Polygons :List of 1 > .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots > .. .. .. .. .. .. ..@ labpt : num [1:2] 700500 6500500 > .. .. .. .. .. .. ..@ area : num 1e+06 > .. .. .. .. .. .. ..@ hole : logi FALSE > .. .. .. .. .. .. ..@ ringDir: int 1 > .. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 700000 700000 701000 > 701000 700000 ... > .. .. .. ..@ plotOrder: int 1 > .. .. .. ..@ labpt : num [1:2] 700500 6500500 > .. .. .. ..@ ID : chr "0" > .. .. .. ..@ area : num 1e+06 > ..@ plotOrder : int 1 > ..@ bbox : num [1:2, 1:2] 700000 6500000 701000 6501000 > .. ..- attr(*, "dimnames")=List of 2 > .. .. ..$ : chr [1:2] "x" "y" > .. .. ..$ : chr [1:2] "min" "max" > ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot > .. .. ..@ projargs: chr "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 > +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs" > > > If you put that big @projagrs into google.com, this is what you get: > Proj4js.defs["EPSG:2154"] = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"; > > Is that what you want, please? > > Thanks, > Erin > > > ------------------------------------------------------------------------ > *From:* R-sig-Geo [r-sig-geo-bounces at r-project.org] on behalf of PONS > Frederic - CEREMA/DTerMed/DREC/SRILH [Frederic.Pons at cerema.fr] > *Sent:* Tuesday, September 22, 2015 9:25 AM > *To:* r-sig-geo at r-project.org > *Subject:* [R-sig-Geo] Problem in EPSG 2154 => 102110 > > Dear R-users, > > I have a problem when I create a spatialpolygondataframe > > I want to have an EPSG 2154 but after the export the epsg is 102110. > > It seems to be the "same" CRS but it is not what I want. > > A small example to help me > Best regards > > xlla=700000 > ylla=6500000 > ncolsa=1000 > nrowsa=1000 > cellsizea=1 > > tableau <- data.frame(IDENT = 1, ncols = 1000, row.names = 1) > > crds <- cbind(x=c(xlla,xlla+ncolsa*cellsizea, xlla+ncolsa*cellsizea, > xlla, xlla), y=c(ylla, ylla, ylla+nrowsa*cellsizea, > ylla+nrowsa*cellsizea, ylla)) > > Pa <- Polygon (crds) > Psa <- Polygons (list ( Pa ), 1) > pola <- SpatialPolygons (list ( Psa ), proj4string=CRS("+init=epsg:2154")) > SPDFa <- SpatialPolygonsDataFrame(pola, tableau) > > writeOGR(SPDFa, dsn="C:\\ajeter",layer="toto",driver="ESRI > Shapefile",overwrite_layer=TRUE) > > *Fr?d?ric Pons * > *Expert hydraulique sur les inondations et al?as c?tiers > **DREC/Service Risques Inondations Littoraux et Hydraulique **- T?l.: > (33)4 42 24 76 68 * > *Direction Territoriale M?diterran?e > * > Centre d??tudes et d?expertise sur les risques, l?environnement, la > mobilit? et l?am?nagement > www.cerema.fr > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: cerema.png Type: image/png Size: 6094 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 6094 bytes Desc: not available URL: From gbl1 at hi.is Wed Sep 23 13:10:56 2015 From: gbl1 at hi.is (Gilles Benjamin Leduc) Date: Wed, 23 Sep 2015 11:10:56 +0000 Subject: [R-sig-Geo] New package: Linarius Message-ID: <2db8-56028900-ef-2c1dc480@149128861> Dear member of the list, I want to let you know about my R package: Linarius. available here: https://github.com/giby/Linarius It provides many feature I was in need of for my research. I have been recently working on documentation. I would appreciate some feed back, if some of you could proofread and test. It provide interesting features such as anamorphosis preparation and tripolar heat-maps. install: library(devtools) install_github("giby/Linarius") library(Linarius) Best regards Benjamin From dupouey at nancy.inra.fr Wed Sep 23 19:10:45 2015 From: dupouey at nancy.inra.fr (Jean-Luc Dupouey) Date: Wed, 23 Sep 2015 19:10:45 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" Message-ID: <5602DD15.8030109@nancy.inra.fr> Why gIntersection returns the ""TopologyException: no outgoing dirEdge found at" error in the following very simple case: > #construct a spatial layer with two adjacent squares, each of 10 x 10 units: > > Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) > Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) > > Pols1=Polygons(list(Polygon(Pol1)),"Pols1") > Pols2=Polygons(list(Polygon(Pol2)),"Pols2") > MyLay=SpatialPolygons(list(Pols1,Pols2)) > > #construct the same layer, but lagged by 0.5 in x and y directions > > Pol1l=Pol1+0.5 > Pol2l=Pol2+0.5 > > Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") > Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") > MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) > > #view the resulting spatial layers: > > plot(MyLay) > plot(MyLayl,add=TRUE) > > #try to intersect: > > inter=gIntersection(MyLay,MyLayl) Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, "rgeos_intersection") : TopologyException: no outgoing dirEdge found at 0.5 0 It works with the option byid=TRUE. But my question is why it does not work without? Is this behaviour predictable? I went through some previous related posts to the list, but could not find the answer. Thanks, -- Jean-Luc Dupouey INRA Forest Ecology & Ecophysiology Unit F-54280 Champenoux France mail: dupouey at nancy.inra.fr From Roger.Bivand at nhh.no Wed Sep 23 19:39:52 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Wed, 23 Sep 2015 19:39:52 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <5602DD15.8030109@nancy.inra.fr> References: <5602DD15.8030109@nancy.inra.fr> Message-ID: On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: > Why gIntersection returns the ""TopologyException: no outgoing dirEdge found > at" error in the following very simple case: > >> #construct a spatial layer with two adjacent squares, each of 10 x 10 > units: >> >> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >> >> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >> MyLay=SpatialPolygons(list(Pols1,Pols2)) >> >> #construct the same layer, but lagged by 0.5 in x and y directions >> >> Pol1l=Pol1+0.5 >> Pol2l=Pol2+0.5 >> >> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >> >> #view the resulting spatial layers: >> >> plot(MyLay) >> plot(MyLayl,add=TRUE) >> >> #try to intersect: >> >> inter=gIntersection(MyLay,MyLayl) > Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, > "rgeos_intersection") : > TopologyException: no outgoing dirEdge found at 0.5 0 The error message is coming from GEOS - you are welcome to investigate further. If you use gUnaryUnion() on the objects first, there is no error: library(rgeos) Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) library(sp) Pols1=Polygons(list(Polygon(Pol1)),"Pols1") Pols2=Polygons(list(Polygon(Pol2)),"Pols2") MyLay=SpatialPolygons(list(Pols1,Pols2)) Pol1l=Pol1+0.5 Pol2l=Pol2+0.5 Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) plot(MyLay) plot(MyLayl,add=TRUE) points(x=0.5, y=0) inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) plot(inter, add=TRUE, border="green") It is a GEOS issue, not rgeos. > > It works with the option byid=TRUE. > > But my question is why it does not work without? Is this behaviour > predictable? This is unknown. I'll try again on GEOS 3.5.0 and see if it is still there: yes, unfortunately it is still there. Roger > > I went through some previous related posts to the list, but could not find > the answer. > > Thanks, > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From dhirajkhanna at gmail.com Thu Sep 24 19:23:55 2015 From: dhirajkhanna at gmail.com (Dhiraj Khanna) Date: Thu, 24 Sep 2015 22:53:55 +0530 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings Message-ID: Hello, I am trying to solve automatic label placement problem for an engineering drawing using the Simulated Annealing algorithm. I came across the pointLabel() function in the maptools library in R. However, what I found was that while the function is able to optimally place the labels, it doesn't take into account the underlying drawing. I don't want the labels to overlap with the drawing lines. Is there some way I can achieve this? Also, my labels are of varying size in terms of width and height. Is there any way in which I can specify the dimension of each label apart from the point of origin of the labels? This is my code and a link to the requisite csv files: https://www.dropbox.com/s/85qqs4nlvm4crck/TextBoxData.rar?dl=0 library(dplyr) library(maptools) #Known Size of Sheet xmin <- -357.7 xmax <- 19.3 ymin <- -90.2 ymax <- 159.7 #Read in the data linescoords <- read.csv("Linecoords.csv") #Coordinates translation linescoords$X <- linescoords$X - xmin linescoords$Y <- linescoords$Y - ymin #Plot the figure xlimit <- c(-10, abs(xmin-xmax)+10 ) ylimit <- c(-10, abs(ymin-ymax)+10 ) plot(linescoords$X, linescoords$Y, "p", xlim=xlimit, ylim = ylimit) i <- seq(1, nrow(linescoords), 2)for(x in i){ segments(linescoords$X[x], linescoords$Y[x], linescoords$X[x+1], linescoords$Y[x+1])} #Read in text labels data labels <- read.csv("labels.csv") #Text labels Coordinates translation labels$x <- labels$x - xmin labels$y <- labels$y - ymin labels$xminl <- labels$xminl - xmin labels$xmaxl <- labels$xmaxl - xmin labels$yminl <- labels$yminl - ymin labels$ymaxl <- labels$ymaxl - ymin #Point of Origin for labels points(labels$x, labels$y, pch=16, col="red") #Width & Height of labels labels <- labels %>% mutate(width=abs(xminl-xmaxl), height=abs(yminl-ymaxl)) pointLabel(labels$x, labels$y, labels$Point) Regards Dhiraj Khanna Mob:09873263331 [[alternative HTML version deleted]] From matzke at nimbios.org Fri Sep 25 09:08:55 2015 From: matzke at nimbios.org (Nick Matzke) Date: Fri, 25 Sep 2015 17:08:55 +1000 Subject: [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, 180) In-Reply-To: References: Message-ID: Hi all, Thanks for all of the help! I just wanted to follow-up and post the code that ended up for my purposes. (Also, this may help my future self find the code again in a few years.) If you want to see the graphic, see: http://phylo.wikidot.com/biogeonick Cheers, Nick Code: ================= ####################################################### # Make a map of Nick Matzke's world travels # # Using: http://www.latlong.net/ # ####################################################### # Plot Great Circle paths: # https://stat.ethz.ch/pipermail/r-sig-geo/2015-June/023032.html library(geosphere) library(gdata) # for read.xls library(maptools) # for e.g. wrld_simpl library(rgdal) # for e.g. library(gpclib) # for polygon clipping library(fields) # for colorbar.plot wd = "/drives/GDrive/Matzke_PhD_docs/CV/_graphics/Matzke_map/" setwd(wd) xlsfn = "_Matzke_where_Ive_been_v1.xlsx" xls = read.xls(xlsfn, header=TRUE, stringsAsFactors=FALSE) head(xls) tail(xls) long_offset = -70 pdffn = "Matzke_map_v1.pdf" pdf(file=pdffn, width=12, height=6) data(wrld_simpl) #The world as a SpatialPolygonsDataFrame #To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break: w <- nowrapRecenter(wrld_simpl, offset = 180+long_offset, avoidGEOS=TRUE) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) CRS_string = paste0("+proj=robin +lon_0=", long_offset) wrld_reCentered <- spTransform(w, CRS(CRS_string)) #wrld_reCentered2 <- spTransform(wrld_reCentered, CRS("+proj=longlat +lon_0=90")) # Color countries by visiting country_names = setNames(rep("white", length(wrld_simpl$NAME)), wrld_simpl$NAME) country_colors <- setNames(rep("white", length(wrld_simpl$NAME)), wrld_simpl$NAME) countries_visited = c("Germany", "United States", "Canada", "Mexico", "United Kingdom", "France", "Zimbabwe", "Zambia", "United Republic of Tanzania", "Kenya", "Greece", "South Africa", "Namibia", "Lesotho", "New Zealand", "French Guiana", "Brazil", "Australia", "Swaziland", "Botswana", "Finland", "Turkey", "Angola", "Madagascar", "China", "Spain", "Chile") country_colors[countries_visited] = rep("grey70", times=length(countries_visited)) plot(wrld_reCentered, border="grey40", lwd=0.5, col=country_colors) xls_original = xls xls$latitude = jitter(xls$latitude) xls$longitude = jitter(xls$longitude) cols_for_lines = rainbow(n=nrow(xls)) for (i in 2:nrow(xls)) { point1 = c(xls$longitude[i-1], xls$latitude[i-1]) point2 = c(xls$longitude[i], xls$latitude[i]) names(point1) = c("x","y") names(point2) = c("x","y") path = gcIntermediate(p1=point1, p2=point2, n=200, addStartEnd=TRUE, breakAtDateLine=TRUE) if (is.null(dim(path)) == FALSE) { L1 = Line(path) Ls1 = Lines(L1, ID="a") SL1 = SpatialLines(list(Ls1), proj4string=CRS("+proj=longlat")) SL1 #plot(SL1, add=TRUE) lw <- nowrapSpatialLines(SL1, offset = 180+long_offset) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) lwrld_reCentered <- spTransform(lw, CRS(CRS_string)) plot(lwrld_reCentered, add=TRUE, col=cols_for_lines[i], lwd=2) #lines(sppoints, col=cols_for_lines[i]) #path = coordinates(path) #sppoints = SpatialPoints(coords=path, proj4string=CRS("+proj=robin +lon_0=-80")) #points(sppoints, col=cols_for_lines[i], add=TRUE) } if (is.null(dim(path)) == TRUE) { for (j in 1:length(path)) { path2 = path[[j]] #sppoints = SpatialPoints(coords=path2, proj4string=CRS("+proj=robin +lon_0=-80")) #points(sppoints, col=cols_for_lines[i], add=TRUE) #lines(sppoints, col=cols_for_lines[i]) L1 = Line(path2) Ls1 = Lines(L1, ID="a") SL1 = SpatialLines(list(Ls1), proj4string=CRS("+proj=longlat")) SL1 lw <- nowrapSpatialLines(SL1, offset = 180+long_offset) #Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150?E as the new center) lwrld_reCentered <- spTransform(lw, CRS(CRS_string)) plot(lwrld_reCentered, add=TRUE, col=cols_for_lines[i], lwd=2) } } } # END for (i in 2:nrow(xls)) plot(0,0, pch=".", col="white", xlim=c(0,1), ylim=c(0,1)) stripvals <- ( 1:100) colorbar.plot(x=0.5, y=0.5, strip=y, horizontal=FALSE) dev.off() cmdstr = paste0("open ", pdffn) system(cmdstr) ================= On Mon, Sep 14, 2015 at 6:58 PM, englishchristophera at gmail.com < englishchristophera at gmail.com> wrote: > > > There is the minus sign part to enter. Though knowing what you are > ultimately seeking would help clarify. That being said- dancing around the > dateline is conspicuous for the difficulties that can present.Chris > ------ Original message------From: Nick MatzkeDate: Mon, Sep 14, 2015 7:47 > AMTo: Frede Aakmann T?gersen;Cc: r-sig-geo at stat.math.ethz.ch;Subject:Re: > [R-sig-Geo] making wrld_simpl longitude borders something other than (-180, > 180) > Apologies, I got my wires crossed.What I meant was, how would I make a map > where the left edge was atlongitude 100 (e.g. Thailand), and the right edge > is at, say 99(again Thailand). The Pacific Ocean, and the International > Dateline, wouldbe in the middle of this map.I tried the obvious > thing:plot(wrld_simpl, xlim = c(100, 99))...but that produces a flipped > map...Cheers!NickOn Mon, Sep 14, 2015 at 3:38 PM, Frede Aakmann T?gersen > wrote:> Hi Nick>> To be honest I do not understand your question so I am > guessing that you> probably only need to set the xlim to c(-100, 100). Here > is an example:>> > data(wrld_simpl)> > plot(wrld_simpl)> > plot(wrld_simpl, > xlim = c(-100, 100))>> Why would one wants to redefine the longitudes from > the interval (-180,> 180) to (-100, 100)?>>> Yours sincerely / Med venlig > hilsen>> Frede Aakmann T?gersen> Specialist, M.Sc., Ph.D.> Plant > Performance & Modeling>> Technology & Service Solutions> T +45 9730 5135> M > +45 2547 6050> frtog at vestas.com> http://www.vestas.com>> Company reg. > name: Vestas Wind Systems A/S> This e-mail is subject to our e-mail > disclaimer statement.> Please refer to www.vestas.com/legal/notice> If > you have received this e-mail in error please contact the sender.>>> > -----Original Message-----> From: R-sig-Geo [mailto: > r-sig-geo-bounces at r-project.org] On Behalf Of> Nick Matzke> Sent: 14. > september 2015 06:51> To: r-sig-geo at stat.math.ethz.ch> Subject: > [R-sig-Geo] making wrld_simpl longitude borders something other> than > (-180, 180)>> Hi all,>> I would like to plot wrld_simpl, but have the left > and right edges of the> map be at something like 100 degrees longitude, > rather than (-180, 180).>> I tried messing with the bounding box with no > luck.>> I can imagine something like burrowing into the object and > subtracting 80> degrees from all the longitudes, but I suspect there must > be a better way?>> Any help appreciated!> Nick>> [[alternative HTML > version deleted]]>> _______________________________________________> > R-sig-Geo mailing list> R-sig-Geo at r-project.org> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> [[alternative HTML > version deleted]]_______________________________________________R-sig-Geo > mailing listR-sig-Geo at r-project.orghttps:// > stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] From dupouey at nancy.inra.fr Fri Sep 25 13:16:58 2015 From: dupouey at nancy.inra.fr (Jean-Luc Dupouey) Date: Fri, 25 Sep 2015 13:16:58 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> Message-ID: <56052D2A.8060009@nancy.inra.fr> Thanks for your answer. Unfortunately, I have no time to spend debugging the GEOS code. Just making some tests under R, I found an even worse situation, where the program seems to work, but gives a completely false result: library(sp) library(rgeos) #build a first polygon, MyLay, composed of two adjacent squares, size 1x1: Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) Pols1=Polygons(list(Polygon(Pol1)),"Pols1") Pols2=Polygons(list(Polygon(Pol2)),"Pols2") MyLay=SpatialPolygons(list(Pols1,Pols2)) #build a second polygon, MyLayl, composed of the same two squares lagged by 0.1 in x and y directions: Pol1l=Pol1+0.1 Pol2l=Pol2+0.1 Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) #view the resulting spatial layers: plot(MyLay) plot(MyLayl,add=TRUE) #"successful" intersection: inter=gIntersection(MyLay,MyLayl) #but false result: the intersection gives the same contour as MyLay! plot(MyLay) plot(MyLayl,add=TRUE) plot(inter,col="red",add=TRUE) I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. If such an error occurs when crossing larger spatial layers, it will remain undetectable. If I am not wrong, it implies that this software is not very reliable. Especially when considering that byid=FALSE is the default option. gIntersection gives a correct result using the option byid=TRUE. The intersect function of the raster package also gives a correct intersection. Do you think this latter function could be a better option, in general? Thanks in advance, Jean-Luc Dupouey INRA Forest Ecology & Ecophysiology Unit F-54280 Champenoux France mail: dupouey at nancy.inra.fr Le 23/09/2015 19:39, Roger Bivand a ?crit : > On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: > >> Why gIntersection returns the ""TopologyException: no outgoing >> dirEdge found at" error in the following very simple case: >> >>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >> units: >>> >>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>> >>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>> >>> #construct the same layer, but lagged by 0.5 in x and y directions >>> >>> Pol1l=Pol1+0.5 >>> Pol2l=Pol2+0.5 >>> >>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>> >>> #view the resulting spatial layers: >>> >>> plot(MyLay) >>> plot(MyLayl,add=TRUE) >>> >>> #try to intersect: >>> >>> inter=gIntersection(MyLay,MyLayl) >> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >> "rgeos_intersection") : >> TopologyException: no outgoing dirEdge found at 0.5 0 > > The error message is coming from GEOS - you are welcome to investigate > further. If you use gUnaryUnion() on the objects first, there is no > error: > > library(rgeos) > Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) > Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) > library(sp) > Pols1=Polygons(list(Polygon(Pol1)),"Pols1") > Pols2=Polygons(list(Polygon(Pol2)),"Pols2") > MyLay=SpatialPolygons(list(Pols1,Pols2)) > Pol1l=Pol1+0.5 > Pol2l=Pol2+0.5 > Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") > Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") > MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) > plot(MyLay) > plot(MyLayl,add=TRUE) > points(x=0.5, y=0) > inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) > plot(inter, add=TRUE, border="green") > > It is a GEOS issue, not rgeos. > >> >> It works with the option byid=TRUE. >> >> But my question is why it does not work without? Is this behaviour >> predictable? > > This is unknown. I'll try again on GEOS 3.5.0 and see if it is still > there: yes, unfortunately it is still there. > > Roger > >> >> I went through some previous related posts to the list, but could not >> find the answer. >> >> Thanks, >> >> > From Roger.Bivand at nhh.no Fri Sep 25 13:37:44 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 13:37:44 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <56052D2A.8060009@nancy.inra.fr> References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> Message-ID: On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: > Thanks for your answer. Unfortunately, I have no time to spend debugging > the GEOS code. Just making some tests under R, I found an even worse > situation, where the program seems to work, but gives a completely false > result: Well, none of us get paid around here for support or maintenance, so you are the guy asking the question, you are the one interested in the answer, you should find the time to "pay back" what other volunteers have created. > > library(sp) > library(rgeos) > > #build a first polygon, MyLay, composed of two adjacent squares, size 1x1: > > Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) > Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) > > Pols1=Polygons(list(Polygon(Pol1)),"Pols1") > Pols2=Polygons(list(Polygon(Pol2)),"Pols2") > MyLay=SpatialPolygons(list(Pols1,Pols2)) > > #build a second polygon, MyLayl, composed of the same two squares lagged by > 0.1 in x and y directions: > > Pol1l=Pol1+0.1 > Pol2l=Pol2+0.1 > > Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") > Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") > MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) > > #view the resulting spatial layers: > > plot(MyLay) > plot(MyLayl,add=TRUE) > > #"successful" intersection: > > inter=gIntersection(MyLay,MyLayl) You did not follow my advice to put the objects into gUnaryUnion() first, to remove the problem. It isn't obvious where this problem is coming from, but most likely requires debugging in GEOS itself. > > #but false result: the intersection gives the same contour as MyLay! > > plot(MyLay) > plot(MyLayl,add=TRUE) > plot(inter,col="red",add=TRUE) > > I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. > > If such an error occurs when crossing larger spatial layers, it will remain > undetectable. > > If I am not wrong, it implies that this software is not very reliable. > Especially when considering that byid=FALSE is the default option. > > gIntersection gives a correct result using the option byid=TRUE. This was not what you said you wanted, which was the (single) object for which MyLay intersected MyLayl. > The intersect function of the raster package also gives a correct > intersection. Do you think this latter function could be a better > option, in general? > No, not at all. If you inspect it, you'll see that it simply tries to "help" users by trying to guess which "data" slot elements might be copied across. It also calls gIntersect() in dense mode, which will choke on intersections between objects with many geometries. It runs gIntersection(..., byid=TRUE), so adds little to just doing that. See: library(rgdal) getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) Hope this clarifies, Roger > Thanks in advance, > > Jean-Luc Dupouey > > INRA > Forest Ecology & Ecophysiology Unit > F-54280 Champenoux > France > mail: dupouey at nancy.inra.fr > > Le 23/09/2015 19:39, Roger Bivand a ?crit : >> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >> >>> Why gIntersection returns the ""TopologyException: no outgoing >>> dirEdge found at" error in the following very simple case: >>> >>>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >>> units: >>>> >>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>> >>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>> >>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>> >>>> Pol1l=Pol1+0.5 >>>> Pol2l=Pol2+0.5 >>>> >>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>> >>>> #view the resulting spatial layers: >>>> >>>> plot(MyLay) >>>> plot(MyLayl,add=TRUE) >>>> >>>> #try to intersect: >>>> >>>> inter=gIntersection(MyLay,MyLayl) >>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>> "rgeos_intersection") : >>> TopologyException: no outgoing dirEdge found at 0.5 0 >> >> The error message is coming from GEOS - you are welcome to investigate >> further. If you use gUnaryUnion() on the objects first, there is no >> error: >> >> library(rgeos) >> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >> library(sp) >> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >> MyLay=SpatialPolygons(list(Pols1,Pols2)) >> Pol1l=Pol1+0.5 >> Pol2l=Pol2+0.5 >> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >> plot(MyLay) >> plot(MyLayl,add=TRUE) >> points(x=0.5, y=0) >> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >> plot(inter, add=TRUE, border="green") >> >> It is a GEOS issue, not rgeos. >> >>> >>> It works with the option byid=TRUE. >>> >>> But my question is why it does not work without? Is this behaviour >>> predictable? >> >> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >> there: yes, unfortunately it is still there. >> >> Roger >> >>> >>> I went through some previous related posts to the list, but could not >>> find the answer. >>> >>> Thanks, >>> >>> >> > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From Roger.Bivand at nhh.no Fri Sep 25 14:36:24 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 14:36:24 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> Message-ID: On Fri, 25 Sep 2015, Roger Bivand wrote: > On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: > ... >> >> library(sp) >> library(rgeos) >> >> #build a first polygon, MyLay, composed of two adjacent squares, size 1x1: >> >> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the earlier: > inter=gIntersection(MyLay,MyLayl) Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, "rgeos_intersection") : TopologyException: no outgoing dirEdge found at 0.5 0 so this is another rendering of the original edge case in GEOS in this thread. The practical resolution is to run gUnaryUnion() on the objects when byid=FALSE and the required output is a single (possibly multipart) geometry containing the whole intersection. Should we consider using gUnaryUnion() by default if byid for the object is FALSE, but permit users to choose not to do this? Roger >> >> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >> MyLay=SpatialPolygons(list(Pols1,Pols2)) >> >> #build a second polygon, MyLayl, composed of the same two squares lagged by >> 0.1 in x and y directions: >> >> Pol1l=Pol1+0.1 >> Pol2l=Pol2+0.1 >> >> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >> >> #view the resulting spatial layers: >> >> plot(MyLay) >> plot(MyLayl,add=TRUE) >> >> #"successful" intersection: >> >> inter=gIntersection(MyLay,MyLayl) > > You did not follow my advice to put the objects into gUnaryUnion() first, to > remove the problem. It isn't obvious where this problem is coming from, but > most likely requires debugging in GEOS itself. > >> >> #but false result: the intersection gives the same contour as MyLay! >> >> plot(MyLay) >> plot(MyLayl,add=TRUE) >> plot(inter,col="red",add=TRUE) >> >> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >> >> If such an error occurs when crossing larger spatial layers, it will remain >> undetectable. >> >> If I am not wrong, it implies that this software is not very reliable. >> Especially when considering that byid=FALSE is the default option. >> >> gIntersection gives a correct result using the option byid=TRUE. > > This was not what you said you wanted, which was the (single) object for > which MyLay intersected MyLayl. > >> The intersect function of the raster package also gives a correct >> intersection. Do you think this latter function could be a better option, >> in general? >> > > No, not at all. If you inspect it, you'll see that it simply tries to "help" > users by trying to guess which "data" slot elements might be copied across. > It also calls gIntersect() in dense mode, which will choke on intersections > between objects with many geometries. It runs gIntersection(..., byid=TRUE), > so adds little to just doing that. > > See: > > library(rgdal) > getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) > > Hope this clarifies, > > Roger > >> Thanks in advance, >> >> Jean-Luc Dupouey >> >> INRA >> Forest Ecology & Ecophysiology Unit >> F-54280 Champenoux >> France >> mail: dupouey at nancy.inra.fr >> >> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>> >>>> Why gIntersection returns the ""TopologyException: no outgoing >>>> dirEdge found at" error in the following very simple case: >>>> >>>>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >>>> units: >>>>> >>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>> >>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>> >>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>> >>>>> Pol1l=Pol1+0.5 >>>>> Pol2l=Pol2+0.5 >>>>> >>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>> >>>>> #view the resulting spatial layers: >>>>> >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> >>>>> #try to intersect: >>>>> >>>>> inter=gIntersection(MyLay,MyLayl) >>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>> "rgeos_intersection") : >>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>> >>> The error message is coming from GEOS - you are welcome to investigate >>> further. If you use gUnaryUnion() on the objects first, there is no >>> error: >>> >>> library(rgeos) >>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>> library(sp) >>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>> Pol1l=Pol1+0.5 >>> Pol2l=Pol2+0.5 >>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>> plot(MyLay) >>> plot(MyLayl,add=TRUE) >>> points(x=0.5, y=0) >>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>> plot(inter, add=TRUE, border="green") >>> >>> It is a GEOS issue, not rgeos. >>> >>>> >>>> It works with the option byid=TRUE. >>>> >>>> But my question is why it does not work without? Is this behaviour >>>> predictable? >>> >>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>> there: yes, unfortunately it is still there. >>> >>> Roger >>> >>>> >>>> I went through some previous related posts to the list, but could not >>>> find the answer. >>>> >>>> Thanks, >>>> >>>> >>> >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From edzer.pebesma at uni-muenster.de Fri Sep 25 14:46:14 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 25 Sep 2015 14:46:14 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> Message-ID: <56054216.7010107@uni-muenster.de> On 25/09/15 14:36, Roger Bivand wrote: > On Fri, 25 Sep 2015, Roger Bivand wrote: > >> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >> > ... >>> >>> library(sp) >>> library(rgeos) >>> >>> #build a first polygon, MyLay, composed of two adjacent squares, size >>> 1x1: >>> >>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) > > Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the > earlier: > >> inter=gIntersection(MyLay,MyLayl) > Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, > "rgeos_intersection") : > TopologyException: no outgoing dirEdge found at 0.5 0 > > so this is another rendering of the original edge case in GEOS in this > thread. The practical resolution is to run gUnaryUnion() on the objects > when byid=FALSE and the required output is a single (possibly multipart) > geometry containing the whole intersection. > > Should we consider using gUnaryUnion() by default if byid for the object > is FALSE, but permit users to choose not to do this? Has someone tried to reproduce this with GEOS, without R, e.g. by a PostGIS query? > > Roger > >>> >>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>> >>> #build a second polygon, MyLayl, composed of the same two squares >>> lagged by 0.1 in x and y directions: >>> >>> Pol1l=Pol1+0.1 >>> Pol2l=Pol2+0.1 >>> >>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>> >>> #view the resulting spatial layers: >>> >>> plot(MyLay) >>> plot(MyLayl,add=TRUE) >>> >>> #"successful" intersection: >>> >>> inter=gIntersection(MyLay,MyLayl) >> >> You did not follow my advice to put the objects into gUnaryUnion() >> first, to remove the problem. It isn't obvious where this problem is >> coming from, but most likely requires debugging in GEOS itself. >> >>> >>> #but false result: the intersection gives the same contour as MyLay! >>> >>> plot(MyLay) >>> plot(MyLayl,add=TRUE) >>> plot(inter,col="red",add=TRUE) >>> >>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>> >>> If such an error occurs when crossing larger spatial layers, it will >>> remain undetectable. >>> >>> If I am not wrong, it implies that this software is not very >>> reliable. Especially when considering that byid=FALSE is the default >>> option. >>> >>> gIntersection gives a correct result using the option byid=TRUE. >> >> This was not what you said you wanted, which was the (single) object >> for which MyLay intersected MyLayl. >> >>> The intersect function of the raster package also gives a correct >>> intersection. Do you think this latter function could be a better >>> option, in general? >>> >> >> No, not at all. If you inspect it, you'll see that it simply tries to >> "help" users by trying to guess which "data" slot elements might be >> copied across. It also calls gIntersect() in dense mode, which will >> choke on intersections between objects with many geometries. It runs >> gIntersection(..., byid=TRUE), so adds little to just doing that. >> >> See: >> >> library(rgdal) >> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >> >> Hope this clarifies, >> >> Roger >> >>> Thanks in advance, >>> >>> Jean-Luc Dupouey >>> >>> INRA >>> Forest Ecology & Ecophysiology Unit >>> F-54280 Champenoux >>> France >>> mail: dupouey at nancy.inra.fr >>> >>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>> >>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>> dirEdge found at" error in the following very simple case: >>>>> >>>>>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >>>>> units: >>>>>> >>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>> >>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>> >>>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>>> >>>>>> Pol1l=Pol1+0.5 >>>>>> Pol2l=Pol2+0.5 >>>>>> >>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>> >>>>>> #view the resulting spatial layers: >>>>>> >>>>>> plot(MyLay) >>>>>> plot(MyLayl,add=TRUE) >>>>>> >>>>>> #try to intersect: >>>>>> >>>>>> inter=gIntersection(MyLay,MyLayl) >>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>> "rgeos_intersection") : >>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>> >>>> The error message is coming from GEOS - you are welcome to investigate >>>> further. If you use gUnaryUnion() on the objects first, there is no >>>> error: >>>> >>>> library(rgeos) >>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>> library(sp) >>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>> Pol1l=Pol1+0.5 >>>> Pol2l=Pol2+0.5 >>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>> plot(MyLay) >>>> plot(MyLayl,add=TRUE) >>>> points(x=0.5, y=0) >>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>> plot(inter, add=TRUE, border="green") >>>> >>>> It is a GEOS issue, not rgeos. >>>> >>>>> >>>>> It works with the option byid=TRUE. >>>>> >>>>> But my question is why it does not work without? Is this behaviour >>>>> predictable? >>>> >>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>>> there: yes, unfortunately it is still there. >>>> >>>> Roger >>>> >>>>> >>>>> I went through some previous related posts to the list, but could not >>>>> find the answer. >>>>> >>>>> Thanks, >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> R-sig-Geo at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>> >> >> > > > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From Roger.Bivand at nhh.no Fri Sep 25 19:02:15 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 19:02:15 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <56054216.7010107@uni-muenster.de> References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> Message-ID: On Fri, 25 Sep 2015, Edzer Pebesma wrote: > > > On 25/09/15 14:36, Roger Bivand wrote: >> On Fri, 25 Sep 2015, Roger Bivand wrote: >> >>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>> >> ... >>>> >>>> library(sp) >>>> library(rgeos) >>>> >>>> #build a first polygon, MyLay, composed of two adjacent squares, size >>>> 1x1: >>>> >>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >> >> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the >> earlier: >> >>> inter=gIntersection(MyLay,MyLayl) >> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >> "rgeos_intersection") : >> TopologyException: no outgoing dirEdge found at 0.5 0 >> >> so this is another rendering of the original edge case in GEOS in this >> thread. The practical resolution is to run gUnaryUnion() on the objects >> when byid=FALSE and the required output is a single (possibly multipart) >> geometry containing the whole intersection. >> >> Should we consider using gUnaryUnion() by default if byid for the object >> is FALSE, but permit users to choose not to do this? > > Has someone tried to reproduce this with GEOS, without R, e.g. by a > PostGIS query? Do you have a running PostGIS instance - I don't. I did try v.overlay in GRASS, but it isn't GEOS-based, and returns the correct answer for byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm re-installing GEOS with Python, but someone else should check (my GEOS 3.5.0). Roger > >> >> Roger >> >>>> >>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>> >>>> #build a second polygon, MyLayl, composed of the same two squares >>>> lagged by 0.1 in x and y directions: >>>> >>>> Pol1l=Pol1+0.1 >>>> Pol2l=Pol2+0.1 >>>> >>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>> >>>> #view the resulting spatial layers: >>>> >>>> plot(MyLay) >>>> plot(MyLayl,add=TRUE) >>>> >>>> #"successful" intersection: >>>> >>>> inter=gIntersection(MyLay,MyLayl) >>> >>> You did not follow my advice to put the objects into gUnaryUnion() >>> first, to remove the problem. It isn't obvious where this problem is >>> coming from, but most likely requires debugging in GEOS itself. >>> >>>> >>>> #but false result: the intersection gives the same contour as MyLay! >>>> >>>> plot(MyLay) >>>> plot(MyLayl,add=TRUE) >>>> plot(inter,col="red",add=TRUE) >>>> >>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>> >>>> If such an error occurs when crossing larger spatial layers, it will >>>> remain undetectable. >>>> >>>> If I am not wrong, it implies that this software is not very >>>> reliable. Especially when considering that byid=FALSE is the default >>>> option. >>>> >>>> gIntersection gives a correct result using the option byid=TRUE. >>> >>> This was not what you said you wanted, which was the (single) object >>> for which MyLay intersected MyLayl. >>> >>>> The intersect function of the raster package also gives a correct >>>> intersection. Do you think this latter function could be a better >>>> option, in general? >>>> >>> >>> No, not at all. If you inspect it, you'll see that it simply tries to >>> "help" users by trying to guess which "data" slot elements might be >>> copied across. It also calls gIntersect() in dense mode, which will >>> choke on intersections between objects with many geometries. It runs >>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>> >>> See: >>> >>> library(rgdal) >>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>> >>> Hope this clarifies, >>> >>> Roger >>> >>>> Thanks in advance, >>>> >>>> Jean-Luc Dupouey >>>> >>>> INRA >>>> Forest Ecology & Ecophysiology Unit >>>> F-54280 Champenoux >>>> France >>>> mail: dupouey at nancy.inra.fr >>>> >>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>> >>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>> dirEdge found at" error in the following very simple case: >>>>>> >>>>>>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >>>>>> units: >>>>>>> >>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>> >>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>> >>>>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>>>> >>>>>>> Pol1l=Pol1+0.5 >>>>>>> Pol2l=Pol2+0.5 >>>>>>> >>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>> >>>>>>> #view the resulting spatial layers: >>>>>>> >>>>>>> plot(MyLay) >>>>>>> plot(MyLayl,add=TRUE) >>>>>>> >>>>>>> #try to intersect: >>>>>>> >>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>> "rgeos_intersection") : >>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>> >>>>> The error message is coming from GEOS - you are welcome to investigate >>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>> error: >>>>> >>>>> library(rgeos) >>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>> library(sp) >>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>> Pol1l=Pol1+0.5 >>>>> Pol2l=Pol2+0.5 >>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> points(x=0.5, y=0) >>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>> plot(inter, add=TRUE, border="green") >>>>> >>>>> It is a GEOS issue, not rgeos. >>>>> >>>>>> >>>>>> It works with the option byid=TRUE. >>>>>> >>>>>> But my question is why it does not work without? Is this behaviour >>>>>> predictable? >>>>> >>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>>>> there: yes, unfortunately it is still there. >>>>> >>>>> Roger >>>>> >>>>>> >>>>>> I went through some previous related posts to the list, but could not >>>>>> find the answer. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> >>>>> >>>> >>>> _______________________________________________ >>>> R-sig-Geo mailing list >>>> R-sig-Geo at r-project.org >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>> >>> >>> >> >> >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From vijaylulla at gmail.com Fri Sep 25 19:28:02 2015 From: vijaylulla at gmail.com (Vijay Lulla) Date: Fri, 25 Sep 2015 13:28:02 -0400 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> Message-ID: Seems to be working in PostGIS! Below is from my PostGIS session: gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); st_intersects --------------- t (1 row) gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); st_intersection ------------------------------------------------------------------------------------ 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 (1 row) gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); st_intersection ------------------------------------------------------------------------------------ 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 (1 row) gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); st_intersects --------------- t (1 row) gisdb=# select postgis_version(); postgis_version --------------------------------------- 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 (1 row) gisdb=# select postgis_full_version(); postgis_full_vers ion ------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------- POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. 4.8.0, 6 March 2012" GDAL ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER (1 row) On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand wrote: > On Fri, 25 Sep 2015, Edzer Pebesma wrote: > >> >> >> On 25/09/15 14:36, Roger Bivand wrote: >>> >>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>> >>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>> >>> ... >>>>> >>>>> >>>>> library(sp) >>>>> library(rgeos) >>>>> >>>>> #build a first polygon, MyLay, composed of two adjacent squares, size >>>>> 1x1: >>>>> >>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>> >>> >>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the >>> earlier: >>> >>>> inter=gIntersection(MyLay,MyLayl) >>> >>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>> "rgeos_intersection") : >>> TopologyException: no outgoing dirEdge found at 0.5 0 >>> >>> so this is another rendering of the original edge case in GEOS in this >>> thread. The practical resolution is to run gUnaryUnion() on the objects >>> when byid=FALSE and the required output is a single (possibly multipart) >>> geometry containing the whole intersection. >>> >>> Should we consider using gUnaryUnion() by default if byid for the object >>> is FALSE, but permit users to choose not to do this? >> >> >> Has someone tried to reproduce this with GEOS, without R, e.g. by a >> PostGIS query? > > > Do you have a running PostGIS instance - I don't. I did try v.overlay in > GRASS, but it isn't GEOS-based, and returns the correct answer for > byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm re-installing GEOS > with Python, but someone else should check (my GEOS 3.5.0). > > Roger > > >> >>> >>> Roger >>> >>>>> >>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>> >>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>> lagged by 0.1 in x and y directions: >>>>> >>>>> Pol1l=Pol1+0.1 >>>>> Pol2l=Pol2+0.1 >>>>> >>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>> >>>>> #view the resulting spatial layers: >>>>> >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> >>>>> #"successful" intersection: >>>>> >>>>> inter=gIntersection(MyLay,MyLayl) >>>> >>>> >>>> You did not follow my advice to put the objects into gUnaryUnion() >>>> first, to remove the problem. It isn't obvious where this problem is >>>> coming from, but most likely requires debugging in GEOS itself. >>>> >>>>> >>>>> #but false result: the intersection gives the same contour as MyLay! >>>>> >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> plot(inter,col="red",add=TRUE) >>>>> >>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>> >>>>> If such an error occurs when crossing larger spatial layers, it will >>>>> remain undetectable. >>>>> >>>>> If I am not wrong, it implies that this software is not very >>>>> reliable. Especially when considering that byid=FALSE is the default >>>>> option. >>>>> >>>>> gIntersection gives a correct result using the option byid=TRUE. >>>> >>>> >>>> This was not what you said you wanted, which was the (single) object >>>> for which MyLay intersected MyLayl. >>>> >>>>> The intersect function of the raster package also gives a correct >>>>> intersection. Do you think this latter function could be a better >>>>> option, in general? >>>>> >>>> >>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>> "help" users by trying to guess which "data" slot elements might be >>>> copied across. It also calls gIntersect() in dense mode, which will >>>> choke on intersections between objects with many geometries. It runs >>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>> >>>> See: >>>> >>>> library(rgdal) >>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>> >>>> Hope this clarifies, >>>> >>>> Roger >>>> >>>>> Thanks in advance, >>>>> >>>>> Jean-Luc Dupouey >>>>> >>>>> INRA >>>>> Forest Ecology & Ecophysiology Unit >>>>> F-54280 Champenoux >>>>> France >>>>> mail: dupouey at nancy.inra.fr >>>>> >>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>> >>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>> >>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>> dirEdge found at" error in the following very simple case: >>>>>>> >>>>>>>> #construct a spatial layer with two adjacent squares, each of 10 x >>>>>>>> 10 >>>>>>> >>>>>>> units: >>>>>>>> >>>>>>>> >>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>> >>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>> >>>>>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>>>>> >>>>>>>> Pol1l=Pol1+0.5 >>>>>>>> Pol2l=Pol2+0.5 >>>>>>>> >>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>> >>>>>>>> #view the resulting spatial layers: >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> >>>>>>>> #try to intersect: >>>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> >>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>>> "rgeos_intersection") : >>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>> >>>>>> >>>>>> The error message is coming from GEOS - you are welcome to investigate >>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>> error: >>>>>> >>>>>> library(rgeos) >>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>> library(sp) >>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>> Pol1l=Pol1+0.5 >>>>>> Pol2l=Pol2+0.5 >>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>> plot(MyLay) >>>>>> plot(MyLayl,add=TRUE) >>>>>> points(x=0.5, y=0) >>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>> plot(inter, add=TRUE, border="green") >>>>>> >>>>>> It is a GEOS issue, not rgeos. >>>>>> >>>>>>> >>>>>>> It works with the option byid=TRUE. >>>>>>> >>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>> predictable? >>>>>> >>>>>> >>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>>>>> there: yes, unfortunately it is still there. >>>>>> >>>>>> Roger >>>>>> >>>>>>> >>>>>>> I went through some previous related posts to the list, but could not >>>>>>> find the answer. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> R-sig-Geo mailing list >>>>> R-sig-Geo at r-project.org >>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>> >>>> >>>> >>> >>> >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> R-sig-Geo at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>> >> >> > > -- > Roger Bivand > Department of Economics, Norwegian School of Economics, > Helleveien 30, N-5045 Bergen, Norway. > voice: +47 55 95 93 55; fax +47 55 95 91 00 > e-mail: Roger.Bivand at nhh.no > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > From Roger.Bivand at nhh.no Fri Sep 25 19:29:41 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 19:29:41 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> Message-ID: On Fri, 25 Sep 2015, Roger Bivand wrote: > On Fri, 25 Sep 2015, Edzer Pebesma wrote: > >> >> >> On 25/09/15 14:36, Roger Bivand wrote: >>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>> >>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>> >>> ... >>>>> >>>>> library(sp) >>>>> library(rgeos) >>>>> >>>>> #build a first polygon, MyLay, composed of two adjacent squares, size >>>>> 1x1: >>>>> >>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>> >>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the >>> earlier: >>> >>>> inter=gIntersection(MyLay,MyLayl) >>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>> "rgeos_intersection") : >>> TopologyException: no outgoing dirEdge found at 0.5 0 >>> >>> so this is another rendering of the original edge case in GEOS in this >>> thread. The practical resolution is to run gUnaryUnion() on the objects >>> when byid=FALSE and the required output is a single (possibly multipart) >>> geometry containing the whole intersection. >>> >>> Should we consider using gUnaryUnion() by default if byid for the object >>> is FALSE, but permit users to choose not to do this? >> >> Has someone tried to reproduce this with GEOS, without R, e.g. by a >> PostGIS query? > > Do you have a running PostGIS instance - I don't. I did try v.overlay in > GRASS, but it isn't GEOS-based, and returns the correct answer for > byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm re-installing GEOS > with Python, but someone else should check (my GEOS 3.5.0). With Shapely, I see (values output from rgeos::writeWKT): from shapely.wkt import dumps, loads >>> MyLay = loads("GEOMETRYCOLLECTION (POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)), POLYGON ((0.0000000000000000 0.0000000000000000, 1.0000000000000000 0.0000000000000000, 1.0000000000000000 -1.0000000000000000, 0.0000000000000000 -1.0000000000000000, 0.0000000000000000 0.0000000000000000)))") >>> MyLayl = loads("GEOMETRYCOLLECTION (POLYGON ((0.1000000000000000 0.1000000000000000, 0.1000000000000000 1.1000000000000001, 1.1000000000000001 1.1000000000000001, 1.1000000000000001 0.1000000000000000, 0.1000000000000000 0.1000000000000000)), POLYGON ((0.1000000000000000 0.1000000000000000, 1.1000000000000001 0.1000000000000000, 1.1000000000000001 -0.9000000000000000, 0.1000000000000000 -0.9000000000000000, 0.1000000000000000 0.1000000000000000)))") >>> merged = MyLay.intersection(MyLayl) >>> dumps(merged) 'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 1.0000000000000000 -1.0000000000000000, 0.0000000000000000 -1.0000000000000000, 0.0000000000000000 0.0000000000000000))' >>> merged.equals(MyLay) True So this looks like GEOS, not rgeos. I'll post to geos-devel for clarification. Roger > > Roger > >> >>> >>> Roger >>> >>>>> >>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>> >>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>> lagged by 0.1 in x and y directions: >>>>> >>>>> Pol1l=Pol1+0.1 >>>>> Pol2l=Pol2+0.1 >>>>> >>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>> >>>>> #view the resulting spatial layers: >>>>> >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> >>>>> #"successful" intersection: >>>>> >>>>> inter=gIntersection(MyLay,MyLayl) >>>> >>>> You did not follow my advice to put the objects into gUnaryUnion() >>>> first, to remove the problem. It isn't obvious where this problem is >>>> coming from, but most likely requires debugging in GEOS itself. >>>> >>>>> >>>>> #but false result: the intersection gives the same contour as MyLay! >>>>> >>>>> plot(MyLay) >>>>> plot(MyLayl,add=TRUE) >>>>> plot(inter,col="red",add=TRUE) >>>>> >>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>> >>>>> If such an error occurs when crossing larger spatial layers, it will >>>>> remain undetectable. >>>>> >>>>> If I am not wrong, it implies that this software is not very >>>>> reliable. Especially when considering that byid=FALSE is the default >>>>> option. >>>>> >>>>> gIntersection gives a correct result using the option byid=TRUE. >>>> >>>> This was not what you said you wanted, which was the (single) object >>>> for which MyLay intersected MyLayl. >>>> >>>>> The intersect function of the raster package also gives a correct >>>>> intersection. Do you think this latter function could be a better >>>>> option, in general? >>>>> >>>> >>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>> "help" users by trying to guess which "data" slot elements might be >>>> copied across. It also calls gIntersect() in dense mode, which will >>>> choke on intersections between objects with many geometries. It runs >>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>> >>>> See: >>>> >>>> library(rgdal) >>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>> >>>> Hope this clarifies, >>>> >>>> Roger >>>> >>>>> Thanks in advance, >>>>> >>>>> Jean-Luc Dupouey >>>>> >>>>> INRA >>>>> Forest Ecology & Ecophysiology Unit >>>>> F-54280 Champenoux >>>>> France >>>>> mail: dupouey at nancy.inra.fr >>>>> >>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>> >>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>> dirEdge found at" error in the following very simple case: >>>>>>> >>>>>>>> #construct a spatial layer with two adjacent squares, each of 10 x 10 >>>>>>> units: >>>>>>>> >>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>> >>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>> >>>>>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>>>>> >>>>>>>> Pol1l=Pol1+0.5 >>>>>>>> Pol2l=Pol2+0.5 >>>>>>>> >>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>> >>>>>>>> #view the resulting spatial layers: >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> >>>>>>>> #try to intersect: >>>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>>> "rgeos_intersection") : >>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>> >>>>>> The error message is coming from GEOS - you are welcome to investigate >>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>> error: >>>>>> >>>>>> library(rgeos) >>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>> library(sp) >>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>> Pol1l=Pol1+0.5 >>>>>> Pol2l=Pol2+0.5 >>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>> plot(MyLay) >>>>>> plot(MyLayl,add=TRUE) >>>>>> points(x=0.5, y=0) >>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>> plot(inter, add=TRUE, border="green") >>>>>> >>>>>> It is a GEOS issue, not rgeos. >>>>>> >>>>>>> >>>>>>> It works with the option byid=TRUE. >>>>>>> >>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>> predictable? >>>>>> >>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>>>>> there: yes, unfortunately it is still there. >>>>>> >>>>>> Roger >>>>>> >>>>>>> >>>>>>> I went through some previous related posts to the list, but could not >>>>>>> find the answer. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> R-sig-Geo mailing list >>>>> R-sig-Geo at r-project.org >>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>> >>>> >>>> >>> >>> >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> R-sig-Geo at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>> >> >> > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From jochen.albrecht at gmail.com Fri Sep 25 19:36:03 2015 From: jochen.albrecht at gmail.com (Jochen Albrecht) Date: Fri, 25 Sep 2015 13:36:03 -0400 Subject: [R-sig-Geo] source of Bivand reference to 1986 Medicaid data Message-ID: A student of mine, who not only carefully read Roger's chapter in Fischer & Getis (2009) *Handbook of Applied Spatial Data Analysis* but then also wanted to explore the code snippets, pointed out to me that a data set referenced in that chapter does not seem to have a web presence. Does anyone on this group know of the Medicaid 1986 program quality scores data and where to find it on the Web? I have found later references to others who have worked with this data, which leads me to believe that it was originally compiled by the Public Citizen Health Research Group but their web site search tool also has no pointers to the data itself. Cheers, Jochen "*The data set contains Medicaid program quality scores for 48 U.S. contiguous states for 1986, here stored externally in a shapefile, and read into a SpatialPolygonsDataFrame object*." .. "*The PQS variable belongs to the medicaid object, here a SpatialPolygonsDataFrame object, and is accessed using the $ operator.*" > stem(medicaid$PQS, scale = 2) > stripchart (medicaid$PQS, method = ,jitter?, vertical = TRUE) > boxplot(medicaid$PQS) > hist(medicaid$PQS, col = ,grey90?, freq = FALSE) > lines(density(medicaid$PQS, bw = 15), lwd = 2) > rug(medicaid$PQS) [[alternative HTML version deleted]] From Roger.Bivand at nhh.no Fri Sep 25 19:44:46 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 19:44:46 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> Message-ID: On Fri, 25 Sep 2015, Vijay Lulla wrote: > Seems to be working in PostGIS! Below is from my PostGIS session: > > gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 > 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); > st_intersects > --------------- > t > (1 row) > > > gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 > 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); > st_intersection > ------------------------------------------------------------------------------------ > 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 > (1 row) > > gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 > 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); > st_intersection > ------------------------------------------------------------------------------------ > 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 > (1 row) Thanks for this, but are these the same - that is each geometry collection consists of two touching squares, but the second is offset =.1 North Eastwards? In any case, very grateful that you took a look! Roger > > > gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 > 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); > st_intersects > --------------- > t > (1 row) > > gisdb=# select postgis_version(); > postgis_version > --------------------------------------- > 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 > (1 row) > > > gisdb=# select postgis_full_version(); > > postgis_full_vers > ion > ------------------------------------------------------------------------------------------ > ---------------------------------------------------------------------------- > POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. > 4.8.0, 6 March 2012" GDAL > ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER > (1 row) > > On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand wrote: >> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >> >>> >>> >>> On 25/09/15 14:36, Roger Bivand wrote: >>>> >>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>> >>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>> >>>> ... >>>>>> >>>>>> >>>>>> library(sp) >>>>>> library(rgeos) >>>>>> >>>>>> #build a first polygon, MyLay, composed of two adjacent squares, size >>>>>> 1x1: >>>>>> >>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>> >>>> >>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives the >>>> earlier: >>>> >>>>> inter=gIntersection(MyLay,MyLayl) >>>> >>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>> "rgeos_intersection") : >>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>> >>>> so this is another rendering of the original edge case in GEOS in this >>>> thread. The practical resolution is to run gUnaryUnion() on the objects >>>> when byid=FALSE and the required output is a single (possibly multipart) >>>> geometry containing the whole intersection. >>>> >>>> Should we consider using gUnaryUnion() by default if byid for the object >>>> is FALSE, but permit users to choose not to do this? >>> >>> >>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>> PostGIS query? >> >> >> Do you have a running PostGIS instance - I don't. I did try v.overlay in >> GRASS, but it isn't GEOS-based, and returns the correct answer for >> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm re-installing GEOS >> with Python, but someone else should check (my GEOS 3.5.0). >> >> Roger >> >> >>> >>>> >>>> Roger >>>> >>>>>> >>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>> >>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>> lagged by 0.1 in x and y directions: >>>>>> >>>>>> Pol1l=Pol1+0.1 >>>>>> Pol2l=Pol2+0.1 >>>>>> >>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>> >>>>>> #view the resulting spatial layers: >>>>>> >>>>>> plot(MyLay) >>>>>> plot(MyLayl,add=TRUE) >>>>>> >>>>>> #"successful" intersection: >>>>>> >>>>>> inter=gIntersection(MyLay,MyLayl) >>>>> >>>>> >>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>> first, to remove the problem. It isn't obvious where this problem is >>>>> coming from, but most likely requires debugging in GEOS itself. >>>>> >>>>>> >>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>> >>>>>> plot(MyLay) >>>>>> plot(MyLayl,add=TRUE) >>>>>> plot(inter,col="red",add=TRUE) >>>>>> >>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>> >>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>> remain undetectable. >>>>>> >>>>>> If I am not wrong, it implies that this software is not very >>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>> option. >>>>>> >>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>> >>>>> >>>>> This was not what you said you wanted, which was the (single) object >>>>> for which MyLay intersected MyLayl. >>>>> >>>>>> The intersect function of the raster package also gives a correct >>>>>> intersection. Do you think this latter function could be a better >>>>>> option, in general? >>>>>> >>>>> >>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>> "help" users by trying to guess which "data" slot elements might be >>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>> choke on intersections between objects with many geometries. It runs >>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>> >>>>> See: >>>>> >>>>> library(rgdal) >>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>> >>>>> Hope this clarifies, >>>>> >>>>> Roger >>>>> >>>>>> Thanks in advance, >>>>>> >>>>>> Jean-Luc Dupouey >>>>>> >>>>>> INRA >>>>>> Forest Ecology & Ecophysiology Unit >>>>>> F-54280 Champenoux >>>>>> France >>>>>> mail: dupouey at nancy.inra.fr >>>>>> >>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>> >>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>> >>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>> >>>>>>>>> #construct a spatial layer with two adjacent squares, each of 10 x >>>>>>>>> 10 >>>>>>>> >>>>>>>> units: >>>>>>>>> >>>>>>>>> >>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>> >>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>> >>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y directions >>>>>>>>> >>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>> >>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>> >>>>>>>>> #view the resulting spatial layers: >>>>>>>>> >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> >>>>>>>>> #try to intersect: >>>>>>>>> >>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>> >>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>>>> "rgeos_intersection") : >>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>> >>>>>>> >>>>>>> The error message is coming from GEOS - you are welcome to investigate >>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>> error: >>>>>>> >>>>>>> library(rgeos) >>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>> library(sp) >>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>> Pol1l=Pol1+0.5 >>>>>>> Pol2l=Pol2+0.5 >>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>> plot(MyLay) >>>>>>> plot(MyLayl,add=TRUE) >>>>>>> points(x=0.5, y=0) >>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>> plot(inter, add=TRUE, border="green") >>>>>>> >>>>>>> It is a GEOS issue, not rgeos. >>>>>>> >>>>>>>> >>>>>>>> It works with the option byid=TRUE. >>>>>>>> >>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>> predictable? >>>>>>> >>>>>>> >>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is still >>>>>>> there: yes, unfortunately it is still there. >>>>>>> >>>>>>> Roger >>>>>>> >>>>>>>> >>>>>>>> I went through some previous related posts to the list, but could not >>>>>>>> find the answer. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> R-sig-Geo mailing list >>>>>> R-sig-Geo at r-project.org >>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> R-sig-Geo mailing list >>>> R-sig-Geo at r-project.org >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>> >>> >>> >> >> -- >> Roger Bivand >> Department of Economics, Norwegian School of Economics, >> Helleveien 30, N-5045 Bergen, Norway. >> voice: +47 55 95 93 55; fax +47 55 95 91 00 >> e-mail: Roger.Bivand at nhh.no >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From Roger.Bivand at nhh.no Fri Sep 25 20:17:47 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Fri, 25 Sep 2015 20:17:47 +0200 Subject: [R-sig-Geo] source of Bivand reference to 1986 Medicaid data In-Reply-To: References: Message-ID: On Fri, 25 Sep 2015, Jochen Albrecht wrote: > A student of mine, who not only carefully read Roger's chapter in Fischer & > Getis (2009) *Handbook of Applied Spatial Data Analysis* but then also > wanted to explore the code snippets, pointed out to me that a data set > referenced in that chapter does not seem to have a web presence. > Does anyone on this group know of the Medicaid 1986 program quality scores > data and where to find it on the Web? I have found later references to > others who have worked with this data, which leads me to believe that it > was originally compiled by the Public Citizen Health Research Group but > their web site search tool also has no pointers to the data itself. The data are from: Jacoby, William G. (1997) Statistical Graphics for Univariate and Bivariate Data. Thousand Oaks, CA: Sage. I've put a copy?of both the simulated data and Jacoby's tabulation of PQS added to a shapefile on: http://spatial.nhh.no/misc/jacoby.zip Hope this helps, Roger PS. I did ask about providing code and data for the handbook, but the publisher was not then interested. > Cheers, > Jochen > > "*The data set contains Medicaid program quality scores for 48 U.S. > contiguous states for 1986, here stored externally in a shapefile, and read > into a SpatialPolygonsDataFrame object*." .. "*The PQS variable belongs > to the medicaid object, here a SpatialPolygonsDataFrame object, and is > accessed using the $ operator.*" > >> stem(medicaid$PQS, scale = 2) >> stripchart (medicaid$PQS, method = ,jitter?, vertical = TRUE) >> boxplot(medicaid$PQS) >> hist(medicaid$PQS, col = ,grey90?, freq = FALSE) >> lines(density(medicaid$PQS, bw = 15), lwd = 2) >> rug(medicaid$PQS) > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From edzer.pebesma at uni-muenster.de Fri Sep 25 21:55:20 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 25 Sep 2015 21:55:20 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> Message-ID: <5605A6A8.3080604@uni-muenster.de> Thanks Vijay; FYI, following OP's example, I see in PostGIS: SELECT ST_AsText(ST_Intersection( 'MULTIPOLYGON( ((0 0, 0 10, 10 10, 10 0, 0 0)), ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry, 'MULTIPOLYGON( ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), ((0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5)))'::geometry )); giving: ERROR: Error performing intersection: TopologyException: Input geom 0 is invalid: Self-intersection at or near point 0 0 at 0 0 but SELECT ST_AsText(ST_Intersection( 'MULTIPOLYGON( ((0 0, 0 10, 10 10, 10 0, 0 0)), ((0 -1, 10 -1, 10 -10, 0 -10, 0 -1)))'::geometry, 'MULTIPOLYGON( ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), ((0.5 0.0, 10.5 0.0, 10.5 -10.5, 0.5 -10.5, 0.5 0.0)))'::geometry )); giving no error; when I try SELECT ST_AsText(ST_Intersection( 'POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0), (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry, 'POLYGON( (0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5), (0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5))'::geometry )); it gives the same error as the first example. On 25/09/15 19:44, Roger Bivand wrote: > On Fri, 25 Sep 2015, Vijay Lulla wrote: > >> Seems to be working in PostGIS! Below is from my PostGIS session: >> >> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >> st_intersects >> --------------- >> t >> (1 row) >> >> >> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >> st_intersection >> ------------------------------------------------------------------------------------ >> >> 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 >> >> (1 row) >> >> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >> st_intersection >> ------------------------------------------------------------------------------------ >> >> 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 >> >> (1 row) > > Thanks for this, but are these the same - that is each geometry > collection consists of two touching squares, but the second is offset > =.1 North Eastwards? In any case, very grateful that you took a look! > > Roger > >> >> >> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >> st_intersects >> --------------- >> t >> (1 row) >> >> gisdb=# select postgis_version(); >> postgis_version >> --------------------------------------- >> 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 >> (1 row) >> >> >> gisdb=# select postgis_full_version(); >> >> postgis_full_vers >> ion >> ------------------------------------------------------------------------------------------ >> >> ---------------------------------------------------------------------------- >> >> POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. >> 4.8.0, 6 March 2012" GDAL >> ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" >> RASTER >> (1 row) >> >> On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand >> wrote: >>> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >>> >>>> >>>> >>>> On 25/09/15 14:36, Roger Bivand wrote: >>>>> >>>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>>> >>>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>>> >>>>> ... >>>>>>> >>>>>>> >>>>>>> library(sp) >>>>>>> library(rgeos) >>>>>>> >>>>>>> #build a first polygon, MyLay, composed of two adjacent squares, >>>>>>> size >>>>>>> 1x1: >>>>>>> >>>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>>> >>>>> >>>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives >>>>> the >>>>> earlier: >>>>> >>>>>> inter=gIntersection(MyLay,MyLayl) >>>>> >>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>> "rgeos_intersection") : >>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>> >>>>> so this is another rendering of the original edge case in GEOS in this >>>>> thread. The practical resolution is to run gUnaryUnion() on the >>>>> objects >>>>> when byid=FALSE and the required output is a single (possibly >>>>> multipart) >>>>> geometry containing the whole intersection. >>>>> >>>>> Should we consider using gUnaryUnion() by default if byid for the >>>>> object >>>>> is FALSE, but permit users to choose not to do this? >>>> >>>> >>>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>>> PostGIS query? >>> >>> >>> Do you have a running PostGIS instance - I don't. I did try v.overlay in >>> GRASS, but it isn't GEOS-based, and returns the correct answer for >>> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm >>> re-installing GEOS >>> with Python, but someone else should check (my GEOS 3.5.0). >>> >>> Roger >>> >>> >>>> >>>>> >>>>> Roger >>>>> >>>>>>> >>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>> >>>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>>> lagged by 0.1 in x and y directions: >>>>>>> >>>>>>> Pol1l=Pol1+0.1 >>>>>>> Pol2l=Pol2+0.1 >>>>>>> >>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>> >>>>>>> #view the resulting spatial layers: >>>>>>> >>>>>>> plot(MyLay) >>>>>>> plot(MyLayl,add=TRUE) >>>>>>> >>>>>>> #"successful" intersection: >>>>>>> >>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>> >>>>>> >>>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>>> first, to remove the problem. It isn't obvious where this problem is >>>>>> coming from, but most likely requires debugging in GEOS itself. >>>>>> >>>>>>> >>>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>>> >>>>>>> plot(MyLay) >>>>>>> plot(MyLayl,add=TRUE) >>>>>>> plot(inter,col="red",add=TRUE) >>>>>>> >>>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>>> >>>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>>> remain undetectable. >>>>>>> >>>>>>> If I am not wrong, it implies that this software is not very >>>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>>> option. >>>>>>> >>>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>>> >>>>>> >>>>>> This was not what you said you wanted, which was the (single) object >>>>>> for which MyLay intersected MyLayl. >>>>>> >>>>>>> The intersect function of the raster package also gives a correct >>>>>>> intersection. Do you think this latter function could be a better >>>>>>> option, in general? >>>>>>> >>>>>> >>>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>>> "help" users by trying to guess which "data" slot elements might be >>>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>>> choke on intersections between objects with many geometries. It runs >>>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>>> >>>>>> See: >>>>>> >>>>>> library(rgdal) >>>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>>> >>>>>> Hope this clarifies, >>>>>> >>>>>> Roger >>>>>> >>>>>>> Thanks in advance, >>>>>>> >>>>>>> Jean-Luc Dupouey >>>>>>> >>>>>>> INRA >>>>>>> Forest Ecology & Ecophysiology Unit >>>>>>> F-54280 Champenoux >>>>>>> France >>>>>>> mail: dupouey at nancy.inra.fr >>>>>>> >>>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>>> >>>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>> >>>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>>> >>>>>>>>>> #construct a spatial layer with two adjacent squares, each of >>>>>>>>>> 10 x >>>>>>>>>> 10 >>>>>>>>> >>>>>>>>> units: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>> >>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>> >>>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y >>>>>>>>>> directions >>>>>>>>>> >>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>> >>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>> >>>>>>>>>> #view the resulting spatial layers: >>>>>>>>>> >>>>>>>>>> plot(MyLay) >>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>> >>>>>>>>>> #try to intersect: >>>>>>>>>> >>>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>>> >>>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, >>>>>>>>> drop_lower_td, >>>>>>>>> "rgeos_intersection") : >>>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>>> >>>>>>>> >>>>>>>> The error message is coming from GEOS - you are welcome to >>>>>>>> investigate >>>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>>> error: >>>>>>>> >>>>>>>> library(rgeos) >>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>> library(sp) >>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>> Pol1l=Pol1+0.5 >>>>>>>> Pol2l=Pol2+0.5 >>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> points(x=0.5, y=0) >>>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>>> plot(inter, add=TRUE, border="green") >>>>>>>> >>>>>>>> It is a GEOS issue, not rgeos. >>>>>>>> >>>>>>>>> >>>>>>>>> It works with the option byid=TRUE. >>>>>>>>> >>>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>>> predictable? >>>>>>>> >>>>>>>> >>>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is >>>>>>>> still >>>>>>>> there: yes, unfortunately it is still there. >>>>>>>> >>>>>>>> Roger >>>>>>>> >>>>>>>>> >>>>>>>>> I went through some previous related posts to the list, but >>>>>>>>> could not >>>>>>>>> find the answer. >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> R-sig-Geo mailing list >>>>>>> R-sig-Geo at r-project.org >>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> R-sig-Geo mailing list >>>>> R-sig-Geo at r-project.org >>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>> >>>> >>>> >>> >>> -- >>> Roger Bivand >>> Department of Economics, Norwegian School of Economics, >>> Helleveien 30, N-5045 Bergen, Norway. >>> voice: +47 55 95 93 55; fax +47 55 95 91 00 >>> e-mail: Roger.Bivand at nhh.no >>> >>> _______________________________________________ >>> R-sig-Geo mailing list >>> R-sig-Geo at r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>> >> > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From edzer.pebesma at uni-muenster.de Fri Sep 25 22:26:44 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Fri, 25 Sep 2015 22:26:44 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <5605A6A8.3080604@uni-muenster.de> References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> <5605A6A8.3080604@uni-muenster.de> Message-ID: <5605AE04.9080602@uni-muenster.de> Trying to reduce the problem, it seems PostGIS thinks that polygons are invalid for which R believes they are valid: postgis=# select ST_IsValid('MULTIPOLYGON( postgis'# ((0 0, 0 10, 10 10, 10 0, 0 0)), postgis'# ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry); NOTICE: Self-intersection at or near point 0 0 st_isvalid ------------ f (1 row) postgis=# select ST_IsValid('POLYGON( postgis'# (0 0, 0 10, 10 10, 10 0, 0 0), postgis'# (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); NOTICE: Self-intersection at or near point 0 0 st_isvalid ------------ f (1 row) but > library(rgeos) > Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) > Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) > > Pols1=Polygons(list(Polygon(Pol1)),"Pols1") > Pols2=Polygons(list(Polygon(Pol2)),"Pols2") > MyLay=SpatialPolygons(list(Pols1,Pols2)) > gIsValid(MyLay) [1] TRUE Maybe gUnaryUnion-ing MultiPolygons before intersecting when byid = FALSE is not such a bad idea after all? On 25/09/15 21:55, Edzer Pebesma wrote: > Thanks Vijay; FYI, following OP's example, I see in PostGIS: > > SELECT ST_AsText(ST_Intersection( > 'MULTIPOLYGON( > ((0 0, 0 10, 10 10, 10 0, 0 0)), > ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry, > 'MULTIPOLYGON( > ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), > ((0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5)))'::geometry > )); > > giving: > > ERROR: Error performing intersection: TopologyException: Input geom 0 > is invalid: Self-intersection at or near point 0 0 at 0 0 > > but > > SELECT ST_AsText(ST_Intersection( > 'MULTIPOLYGON( > ((0 0, 0 10, 10 10, 10 0, 0 0)), > ((0 -1, 10 -1, 10 -10, 0 -10, 0 -1)))'::geometry, > 'MULTIPOLYGON( > ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), > ((0.5 0.0, 10.5 0.0, 10.5 -10.5, 0.5 -10.5, 0.5 0.0)))'::geometry > )); > > giving no error; when I try > > SELECT ST_AsText(ST_Intersection( > 'POLYGON( > (0 0, 0 10, 10 10, 10 0, 0 0), > (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry, > 'POLYGON( > (0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5), > (0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5))'::geometry > )); > > it gives the same error as the first example. > > > > On 25/09/15 19:44, Roger Bivand wrote: >> On Fri, 25 Sep 2015, Vijay Lulla wrote: >> >>> Seems to be working in PostGIS! Below is from my PostGIS session: >>> >>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>> st_intersects >>> --------------- >>> t >>> (1 row) >>> >>> >>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>> st_intersection >>> ------------------------------------------------------------------------------------ >>> >>> 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 >>> >>> (1 row) >>> >>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>> st_intersection >>> ------------------------------------------------------------------------------------ >>> >>> 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 >>> >>> (1 row) >> >> Thanks for this, but are these the same - that is each geometry >> collection consists of two touching squares, but the second is offset >> =.1 North Eastwards? In any case, very grateful that you took a look! >> >> Roger >> >>> >>> >>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>> st_intersects >>> --------------- >>> t >>> (1 row) >>> >>> gisdb=# select postgis_version(); >>> postgis_version >>> --------------------------------------- >>> 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 >>> (1 row) >>> >>> >>> gisdb=# select postgis_full_version(); >>> >>> postgis_full_vers >>> ion >>> ------------------------------------------------------------------------------------------ >>> >>> ---------------------------------------------------------------------------- >>> >>> POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. >>> 4.8.0, 6 March 2012" GDAL >>> ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" >>> RASTER >>> (1 row) >>> >>> On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand >>> wrote: >>>> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >>>> >>>>> >>>>> >>>>> On 25/09/15 14:36, Roger Bivand wrote: >>>>>> >>>>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>>>> >>>>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>> >>>>>> ... >>>>>>>> >>>>>>>> >>>>>>>> library(sp) >>>>>>>> library(rgeos) >>>>>>>> >>>>>>>> #build a first polygon, MyLay, composed of two adjacent squares, >>>>>>>> size >>>>>>>> 1x1: >>>>>>>> >>>>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>>>> >>>>>> >>>>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives >>>>>> the >>>>>> earlier: >>>>>> >>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>> >>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>> "rgeos_intersection") : >>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>> >>>>>> so this is another rendering of the original edge case in GEOS in this >>>>>> thread. The practical resolution is to run gUnaryUnion() on the >>>>>> objects >>>>>> when byid=FALSE and the required output is a single (possibly >>>>>> multipart) >>>>>> geometry containing the whole intersection. >>>>>> >>>>>> Should we consider using gUnaryUnion() by default if byid for the >>>>>> object >>>>>> is FALSE, but permit users to choose not to do this? >>>>> >>>>> >>>>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>>>> PostGIS query? >>>> >>>> >>>> Do you have a running PostGIS instance - I don't. I did try v.overlay in >>>> GRASS, but it isn't GEOS-based, and returns the correct answer for >>>> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm >>>> re-installing GEOS >>>> with Python, but someone else should check (my GEOS 3.5.0). >>>> >>>> Roger >>>> >>>> >>>>> >>>>>> >>>>>> Roger >>>>>> >>>>>>>> >>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>> >>>>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>>>> lagged by 0.1 in x and y directions: >>>>>>>> >>>>>>>> Pol1l=Pol1+0.1 >>>>>>>> Pol2l=Pol2+0.1 >>>>>>>> >>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>> >>>>>>>> #view the resulting spatial layers: >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> >>>>>>>> #"successful" intersection: >>>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> >>>>>>> >>>>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>>>> first, to remove the problem. It isn't obvious where this problem is >>>>>>> coming from, but most likely requires debugging in GEOS itself. >>>>>>> >>>>>>>> >>>>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> plot(inter,col="red",add=TRUE) >>>>>>>> >>>>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>>>> >>>>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>>>> remain undetectable. >>>>>>>> >>>>>>>> If I am not wrong, it implies that this software is not very >>>>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>>>> option. >>>>>>>> >>>>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>>>> >>>>>>> >>>>>>> This was not what you said you wanted, which was the (single) object >>>>>>> for which MyLay intersected MyLayl. >>>>>>> >>>>>>>> The intersect function of the raster package also gives a correct >>>>>>>> intersection. Do you think this latter function could be a better >>>>>>>> option, in general? >>>>>>>> >>>>>>> >>>>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>>>> "help" users by trying to guess which "data" slot elements might be >>>>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>>>> choke on intersections between objects with many geometries. It runs >>>>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>>>> >>>>>>> See: >>>>>>> >>>>>>> library(rgdal) >>>>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>>>> >>>>>>> Hope this clarifies, >>>>>>> >>>>>>> Roger >>>>>>> >>>>>>>> Thanks in advance, >>>>>>>> >>>>>>>> Jean-Luc Dupouey >>>>>>>> >>>>>>>> INRA >>>>>>>> Forest Ecology & Ecophysiology Unit >>>>>>>> F-54280 Champenoux >>>>>>>> France >>>>>>>> mail: dupouey at nancy.inra.fr >>>>>>>> >>>>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>>>> >>>>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>>> >>>>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>>>> >>>>>>>>>>> #construct a spatial layer with two adjacent squares, each of >>>>>>>>>>> 10 x >>>>>>>>>>> 10 >>>>>>>>>> >>>>>>>>>> units: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>>> >>>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>>> >>>>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y >>>>>>>>>>> directions >>>>>>>>>>> >>>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>>> >>>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>>> >>>>>>>>>>> #view the resulting spatial layers: >>>>>>>>>>> >>>>>>>>>>> plot(MyLay) >>>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>>> >>>>>>>>>>> #try to intersect: >>>>>>>>>>> >>>>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>>>> >>>>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, >>>>>>>>>> drop_lower_td, >>>>>>>>>> "rgeos_intersection") : >>>>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>>>> >>>>>>>>> >>>>>>>>> The error message is coming from GEOS - you are welcome to >>>>>>>>> investigate >>>>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>>>> error: >>>>>>>>> >>>>>>>>> library(rgeos) >>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>> library(sp) >>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> points(x=0.5, y=0) >>>>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>>>> plot(inter, add=TRUE, border="green") >>>>>>>>> >>>>>>>>> It is a GEOS issue, not rgeos. >>>>>>>>> >>>>>>>>>> >>>>>>>>>> It works with the option byid=TRUE. >>>>>>>>>> >>>>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>>>> predictable? >>>>>>>>> >>>>>>>>> >>>>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is >>>>>>>>> still >>>>>>>>> there: yes, unfortunately it is still there. >>>>>>>>> >>>>>>>>> Roger >>>>>>>>> >>>>>>>>>> >>>>>>>>>> I went through some previous related posts to the list, but >>>>>>>>>> could not >>>>>>>>>> find the answer. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> R-sig-Geo mailing list >>>>>>>> R-sig-Geo at r-project.org >>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> R-sig-Geo mailing list >>>>>> R-sig-Geo at r-project.org >>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>> >>>>> >>>>> >>>> >>>> -- >>>> Roger Bivand >>>> Department of Economics, Norwegian School of Economics, >>>> Helleveien 30, N-5045 Bergen, Norway. >>>> voice: +47 55 95 93 55; fax +47 55 95 91 00 >>>> e-mail: Roger.Bivand at nhh.no >>>> >>>> _______________________________________________ >>>> R-sig-Geo mailing list >>>> R-sig-Geo at r-project.org >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>> >>> >> > > > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From vijaylulla at gmail.com Fri Sep 25 23:30:37 2015 From: vijaylulla at gmail.com (Vijay Lulla) Date: Fri, 25 Sep 2015 17:30:37 -0400 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <5605A6A8.3080604@uni-muenster.de> References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> <5605A6A8.3080604@uni-muenster.de> Message-ID: OOPS! Sorry for my mistake. I'm observing the same results that Edzer has listed. It has to do with validity (http://www.postgis.net/docs/using_postgis_dbmanagement.html#OGC_Validity ) but I don't understand why the multipolygon listed in figure n (similar to what we're examining here, I think) in section 4.3.5 of postgis manual is invalid! Please pardon the noise. On Fri, Sep 25, 2015 at 3:55 PM, Edzer Pebesma wrote: > Thanks Vijay; FYI, following OP's example, I see in PostGIS: > > SELECT ST_AsText(ST_Intersection( > 'MULTIPOLYGON( > ((0 0, 0 10, 10 10, 10 0, 0 0)), > ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry, > 'MULTIPOLYGON( > ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), > ((0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5)))'::geometry > )); > > giving: > > ERROR: Error performing intersection: TopologyException: Input geom 0 > is invalid: Self-intersection at or near point 0 0 at 0 0 > > but > > SELECT ST_AsText(ST_Intersection( > 'MULTIPOLYGON( > ((0 0, 0 10, 10 10, 10 0, 0 0)), > ((0 -1, 10 -1, 10 -10, 0 -10, 0 -1)))'::geometry, > 'MULTIPOLYGON( > ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), > ((0.5 0.0, 10.5 0.0, 10.5 -10.5, 0.5 -10.5, 0.5 0.0)))'::geometry > )); > > giving no error; when I try > > SELECT ST_AsText(ST_Intersection( > 'POLYGON( > (0 0, 0 10, 10 10, 10 0, 0 0), > (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry, > 'POLYGON( > (0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5), > (0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5))'::geometry > )); > > it gives the same error as the first example. > > > > On 25/09/15 19:44, Roger Bivand wrote: >> On Fri, 25 Sep 2015, Vijay Lulla wrote: >> >>> Seems to be working in PostGIS! Below is from my PostGIS session: >>> >>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>> st_intersects >>> --------------- >>> t >>> (1 row) >>> >>> >>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>> st_intersection >>> ------------------------------------------------------------------------------------ >>> >>> 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 >>> >>> (1 row) >>> >>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>> st_intersection >>> ------------------------------------------------------------------------------------ >>> >>> 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 >>> >>> (1 row) >> >> Thanks for this, but are these the same - that is each geometry >> collection consists of two touching squares, but the second is offset >> =.1 North Eastwards? In any case, very grateful that you took a look! >> >> Roger >> >>> >>> >>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>> st_intersects >>> --------------- >>> t >>> (1 row) >>> >>> gisdb=# select postgis_version(); >>> postgis_version >>> --------------------------------------- >>> 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 >>> (1 row) >>> >>> >>> gisdb=# select postgis_full_version(); >>> >>> postgis_full_vers >>> ion >>> ------------------------------------------------------------------------------------------ >>> >>> ---------------------------------------------------------------------------- >>> >>> POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. >>> 4.8.0, 6 March 2012" GDAL >>> ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" >>> RASTER >>> (1 row) >>> >>> On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand >>> wrote: >>>> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >>>> >>>>> >>>>> >>>>> On 25/09/15 14:36, Roger Bivand wrote: >>>>>> >>>>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>>>> >>>>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>> >>>>>> ... >>>>>>>> >>>>>>>> >>>>>>>> library(sp) >>>>>>>> library(rgeos) >>>>>>>> >>>>>>>> #build a first polygon, MyLay, composed of two adjacent squares, >>>>>>>> size >>>>>>>> 1x1: >>>>>>>> >>>>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>>>> >>>>>> >>>>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives >>>>>> the >>>>>> earlier: >>>>>> >>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>> >>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>> "rgeos_intersection") : >>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>> >>>>>> so this is another rendering of the original edge case in GEOS in this >>>>>> thread. The practical resolution is to run gUnaryUnion() on the >>>>>> objects >>>>>> when byid=FALSE and the required output is a single (possibly >>>>>> multipart) >>>>>> geometry containing the whole intersection. >>>>>> >>>>>> Should we consider using gUnaryUnion() by default if byid for the >>>>>> object >>>>>> is FALSE, but permit users to choose not to do this? >>>>> >>>>> >>>>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>>>> PostGIS query? >>>> >>>> >>>> Do you have a running PostGIS instance - I don't. I did try v.overlay in >>>> GRASS, but it isn't GEOS-based, and returns the correct answer for >>>> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm >>>> re-installing GEOS >>>> with Python, but someone else should check (my GEOS 3.5.0). >>>> >>>> Roger >>>> >>>> >>>>> >>>>>> >>>>>> Roger >>>>>> >>>>>>>> >>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>> >>>>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>>>> lagged by 0.1 in x and y directions: >>>>>>>> >>>>>>>> Pol1l=Pol1+0.1 >>>>>>>> Pol2l=Pol2+0.1 >>>>>>>> >>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>> >>>>>>>> #view the resulting spatial layers: >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> >>>>>>>> #"successful" intersection: >>>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> >>>>>>> >>>>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>>>> first, to remove the problem. It isn't obvious where this problem is >>>>>>> coming from, but most likely requires debugging in GEOS itself. >>>>>>> >>>>>>>> >>>>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>>>> >>>>>>>> plot(MyLay) >>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>> plot(inter,col="red",add=TRUE) >>>>>>>> >>>>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>>>> >>>>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>>>> remain undetectable. >>>>>>>> >>>>>>>> If I am not wrong, it implies that this software is not very >>>>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>>>> option. >>>>>>>> >>>>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>>>> >>>>>>> >>>>>>> This was not what you said you wanted, which was the (single) object >>>>>>> for which MyLay intersected MyLayl. >>>>>>> >>>>>>>> The intersect function of the raster package also gives a correct >>>>>>>> intersection. Do you think this latter function could be a better >>>>>>>> option, in general? >>>>>>>> >>>>>>> >>>>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>>>> "help" users by trying to guess which "data" slot elements might be >>>>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>>>> choke on intersections between objects with many geometries. It runs >>>>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>>>> >>>>>>> See: >>>>>>> >>>>>>> library(rgdal) >>>>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>>>> >>>>>>> Hope this clarifies, >>>>>>> >>>>>>> Roger >>>>>>> >>>>>>>> Thanks in advance, >>>>>>>> >>>>>>>> Jean-Luc Dupouey >>>>>>>> >>>>>>>> INRA >>>>>>>> Forest Ecology & Ecophysiology Unit >>>>>>>> F-54280 Champenoux >>>>>>>> France >>>>>>>> mail: dupouey at nancy.inra.fr >>>>>>>> >>>>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>>>> >>>>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>>> >>>>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>>>> >>>>>>>>>>> #construct a spatial layer with two adjacent squares, each of >>>>>>>>>>> 10 x >>>>>>>>>>> 10 >>>>>>>>>> >>>>>>>>>> units: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>>> >>>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>>> >>>>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y >>>>>>>>>>> directions >>>>>>>>>>> >>>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>>> >>>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>>> >>>>>>>>>>> #view the resulting spatial layers: >>>>>>>>>>> >>>>>>>>>>> plot(MyLay) >>>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>>> >>>>>>>>>>> #try to intersect: >>>>>>>>>>> >>>>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>>>> >>>>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, >>>>>>>>>> drop_lower_td, >>>>>>>>>> "rgeos_intersection") : >>>>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>>>> >>>>>>>>> >>>>>>>>> The error message is coming from GEOS - you are welcome to >>>>>>>>> investigate >>>>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>>>> error: >>>>>>>>> >>>>>>>>> library(rgeos) >>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>> library(sp) >>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> points(x=0.5, y=0) >>>>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>>>> plot(inter, add=TRUE, border="green") >>>>>>>>> >>>>>>>>> It is a GEOS issue, not rgeos. >>>>>>>>> >>>>>>>>>> >>>>>>>>>> It works with the option byid=TRUE. >>>>>>>>>> >>>>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>>>> predictable? >>>>>>>>> >>>>>>>>> >>>>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is >>>>>>>>> still >>>>>>>>> there: yes, unfortunately it is still there. >>>>>>>>> >>>>>>>>> Roger >>>>>>>>> >>>>>>>>>> >>>>>>>>>> I went through some previous related posts to the list, but >>>>>>>>>> could not >>>>>>>>>> find the answer. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> R-sig-Geo mailing list >>>>>>>> R-sig-Geo at r-project.org >>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> R-sig-Geo mailing list >>>>>> R-sig-Geo at r-project.org >>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>> >>>>> >>>>> >>>> >>>> -- >>>> Roger Bivand >>>> Department of Economics, Norwegian School of Economics, >>>> Helleveien 30, N-5045 Bergen, Norway. >>>> voice: +47 55 95 93 55; fax +47 55 95 91 00 >>>> e-mail: Roger.Bivand at nhh.no >>>> >>>> _______________________________________________ >>>> R-sig-Geo mailing list >>>> R-sig-Geo at r-project.org >>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>> >>> >> > > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of M?nster, > Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 > Journal of Statistical Software: http://www.jstatsoft.org/ > Computers & Geosciences: http://elsevier.com/locate/cageo/ > Spatial Statistics Society http://www.spatialstatistics.info > From oscar.perpinan at upm.es Sat Sep 26 09:15:09 2015 From: oscar.perpinan at upm.es (Oscar =?utf-8?B?UGVycGnDscOhbg==?= Lamigueiro) Date: Sat, 26 Sep 2015 09:15:09 +0200 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings In-Reply-To: (Dhiraj Khanna's message of "Thu, 24 Sep 2015 22:53:55 +0530") References: Message-ID: <87pp15bqiq.fsf@upm.es> Hi, You could try the `lineLabel` and `sp.lineLabel` functions of this same package. Best. Oscar. -- Oscar Perpi??n Lamigueiro Dpto. Ing. El?ctrica, Electr?nica, Autom?tica y F?sica Aplicada Escuela T?cnica Superior de Ingenier?a y Dise?o Industrial URL: http://oscarperpinan.github.io From edzer.pebesma at uni-muenster.de Sat Sep 26 11:40:56 2015 From: edzer.pebesma at uni-muenster.de (Edzer Pebesma) Date: Sat, 26 Sep 2015 11:40:56 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> <5605A6A8.3080604@uni-muenster.de> Message-ID: <56066828.70203@uni-muenster.de> On 25/09/15 23:30, Vijay Lulla wrote: > OOPS! Sorry for my mistake. I'm observing the same results that > Edzer has listed. It has to do with validity > (http://www.postgis.net/docs/using_postgis_dbmanagement.html#OGC_Validity > ) but I don't understand why the multipolygon listed in figure n > (similar to what we're examining here, I think) in section 4.3.5 of > postgis manual is invalid! It says: "The boundaries of any two elements may touch, but only at a finite number of POINTs." Points on the line that have both polygons in common are ambiguous in terms of the DE-9IM relation with the polygon: they are both inside the polygon as well as on the polygon boundary. Still need to sort out why rgeos reports them as valid. > > Please pardon the noise. > > On Fri, Sep 25, 2015 at 3:55 PM, Edzer Pebesma > wrote: >> Thanks Vijay; FYI, following OP's example, I see in PostGIS: >> >> SELECT ST_AsText(ST_Intersection( >> 'MULTIPOLYGON( >> ((0 0, 0 10, 10 10, 10 0, 0 0)), >> ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry, >> 'MULTIPOLYGON( >> ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), >> ((0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5)))'::geometry >> )); >> >> giving: >> >> ERROR: Error performing intersection: TopologyException: Input geom 0 >> is invalid: Self-intersection at or near point 0 0 at 0 0 >> >> but >> >> SELECT ST_AsText(ST_Intersection( >> 'MULTIPOLYGON( >> ((0 0, 0 10, 10 10, 10 0, 0 0)), >> ((0 -1, 10 -1, 10 -10, 0 -10, 0 -1)))'::geometry, >> 'MULTIPOLYGON( >> ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), >> ((0.5 0.0, 10.5 0.0, 10.5 -10.5, 0.5 -10.5, 0.5 0.0)))'::geometry >> )); >> >> giving no error; when I try >> >> SELECT ST_AsText(ST_Intersection( >> 'POLYGON( >> (0 0, 0 10, 10 10, 10 0, 0 0), >> (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry, >> 'POLYGON( >> (0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5), >> (0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5))'::geometry >> )); >> >> it gives the same error as the first example. >> >> >> >> On 25/09/15 19:44, Roger Bivand wrote: >>> On Fri, 25 Sep 2015, Vijay Lulla wrote: >>> >>>> Seems to be working in PostGIS! Below is from my PostGIS session: >>>> >>>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>>> st_intersects >>>> --------------- >>>> t >>>> (1 row) >>>> >>>> >>>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>>> st_intersection >>>> ------------------------------------------------------------------------------------ >>>> >>>> 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 >>>> >>>> (1 row) >>>> >>>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>>> st_intersection >>>> ------------------------------------------------------------------------------------ >>>> >>>> 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 >>>> >>>> (1 row) >>> >>> Thanks for this, but are these the same - that is each geometry >>> collection consists of two touching squares, but the second is offset >>> =.1 North Eastwards? In any case, very grateful that you took a look! >>> >>> Roger >>> >>>> >>>> >>>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>>> st_intersects >>>> --------------- >>>> t >>>> (1 row) >>>> >>>> gisdb=# select postgis_version(); >>>> postgis_version >>>> --------------------------------------- >>>> 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 >>>> (1 row) >>>> >>>> >>>> gisdb=# select postgis_full_version(); >>>> >>>> postgis_full_vers >>>> ion >>>> ------------------------------------------------------------------------------------------ >>>> >>>> ---------------------------------------------------------------------------- >>>> >>>> POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. >>>> 4.8.0, 6 March 2012" GDAL >>>> ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" >>>> RASTER >>>> (1 row) >>>> >>>> On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand >>>> wrote: >>>>> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >>>>> >>>>>> >>>>>> >>>>>> On 25/09/15 14:36, Roger Bivand wrote: >>>>>>> >>>>>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>>>>> >>>>>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>> >>>>>>> ... >>>>>>>>> >>>>>>>>> >>>>>>>>> library(sp) >>>>>>>>> library(rgeos) >>>>>>>>> >>>>>>>>> #build a first polygon, MyLay, composed of two adjacent squares, >>>>>>>>> size >>>>>>>>> 1x1: >>>>>>>>> >>>>>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>>>>> >>>>>>> >>>>>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives >>>>>>> the >>>>>>> earlier: >>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> >>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>>> "rgeos_intersection") : >>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>> >>>>>>> so this is another rendering of the original edge case in GEOS in this >>>>>>> thread. The practical resolution is to run gUnaryUnion() on the >>>>>>> objects >>>>>>> when byid=FALSE and the required output is a single (possibly >>>>>>> multipart) >>>>>>> geometry containing the whole intersection. >>>>>>> >>>>>>> Should we consider using gUnaryUnion() by default if byid for the >>>>>>> object >>>>>>> is FALSE, but permit users to choose not to do this? >>>>>> >>>>>> >>>>>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>>>>> PostGIS query? >>>>> >>>>> >>>>> Do you have a running PostGIS instance - I don't. I did try v.overlay in >>>>> GRASS, but it isn't GEOS-based, and returns the correct answer for >>>>> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm >>>>> re-installing GEOS >>>>> with Python, but someone else should check (my GEOS 3.5.0). >>>>> >>>>> Roger >>>>> >>>>> >>>>>> >>>>>>> >>>>>>> Roger >>>>>>> >>>>>>>>> >>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>> >>>>>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>>>>> lagged by 0.1 in x and y directions: >>>>>>>>> >>>>>>>>> Pol1l=Pol1+0.1 >>>>>>>>> Pol2l=Pol2+0.1 >>>>>>>>> >>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>> >>>>>>>>> #view the resulting spatial layers: >>>>>>>>> >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> >>>>>>>>> #"successful" intersection: >>>>>>>>> >>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>> >>>>>>>> >>>>>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>>>>> first, to remove the problem. It isn't obvious where this problem is >>>>>>>> coming from, but most likely requires debugging in GEOS itself. >>>>>>>> >>>>>>>>> >>>>>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>>>>> >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> plot(inter,col="red",add=TRUE) >>>>>>>>> >>>>>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>>>>> >>>>>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>>>>> remain undetectable. >>>>>>>>> >>>>>>>>> If I am not wrong, it implies that this software is not very >>>>>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>>>>> option. >>>>>>>>> >>>>>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>>>>> >>>>>>>> >>>>>>>> This was not what you said you wanted, which was the (single) object >>>>>>>> for which MyLay intersected MyLayl. >>>>>>>> >>>>>>>>> The intersect function of the raster package also gives a correct >>>>>>>>> intersection. Do you think this latter function could be a better >>>>>>>>> option, in general? >>>>>>>>> >>>>>>>> >>>>>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>>>>> "help" users by trying to guess which "data" slot elements might be >>>>>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>>>>> choke on intersections between objects with many geometries. It runs >>>>>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>>>>> >>>>>>>> See: >>>>>>>> >>>>>>>> library(rgdal) >>>>>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>>>>> >>>>>>>> Hope this clarifies, >>>>>>>> >>>>>>>> Roger >>>>>>>> >>>>>>>>> Thanks in advance, >>>>>>>>> >>>>>>>>> Jean-Luc Dupouey >>>>>>>>> >>>>>>>>> INRA >>>>>>>>> Forest Ecology & Ecophysiology Unit >>>>>>>>> F-54280 Champenoux >>>>>>>>> France >>>>>>>>> mail: dupouey at nancy.inra.fr >>>>>>>>> >>>>>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>>>>> >>>>>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>>>> >>>>>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>>>>> >>>>>>>>>>>> #construct a spatial layer with two adjacent squares, each of >>>>>>>>>>>> 10 x >>>>>>>>>>>> 10 >>>>>>>>>>> >>>>>>>>>>> units: >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>>>> >>>>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>>>> >>>>>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y >>>>>>>>>>>> directions >>>>>>>>>>>> >>>>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>>>> >>>>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>>>> >>>>>>>>>>>> #view the resulting spatial layers: >>>>>>>>>>>> >>>>>>>>>>>> plot(MyLay) >>>>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>>>> >>>>>>>>>>>> #try to intersect: >>>>>>>>>>>> >>>>>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>>>>> >>>>>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, >>>>>>>>>>> drop_lower_td, >>>>>>>>>>> "rgeos_intersection") : >>>>>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> The error message is coming from GEOS - you are welcome to >>>>>>>>>> investigate >>>>>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>>>>> error: >>>>>>>>>> >>>>>>>>>> library(rgeos) >>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>> library(sp) >>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>> plot(MyLay) >>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>> points(x=0.5, y=0) >>>>>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>>>>> plot(inter, add=TRUE, border="green") >>>>>>>>>> >>>>>>>>>> It is a GEOS issue, not rgeos. >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> It works with the option byid=TRUE. >>>>>>>>>>> >>>>>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>>>>> predictable? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is >>>>>>>>>> still >>>>>>>>>> there: yes, unfortunately it is still there. >>>>>>>>>> >>>>>>>>>> Roger >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> I went through some previous related posts to the list, but >>>>>>>>>>> could not >>>>>>>>>>> find the answer. >>>>>>>>>>> >>>>>>>>>>> Thanks, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> R-sig-Geo mailing list >>>>>>>>> R-sig-Geo at r-project.org >>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> R-sig-Geo mailing list >>>>>>> R-sig-Geo at r-project.org >>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> Roger Bivand >>>>> Department of Economics, Norwegian School of Economics, >>>>> Helleveien 30, N-5045 Bergen, Norway. >>>>> voice: +47 55 95 93 55; fax +47 55 95 91 00 >>>>> e-mail: Roger.Bivand at nhh.no >>>>> >>>>> _______________________________________________ >>>>> R-sig-Geo mailing list >>>>> R-sig-Geo at r-project.org >>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>> >>>> >>> >> >> -- >> Edzer Pebesma >> Institute for Geoinformatics (ifgi), University of M?nster, >> Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 >> Journal of Statistical Software: http://www.jstatsoft.org/ >> Computers & Geosciences: http://elsevier.com/locate/cageo/ >> Spatial Statistics Society http://www.spatialstatistics.info >> -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: From dhirajkhanna at gmail.com Sat Sep 26 17:15:30 2015 From: dhirajkhanna at gmail.com (Dhiraj Khanna) Date: Sat, 26 Sep 2015 20:45:30 +0530 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings In-Reply-To: <87pp15bqiq.fsf@upm.es> References: <87pp15bqiq.fsf@upm.es> Message-ID: Thank you Oscar for the reply. Will try as you suggest. However, must admit that I am quite a noob when it comes to plotting. Was looking at your lineLabel() function and couldn't figure out what a "list of lines" is. Anyway, will struggle a little and do my homework. Just one question though. Will using the lineLabel function align the labels as per the orientation of the line? If so, that is not what I need. The labels need to be straight. Also, I changed the lines to points and then tried the pointLabel function. However, it ignores all the points that are not mentioned in the argument of the function and still plots over them. Any workaround for this? Regards Dhiraj Khanna Mob:09873263331 2015-09-26 12:45 GMT+05:30 Oscar Perpi??n Lamigueiro : > Hi, > > You could try the `lineLabel` and `sp.lineLabel` functions of this same > package. > > Best. > > Oscar. > -- > Oscar Perpi??n Lamigueiro > Dpto. Ing. El?ctrica, Electr?nica, Autom?tica y F?sica Aplicada > Escuela T?cnica Superior de Ingenier?a y Dise?o Industrial > URL: http://oscarperpinan.github.io > [[alternative HTML version deleted]] From Roger.Bivand at nhh.no Sat Sep 26 19:29:09 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Sat, 26 Sep 2015 19:29:09 +0200 Subject: [R-sig-Geo] gIntersection returns error "TopologyException: no outgoing dirEdge found at" In-Reply-To: <5605AE04.9080602@uni-muenster.de> References: <5602DD15.8030109@nancy.inra.fr> <56052D2A.8060009@nancy.inra.fr> <56054216.7010107@uni-muenster.de> <5605A6A8.3080604@uni-muenster.de> <5605AE04.9080602@uni-muenster.de> Message-ID: On Fri, 25 Sep 2015, Edzer Pebesma wrote: > Trying to reduce the problem, it seems PostGIS thinks that polygons are > invalid for which R believes they are valid: > > postgis=# select ST_IsValid('MULTIPOLYGON( > postgis'# ((0 0, 0 10, 10 10, 10 0, 0 0)), > postgis'# ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry); > NOTICE: Self-intersection at or near point 0 0 > st_isvalid > ------------ > f > (1 row) > > postgis=# select ST_IsValid('POLYGON( > postgis'# (0 0, 0 10, 10 10, 10 0, 0 0), > postgis'# (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); > NOTICE: Self-intersection at or near point 0 0 > st_isvalid > ------------ > f > (1 row) > > but > >> library(rgeos) >> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >> >> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >> MyLay=SpatialPolygons(list(Pols1,Pols2)) >> gIsValid(MyLay) > [1] TRUE > > Maybe gUnaryUnion-ing MultiPolygons before intersecting when byid = > FALSE is not such a bad idea after all? > Commited to R-forge as revision 505, seems to address the case, please check. The fix doesn't branch on geometry types, could those affected please check whether this leads to regressions? Roger > > On 25/09/15 21:55, Edzer Pebesma wrote: >> Thanks Vijay; FYI, following OP's example, I see in PostGIS: >> >> SELECT ST_AsText(ST_Intersection( >> 'MULTIPOLYGON( >> ((0 0, 0 10, 10 10, 10 0, 0 0)), >> ((0 0, 10 0, 10 -10, 0 -10, 0 0)))'::geometry, >> 'MULTIPOLYGON( >> ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), >> ((0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5)))'::geometry >> )); >> >> giving: >> >> ERROR: Error performing intersection: TopologyException: Input geom 0 >> is invalid: Self-intersection at or near point 0 0 at 0 0 >> >> but >> >> SELECT ST_AsText(ST_Intersection( >> 'MULTIPOLYGON( >> ((0 0, 0 10, 10 10, 10 0, 0 0)), >> ((0 -1, 10 -1, 10 -10, 0 -10, 0 -1)))'::geometry, >> 'MULTIPOLYGON( >> ((0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5)), >> ((0.5 0.0, 10.5 0.0, 10.5 -10.5, 0.5 -10.5, 0.5 0.0)))'::geometry >> )); >> >> giving no error; when I try >> >> SELECT ST_AsText(ST_Intersection( >> 'POLYGON( >> (0 0, 0 10, 10 10, 10 0, 0 0), >> (0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry, >> 'POLYGON( >> (0.5 0.5, 0.5 10.5, 10.5 10.5, 10.5 0.5, 0.5 0.5), >> (0.5 0.5, 10.5 0.5, 10.5 -10.5, 0.5 -10.5, 0.5 0.5))'::geometry >> )); >> >> it gives the same error as the first example. >> >> >> >> On 25/09/15 19:44, Roger Bivand wrote: >>> On Fri, 25 Sep 2015, Vijay Lulla wrote: >>> >>>> Seems to be working in PostGIS! Below is from my PostGIS session: >>>> >>>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>>> st_intersects >>>> --------------- >>>> t >>>> (1 row) >>>> >>>> >>>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 10, 10 10, 10 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 10 0, 10 -10, 0 -10, 0 0))'::geometry); >>>> st_intersection >>>> ------------------------------------------------------------------------------------ >>>> >>>> 0102000000020000000000000000002440000000000000000000000000000000000000000000000000 >>>> >>>> (1 row) >>>> >>>> gisdb=# SELECT ST_Intersection('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>>> st_intersection >>>> ------------------------------------------------------------------------------------ >>>> >>>> 010200000002000000000000000000F03F000000000000000000000000000000000000000000000000 >>>> >>>> (1 row) >>> >>> Thanks for this, but are these the same - that is each geometry >>> collection consists of two touching squares, but the second is offset >>> =.1 North Eastwards? In any case, very grateful that you took a look! >>> >>> Roger >>> >>>> >>>> >>>> gisdb=# SELECT ST_Intersects('POLYGON((0 0, 0 1, 1 1, 1 0, 0 >>>> 0))'::geometry, 'POLYGON((0 0, 1 0, 1 -1, 0 -1, 0 0))'::geometry); >>>> st_intersects >>>> --------------- >>>> t >>>> (1 row) >>>> >>>> gisdb=# select postgis_version(); >>>> postgis_version >>>> --------------------------------------- >>>> 2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 >>>> (1 row) >>>> >>>> >>>> gisdb=# select postgis_full_version(); >>>> >>>> postgis_full_vers >>>> ion >>>> ------------------------------------------------------------------------------------------ >>>> >>>> ---------------------------------------------------------------------------- >>>> >>>> POSTGIS="2.1.7 r13414" GEOS="3.4.2-CAPI-1.8.2 r3924" PROJ="Rel. >>>> 4.8.0, 6 March 2012" GDAL >>>> ="GDAL 1.11.1, released 2014/09/24" LIBXML="2.7.8" LIBJSON="UNKNOWN" >>>> RASTER >>>> (1 row) >>>> >>>> On Fri, Sep 25, 2015 at 1:02 PM, Roger Bivand >>>> wrote: >>>>> On Fri, 25 Sep 2015, Edzer Pebesma wrote: >>>>> >>>>>> >>>>>> >>>>>> On 25/09/15 14:36, Roger Bivand wrote: >>>>>>> >>>>>>> On Fri, 25 Sep 2015, Roger Bivand wrote: >>>>>>> >>>>>>>> On Fri, 25 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>> >>>>>>> ... >>>>>>>>> >>>>>>>>> >>>>>>>>> library(sp) >>>>>>>>> library(rgeos) >>>>>>>>> >>>>>>>>> #build a first polygon, MyLay, composed of two adjacent squares, >>>>>>>>> size >>>>>>>>> 1x1: >>>>>>>>> >>>>>>>>> Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0)) >>>>>>>>> Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0)) >>>>>>> >>>>>>> >>>>>>> Changing Pol1 and Pol2 by * 5, and the increment below to 0.5 gives >>>>>>> the >>>>>>> earlier: >>>>>>> >>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>> >>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, >>>>>>> "rgeos_intersection") : >>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>> >>>>>>> so this is another rendering of the original edge case in GEOS in this >>>>>>> thread. The practical resolution is to run gUnaryUnion() on the >>>>>>> objects >>>>>>> when byid=FALSE and the required output is a single (possibly >>>>>>> multipart) >>>>>>> geometry containing the whole intersection. >>>>>>> >>>>>>> Should we consider using gUnaryUnion() by default if byid for the >>>>>>> object >>>>>>> is FALSE, but permit users to choose not to do this? >>>>>> >>>>>> >>>>>> Has someone tried to reproduce this with GEOS, without R, e.g. by a >>>>>> PostGIS query? >>>>> >>>>> >>>>> Do you have a running PostGIS instance - I don't. I did try v.overlay in >>>>> GRASS, but it isn't GEOS-based, and returns the correct answer for >>>>> byid=c(TRUE, TRUE) so like rgeos in the same setting. I'm >>>>> re-installing GEOS >>>>> with Python, but someone else should check (my GEOS 3.5.0). >>>>> >>>>> Roger >>>>> >>>>> >>>>>> >>>>>>> >>>>>>> Roger >>>>>>> >>>>>>>>> >>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>> >>>>>>>>> #build a second polygon, MyLayl, composed of the same two squares >>>>>>>>> lagged by 0.1 in x and y directions: >>>>>>>>> >>>>>>>>> Pol1l=Pol1+0.1 >>>>>>>>> Pol2l=Pol2+0.1 >>>>>>>>> >>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>> >>>>>>>>> #view the resulting spatial layers: >>>>>>>>> >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> >>>>>>>>> #"successful" intersection: >>>>>>>>> >>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>> >>>>>>>> >>>>>>>> You did not follow my advice to put the objects into gUnaryUnion() >>>>>>>> first, to remove the problem. It isn't obvious where this problem is >>>>>>>> coming from, but most likely requires debugging in GEOS itself. >>>>>>>> >>>>>>>>> >>>>>>>>> #but false result: the intersection gives the same contour as MyLay! >>>>>>>>> >>>>>>>>> plot(MyLay) >>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>> plot(inter,col="red",add=TRUE) >>>>>>>>> >>>>>>>>> I use R version 3.2.2, rgeos_0.3-12 and sp_1.2-0. >>>>>>>>> >>>>>>>>> If such an error occurs when crossing larger spatial layers, it will >>>>>>>>> remain undetectable. >>>>>>>>> >>>>>>>>> If I am not wrong, it implies that this software is not very >>>>>>>>> reliable. Especially when considering that byid=FALSE is the default >>>>>>>>> option. >>>>>>>>> >>>>>>>>> gIntersection gives a correct result using the option byid=TRUE. >>>>>>>> >>>>>>>> >>>>>>>> This was not what you said you wanted, which was the (single) object >>>>>>>> for which MyLay intersected MyLayl. >>>>>>>> >>>>>>>>> The intersect function of the raster package also gives a correct >>>>>>>>> intersection. Do you think this latter function could be a better >>>>>>>>> option, in general? >>>>>>>>> >>>>>>>> >>>>>>>> No, not at all. If you inspect it, you'll see that it simply tries to >>>>>>>> "help" users by trying to guess which "data" slot elements might be >>>>>>>> copied across. It also calls gIntersect() in dense mode, which will >>>>>>>> choke on intersections between objects with many geometries. It runs >>>>>>>> gIntersection(..., byid=TRUE), so adds little to just doing that. >>>>>>>> >>>>>>>> See: >>>>>>>> >>>>>>>> library(rgdal) >>>>>>>> getMethod("intersect", c("SpatialPolygons", "SpatialPolygons")) >>>>>>>> >>>>>>>> Hope this clarifies, >>>>>>>> >>>>>>>> Roger >>>>>>>> >>>>>>>>> Thanks in advance, >>>>>>>>> >>>>>>>>> Jean-Luc Dupouey >>>>>>>>> >>>>>>>>> INRA >>>>>>>>> Forest Ecology & Ecophysiology Unit >>>>>>>>> F-54280 Champenoux >>>>>>>>> France >>>>>>>>> mail: dupouey at nancy.inra.fr >>>>>>>>> >>>>>>>>> Le 23/09/2015 19:39, Roger Bivand a ?crit : >>>>>>>>>> >>>>>>>>>> On Wed, 23 Sep 2015, Jean-Luc Dupouey wrote: >>>>>>>>>> >>>>>>>>>>> Why gIntersection returns the ""TopologyException: no outgoing >>>>>>>>>>> dirEdge found at" error in the following very simple case: >>>>>>>>>>> >>>>>>>>>>>> #construct a spatial layer with two adjacent squares, each of >>>>>>>>>>>> 10 x >>>>>>>>>>>> 10 >>>>>>>>>>> >>>>>>>>>>> units: >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>>>> >>>>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>>>> >>>>>>>>>>>> #construct the same layer, but lagged by 0.5 in x and y >>>>>>>>>>>> directions >>>>>>>>>>>> >>>>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>>>> >>>>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>>>> >>>>>>>>>>>> #view the resulting spatial layers: >>>>>>>>>>>> >>>>>>>>>>>> plot(MyLay) >>>>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>>>> >>>>>>>>>>>> #try to intersect: >>>>>>>>>>>> >>>>>>>>>>>> inter=gIntersection(MyLay,MyLayl) >>>>>>>>>>> >>>>>>>>>>> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, >>>>>>>>>>> drop_lower_td, >>>>>>>>>>> "rgeos_intersection") : >>>>>>>>>>> TopologyException: no outgoing dirEdge found at 0.5 0 >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> The error message is coming from GEOS - you are welcome to >>>>>>>>>> investigate >>>>>>>>>> further. If you use gUnaryUnion() on the objects first, there is no >>>>>>>>>> error: >>>>>>>>>> >>>>>>>>>> library(rgeos) >>>>>>>>>> Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0)) >>>>>>>>>> Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0)) >>>>>>>>>> library(sp) >>>>>>>>>> Pols1=Polygons(list(Polygon(Pol1)),"Pols1") >>>>>>>>>> Pols2=Polygons(list(Polygon(Pol2)),"Pols2") >>>>>>>>>> MyLay=SpatialPolygons(list(Pols1,Pols2)) >>>>>>>>>> Pol1l=Pol1+0.5 >>>>>>>>>> Pol2l=Pol2+0.5 >>>>>>>>>> Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l") >>>>>>>>>> Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l") >>>>>>>>>> MyLayl=SpatialPolygons(list(Pols1l,Pols2l)) >>>>>>>>>> plot(MyLay) >>>>>>>>>> plot(MyLayl,add=TRUE) >>>>>>>>>> points(x=0.5, y=0) >>>>>>>>>> inter=gIntersection(gUnaryUnion(MyLay), gUnaryUnion(MyLayl)) >>>>>>>>>> plot(inter, add=TRUE, border="green") >>>>>>>>>> >>>>>>>>>> It is a GEOS issue, not rgeos. >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> It works with the option byid=TRUE. >>>>>>>>>>> >>>>>>>>>>> But my question is why it does not work without? Is this behaviour >>>>>>>>>>> predictable? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> This is unknown. I'll try again on GEOS 3.5.0 and see if it is >>>>>>>>>> still >>>>>>>>>> there: yes, unfortunately it is still there. >>>>>>>>>> >>>>>>>>>> Roger >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> I went through some previous related posts to the list, but >>>>>>>>>>> could not >>>>>>>>>>> find the answer. >>>>>>>>>>> >>>>>>>>>>> Thanks, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> R-sig-Geo mailing list >>>>>>>>> R-sig-Geo at r-project.org >>>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> R-sig-Geo mailing list >>>>>>> R-sig-Geo at r-project.org >>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>>> Roger Bivand >>>>> Department of Economics, Norwegian School of Economics, >>>>> Helleveien 30, N-5045 Bergen, Norway. >>>>> voice: +47 55 95 93 55; fax +47 55 95 91 00 >>>>> e-mail: Roger.Bivand at nhh.no >>>>> >>>>> _______________________________________________ >>>>> R-sig-Geo mailing list >>>>> R-sig-Geo at r-project.org >>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >>>>> >>>> >>> >> >> >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > > -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From Roger.Bivand at nhh.no Sat Sep 26 19:47:18 2015 From: Roger.Bivand at nhh.no (Roger Bivand) Date: Sat, 26 Sep 2015 19:47:18 +0200 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings In-Reply-To: References: <87pp15bqiq.fsf@upm.es> Message-ID: On Sat, 26 Sep 2015, Dhiraj Khanna wrote: > Thank you Oscar for the reply. Will try as you suggest. However, must admit > that I am quite a noob when it comes to plotting. Was looking at your > lineLabel() function and couldn't figure out what a "list of lines" is. > Anyway, will struggle a little and do my homework. Just one question > though. Will using the lineLabel function align the labels as per the > orientation of the line? If so, that is not what I need. The labels need to > be straight. > > Also, I changed the lines to points and then tried the pointLabel function. > However, it ignores all the points that are not mentioned in the argument > of the function and still plots over them. Any workaround for this? Maybe also see rgeos::polygonsLabel(), by Karl Ove Hufthammer, to compute optimal label positions for polygons - if your background data can be represented as a SpatialPolygons object. Roger > > Regards > > Dhiraj Khanna > Mob:09873263331 > > 2015-09-26 12:45 GMT+05:30 Oscar Perpi??n Lamigueiro > : > >> Hi, >> >> You could try the `lineLabel` and `sp.lineLabel` functions of this same >> package. >> >> Best. >> >> Oscar. >> -- >> Oscar Perpi??n Lamigueiro >> Dpto. Ing. El?ctrica, Electr?nica, Autom?tica y F?sica Aplicada >> Escuela T?cnica Superior de Ingenier?a y Dise?o Industrial >> URL: http://oscarperpinan.github.io >> > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 91 00 e-mail: Roger.Bivand at nhh.no From oscar.perpinan at upm.es Sun Sep 27 18:28:22 2015 From: oscar.perpinan at upm.es (Oscar =?utf-8?B?UGVycGnDscOhbg==?= Lamigueiro) Date: Sun, 27 Sep 2015 18:28:22 +0200 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings In-Reply-To: (Dhiraj Khanna's message of "Sat, 26 Sep 2015 20:45:30 +0530") References: <87pp15bqiq.fsf@upm.es> Message-ID: <87fv1zx1w9.fsf@upm.es> > Will using the lineLabel function align the labels as per the > orientation of the line? Yes, exactly. > Also, I changed the lines to points and then tried the pointLabel > function. However, it ignores all the points that are not mentioned > in the argument of the function and still plots over them. Any > workaround for this? You may include empty characters ("") as elements in the _labels_ vector. For example: x <- 1:5 y <- 1:5 labels <- c('A', 'B', '', 'D', '') plot(x, y) pointLabel(x, y, labels) Best. Oscar. -- Oscar Perpi??n Lamigueiro Dpto. Ing. El?ctrica, Electr?nica, Autom?tica y F?sica Aplicada Escuela T?cnica Superior de Ingenier?a y Dise?o Industrial URL: http://oscarperpinan.github.io From dhirajkhanna at gmail.com Mon Sep 28 14:46:22 2015 From: dhirajkhanna at gmail.com (Dhiraj Khanna) Date: Mon, 28 Sep 2015 18:16:22 +0530 Subject: [R-sig-Geo] Help on pointLabel() function for engineering drawings In-Reply-To: <87fv1zx1w9.fsf@upm.es> References: <87pp15bqiq.fsf@upm.es> <87fv1zx1w9.fsf@upm.es> Message-ID: Oscar, I did as you suggested by putting ?? for labels that I didn?t want. However, the labels still overlap the drawing :( Here is my code: library(dplyr)library(maptools)#Known Size of Sheet xmin <- -357.7 xmax <- 19.3 ymin <- -90.2 ymax <- 159.7 #Read in the data linescoords <- read.csv("Linecoords.csv") #Coordinates translation linescoords$X <- linescoords$X - xmin linescoords$Y <- linescoords$Y - ymin # Plot the figure xlimit <- c(-10, abs(xmin-xmax)+10 ) ylimit <- c(-10, abs(ymin-ymax)+10 ) plot(linescoords$X, linescoords$Y, "p", xlim=xlimit, ylim = ylimit) i <- seq(1, nrow(linescoords), 2)for(x in i){ segments(linescoords$X[x], linescoords$Y[x], linescoords$X[x+1], linescoords$Y[x+1]) } #Read in text labels data labels <- read.csv("labels.csv") #Text labels Coordinates translation labels$x <- labels$x - xmin labels$y <- labels$y - ymin labels$xminl <- labels$xminl - xmin labels$xmaxl <- labels$xmaxl - xmin labels$yminl <- labels$yminl - ymin labels$ymaxl <- labels$ymaxl - ymin #Point of Origin for labels points(labels$x, labels$y, pch=16, col="red") #Width & Height of labels labels <- labels %>% mutate(width=abs(xminl-xmaxl), height=abs(yminl-ymaxl)) oddseq <- seq(1, nrow(linescoords),2) evenseq <- seq(2, nrow(linescoords),2) x1 <- linescoords$X[oddseq] y1 <- linescoords$Y[oddseq] x2 <- linescoords$X[evenseq] y2 <- linescoords$Y[evenseq] lineseg <- seq(1,length(x1)) lineslope <- as.data.frame(cbind(lineseg, x1, y1, x2, y2)) lineslope <- mutate(lineslope, slope=(y2-y1)/(x2-x1)) pointsx <- vector("list") pointsy <- vector("list")for (s in 1:nrow(lineslope)){ if(lineslope[s,2]==lineslope[s,4]){ louty <- abs(lineslope[s,3]-lineslope[s,5])/3 yp <- seq(lineslope[s,3], lineslope[s,5], length.out=louty) pointsy[[s]] <- yp xp <- seq(lineslope[s,2], lineslope[s,4], length.out=louty) pointsx[[s]] <- xp } else{ loutx <- abs(lineslope[s,2]-lineslope[s,4])/3 xp <- seq(lineslope[s,2], lineslope[s,4], length.out=loutx) pointsx[[s]] <- xp yp <- seq(lineslope[s,3], lineslope[s,5], length.out=loutx) pointsy[[s]] <- yp } } finalx <- unlist(pointsx) finaly <- unlist(pointsy) extralabels <- vector("character", length=length(finalx)) labelsfinal <- append(as.character(labels$Point), extralabels) X <- append(labels$x, finalx) Y <- append(labels$y, finaly) plot(finalx, finaly, "p") pointLabel(X, Y, labelsfinal) points(labels$x, labels$y, pch=16, col="red") ? Regards Dhiraj Khanna Mob:09873263331 On Sun, Sep 27, 2015 at 9:58 PM, Oscar Perpi??n Lamigueiro < oscar.perpinan at upm.es> wrote: > > Will using the lineLabel function align the labels as per the > > orientation of the line? > > Yes, exactly. > > > Also, I changed the lines to points and then tried the pointLabel > > function. However, it ignores all the points that are not mentioned > > in the argument of the function and still plots over them. Any > > workaround for this? > > You may include empty characters ("") as elements in the _labels_ > vector. For example: > > x <- 1:5 > y <- 1:5 > labels <- c('A', 'B', '', 'D', '') > plot(x, y) > pointLabel(x, y, labels) > > Best. > > Oscar. > > -- > Oscar Perpi??n Lamigueiro > Dpto. Ing. El?ctrica, Electr?nica, Autom?tica y F?sica Aplicada > Escuela T?cnica Superior de Ingenier?a y Dise?o Industrial > URL: http://oscarperpinan.github.io > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: TextboxImage.png Type: image/png Size: 6675 bytes Desc: not available URL: From Raphael.Huerlimann at gmx.ch Mon Sep 28 14:53:50 2015 From: Raphael.Huerlimann at gmx.ch (=?UTF-8?Q?=22Raphael_H=C3=BCrlimann=22?=) Date: Mon, 28 Sep 2015 14:53:50 +0200 Subject: [R-sig-Geo] GSIF Message-ID: An HTML attachment was scrubbed... URL: From monika.novac at gmail.com Mon Sep 28 19:13:57 2015 From: monika.novac at gmail.com (monika nov) Date: Mon, 28 Sep 2015 18:13:57 +0100 Subject: [R-sig-Geo] Function stslshac {sphet}: heteroskedasticity and autocorrelation consistent (HAC) estimator In-Reply-To: References: Message-ID: Dear Roger, Thank you for your reply. Finally I got reply from Harry Kelejian, the author of the paper referred to in R help for the function stslshac and also the author of the paper you are referring to. His response was: 'The HAC estimator allows for spatial correlation , as well as heteroskedasticity. There is no need to test for spatial correlation or heteroskedasticity. when using the HAC.' Which answered my question and made this issue clear for me. Regarding your reference, the answer may be implied in the paper, however I would need to spend quite long time studying it to understand it and unfortunately I am quite busy at the moment. Thank you for willingness to help anyway. Monika On 21 September 2015 at 17:04, Roger Bivand wrote: > On Sat, 19 Sep 2015, monika nov wrote: > >> Dear R-users, >> >> I have quite basic question for econometricians, however I would like >> to be sure in this. >> >> If I use a HAC estimator of the variance-covariance (VC) matrix for a >> spatial econometric model, do I still need to test the residuals for >> spatial autocorrelation and heteroscedasticity? (in particular I am >> using function stslshac available in package sphet. The estimator is >> based on Kelejian, H.H. and Prucha, I.R. (2007) HAC estimation in a >> spatial framework, Journal of Econometrics, 140, pages 131?154). >> >> What if the residuals from model estimated by stslshac are spatially >> autocorrelated and (or) heteroscedastic? Can I still use this >> estimator with HAC estimate of VC matrix or shall I go for different >> estimator or specification? Do the estimates have required properties >> (are they unbiased, consistent, efficient)? I would be grateful for >> any reaction. > > > Does this reference throw any light on the question? I'm not aware of > implementations: > > @article{ > year={2015}, > issn={1864-4031}, > journal={Letters in Spatial and Resource Sciences}, > doi={10.1007/s12076-015-0146-2}, > title={Critical issues in spatial models: error term specifications, > additional endogenous variables, pre-testing, and Bayesian analysis}, > url={http://dx.doi.org/10.1007/s12076-015-0146-2}, > publisher={Springer Berlin Heidelberg}, > keywords={Specifications of spatial models; Additional endogenous variables; > Pre-testing; Bayesian analysis; C01; C12; C13}, > author={Kelejian, HarryH.}, > pages={1-24}, > language={English} > } > > Roger > >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > -- > Roger Bivand > Department of Economics, Norwegian School of Economics, > Helleveien 30, N-5045 Bergen, Norway. > voice: +47 55 95 93 55; fax +47 55 95 91 00 > e-mail: Roger.Bivand at nhh.no From aolinto.lst at gmail.com Tue Sep 29 21:57:19 2015 From: aolinto.lst at gmail.com (Antonio Silva) Date: Tue, 29 Sep 2015 16:57:19 -0300 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R In-Reply-To: References: Message-ID: Hello, Some weeks ago I wrote to this list asking about available methods to extract sst and chlorophyll concentration data from hdf files. After some work and much reading I wrote two scripts (see below) to do the job in batch mode, they are very similar. I began to use nc files. I hope it is useful for other. Please let me know if there are any error or inconsistency. Suggestions for improvement are welcome. Regards Antonio Olinto *SST===* # Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil # script to process Aqua MODIS Sea Surface Temperature # Monthly means 9 km resolution # files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3 # all .L3m_MO_SST_sst_9km.nc files must be in the working directory # the script will open each nc file, read lon, lat and sst data, # select data from a specific area and write them into # a single csv file named MODISA_sst.csv # Some reference pages # http://geog.uoregon.edu/GeogR/topics/netCDF-read-ncdf4.html # https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ # load libraries # ncdf4 needs libnetcdf-dev netcdf-bin in Linux # install.packages(c("ncdf4","reshape2")) library("ncdf4") library("reshape2") # set working directory setwd("/mnt/Dados02/MODIS/SST") # indicate the path to the files file.exists("MODISA_sst.csv") # caution new data will be appended to this file if it already exists # file.rename("MODISA_sst.csv","MODISA_sst.old") # file.remove("MODISA_sst.csv") # list and remove objects ls() rm(list = ls()) # set the study area lonmax<--40 lonmin<--50 latmax<--22 latmin<--29 # create a list of files and indicate its length (f <- list.files(".", pattern="*.L3m_MO_SST_sst_9km.nc",full.names=F)) (lf<-length(f)) # variable var<-"sst" for (i in 1:lf) { # progress indicator print(paste("Processing file",i,"from",length(f),sep=" ")) # open netCDF file data<-nc_open(f) # extract data lon<-ncvar_get(data,"lon") lat<-ncvar_get(data,"lat") value<-ncvar_get(data,var) unit<-ncatt_get(data,var,"units")$value # matrix to data.frame dimnames(value)<-list(lon=lon,lat=lat) dat.var<-melt(value,id="lon") # select data from the study area taking out missing data dat.varSAtmp<-subset(dat.var,lon<=lonmax & lon>=lonmin & lat<=latmax & lat>=latmin & value<45) # extract date information dateini<-ncatt_get(data,0,"time_coverage_start")$value dateend<-ncatt_get(data,0,"time_coverage_end")$value datemean<-mean(c(as.Date(dateend,"%Y-%m-%dT%H:%M:%OSZ"),as.Date(dateini,"%Y-%m-%dT%H:%M:%OSZ"))) year<-substring(datemean,0,4) month<-substring(datemean,6,7) # prepare final data set dat.varSA<-data.frame(rep(as.integer(year,nrow(dat.varSAtmp))),rep(as.integer(month,nrow(dat.varSAtmp))), dat.varSAtmp,rep(unit,nrow(dat.varSAtmp)),rep(var,nrow(dat.varSAtmp))) names(dat.varSA)<-c("year","month","lon","lat","value","unit","var") # save csv file fe<-file.exists("MODISA_sst.csv") write.table(dat.varSA,"MODISA_sst.csv",row.names=FALSE,col.names=!fe,sep=";",dec=",",append=fe) # close connection nc_close(data) # clean workspace rm(data,lon,lat,value,unit,dat.var,dat.varSAtmp,dateini,dateend,datemean,year,month,dat.varSA,fe) } rm(var,f,i,latmax,latmin,lf,lonmax,lonmin) *CHL_a=====* # Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil # script to process Aqua MODIS Chlorophyll Concentration OCx Algorithm # Monthly means 9 km resolution # see http://oceancolor.gsfc.nasa.gov/WIKI/OCChlOCI.html # files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3 # all .L3m_MO_CHL_chlor_a_9km.nc files must be in the working directory # the script will open each nc file, read lon, lat and chl data, # select data from a specific area and write them into # a single csv file named MODISA_chl.csv # Some reference pages # http://geog.uoregon.edu/GeogR/topics/netCDF-read-ncdf4.html # https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ # load libraries # ncdf4 needs libnetcdf-dev netcdf-bin in Linux # install.packages(c("ncdf4","reshape2")) library("ncdf4") library("reshape2") # set working directory setwd("/mnt/Dados02/MODIS/CHL") # indicate the path to the files file.exists("MODISA_chl.csv") # caution new data will be appended to this file if it already exists # file.rename("MODISA_chl.csv","MODISA_chl.old") # file.remove("MODISA_chl.csv") # list and remove objects ls() rm(list = ls()) # set the study area lonmax<--40 lonmin<--50 latmax<--22 latmin<--29 # create a list of files and indicate its length (f <- list.files(".", pattern="*.L3m_MO_CHL_chlor_a_9km.nc",full.names=F)) (lf<-length(f)) # variable var<-"chlor_a" for (i in 1:lf) { # progress indicator print(paste("Processing file",i,"from",length(f),sep=" ")) # open netCDF file data<-nc_open(f) # extract data lon<-ncvar_get(data,"lon") lat<-ncvar_get(data,"lat") value<-ncvar_get(data,var) unit<-ncatt_get(data,var,"units")$value # matrix to data.frame dimnames(value)<-list(lon=lon,lat=lat) dat.var<-melt(value,id="lon") # select data from the study area taking out missing data dat.varSAtmp<-na.omit(subset(dat.var,lon<=lonmax & lon>=lonmin & lat<=latmax & lat>=latmin)) # extract date information dateini<-ncatt_get(data,0,"time_coverage_start")$value dateend<-ncatt_get(data,0,"time_coverage_end")$value datemean<-mean(c(as.Date(dateend,"%Y-%m-%dT%H:%M:%OSZ"),as.Date(dateini,"%Y-%m-%dT%H:%M:%OSZ"))) year<-substring(datemean,0,4) month<-substring(datemean,6,7) # prepare final data set dat.varSA<-data.frame(rep(as.integer(year,nrow(dat.varSAtmp))),rep(as.integer(month,nrow(dat.varSAtmp))), dat.varSAtmp,rep(unit,nrow(dat.varSAtmp)),rep(var,nrow(dat.varSAtmp))) names(dat.varSA)<-c("year","month","lon","lat","value","unit","var") # save csv file fe<-file.exists("MODISA_chl.csv") write.table(dat.varSA,"MODISA_chl.csv",row.names=FALSE,col.names=!fe,sep=";",dec=",",append=fe) # close connection nc_close(data) # clean workspace rm(data,lon,lat,value,unit,dat.var,dat.varSAtmp,dateini,dateend,datemean,year,month,dat.varSA,fe) } rm(var,f,i,latmax,latmin,lf,lonmax,lonmin) [[alternative HTML version deleted]] From jstachel at sfwmd.gov Tue Sep 29 22:41:23 2015 From: jstachel at sfwmd.gov (Stachelek, Joseph) Date: Tue, 29 Sep 2015 20:41:23 +0000 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R In-Reply-To: References: Message-ID: Hi Antonio, My suggestion would be turn your scripts into Github "gists" so they could be more widely accessible. https://gist.github.com/ Joseph Stachelek -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Antonio Silva Sent: Tuesday, September 29, 2015 3:57 PM Cc: r-sig-geo at r-project.org Subject: Re: [R-sig-Geo] SST and chlorophyll data extraction in R Hello, Some weeks ago I wrote to this list asking about available methods to extract sst and chlorophyll concentration data from hdf files. After some work and much reading I wrote two scripts (see below) to do the job in batch mode, they are very similar. I began to use nc files. I hope it is useful for other. Please let me know if there are any error or inconsistency. Suggestions for improvement are welcome. Regards Antonio Olinto *SST===* # Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil # script to process Aqua MODIS Sea Surface Temperature # Monthly means 9 km resolution # files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3 # all .L3m_MO_SST_sst_9km.nc files must be in the working directory # the script will open each nc file, read lon, lat and sst data, # select data from a specific area and write them into # a single csv file named MODISA_sst.csv # Some reference pages # http://geog.uoregon.edu/GeogR/topics/netCDF-read-ncdf4.html # https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ # load libraries # ncdf4 needs libnetcdf-dev netcdf-bin in Linux # install.packages(c("ncdf4","reshape2")) library("ncdf4") library("reshape2") # set working directory setwd("/mnt/Dados02/MODIS/SST") # indicate the path to the files file.exists("MODISA_sst.csv") # caution new data will be appended to this file if it already exists # file.rename("MODISA_sst.csv","MODISA_sst.old") # file.remove("MODISA_sst.csv") # list and remove objects ls() rm(list = ls()) # set the study area lonmax<--40 lonmin<--50 latmax<--22 latmin<--29 # create a list of files and indicate its length (f <- list.files(".", pattern="*.L3m_MO_SST_sst_9km.nc",full.names=F)) (lf<-length(f)) # variable var<-"sst" for (i in 1:lf) { # progress indicator print(paste("Processing file",i,"from",length(f),sep=" ")) # open netCDF file data<-nc_open(f) # extract data lon<-ncvar_get(data,"lon") lat<-ncvar_get(data,"lat") value<-ncvar_get(data,var) unit<-ncatt_get(data,var,"units")$value # matrix to data.frame dimnames(value)<-list(lon=lon,lat=lat) dat.var<-melt(value,id="lon") # select data from the study area taking out missing data dat.varSAtmp<-subset(dat.var,lon<=lonmax & lon>=lonmin & lat<=latmax & lat>=latmin & value<45) # extract date information dateini<-ncatt_get(data,0,"time_coverage_start")$value dateend<-ncatt_get(data,0,"time_coverage_end")$value datemean<-mean(c(as.Date(dateend,"%Y-%m-%dT%H:%M:%OSZ"),as.Date(dateini,"%Y-%m-%dT%H:%M:%OSZ"))) year<-substring(datemean,0,4) month<-substring(datemean,6,7) # prepare final data set dat.varSA<-data.frame(rep(as.integer(year,nrow(dat.varSAtmp))),rep(as.integer(month,nrow(dat.varSAtmp))), dat.varSAtmp,rep(unit,nrow(dat.varSAtmp)),rep(var,nrow(dat.varSAtmp))) names(dat.varSA)<-c("year","month","lon","lat","value","unit","var") # save csv file fe<-file.exists("MODISA_sst.csv") write.table(dat.varSA,"MODISA_sst.csv",row.names=FALSE,col.names=!fe,sep=";",dec=",",append=fe) # close connection nc_close(data) # clean workspace rm(data,lon,lat,value,unit,dat.var,dat.varSAtmp,dateini,dateend,datemean,year,month,dat.varSA,fe) } rm(var,f,i,latmax,latmin,lf,lonmax,lonmin) *CHL_a=====* # Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil # script to process Aqua MODIS Chlorophyll Concentration OCx Algorithm # Monthly means 9 km resolution # see http://oceancolor.gsfc.nasa.gov/WIKI/OCChlOCI.html # files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3 # all .L3m_MO_CHL_chlor_a_9km.nc files must be in the working directory # the script will open each nc file, read lon, lat and chl data, # select data from a specific area and write them into # a single csv file named MODISA_chl.csv # Some reference pages # http://geog.uoregon.edu/GeogR/topics/netCDF-read-ncdf4.html # https://scottishsnow.wordpress.com/2014/08/24/many-rastered-beast/ # load libraries # ncdf4 needs libnetcdf-dev netcdf-bin in Linux # install.packages(c("ncdf4","reshape2")) library("ncdf4") library("reshape2") # set working directory setwd("/mnt/Dados02/MODIS/CHL") # indicate the path to the files file.exists("MODISA_chl.csv") # caution new data will be appended to this file if it already exists # file.rename("MODISA_chl.csv","MODISA_chl.old") # file.remove("MODISA_chl.csv") # list and remove objects ls() rm(list = ls()) # set the study area lonmax<--40 lonmin<--50 latmax<--22 latmin<--29 # create a list of files and indicate its length (f <- list.files(".", pattern="*.L3m_MO_CHL_chlor_a_9km.nc",full.names=F)) (lf<-length(f)) # variable var<-"chlor_a" for (i in 1:lf) { # progress indicator print(paste("Processing file",i,"from",length(f),sep=" ")) # open netCDF file data<-nc_open(f) # extract data lon<-ncvar_get(data,"lon") lat<-ncvar_get(data,"lat") value<-ncvar_get(data,var) unit<-ncatt_get(data,var,"units")$value # matrix to data.frame dimnames(value)<-list(lon=lon,lat=lat) dat.var<-melt(value,id="lon") # select data from the study area taking out missing data dat.varSAtmp<-na.omit(subset(dat.var,lon<=lonmax & lon>=lonmin & lat<=latmax & lat>=latmin)) # extract date information dateini<-ncatt_get(data,0,"time_coverage_start")$value dateend<-ncatt_get(data,0,"time_coverage_end")$value datemean<-mean(c(as.Date(dateend,"%Y-%m-%dT%H:%M:%OSZ"),as.Date(dateini,"%Y-%m-%dT%H:%M:%OSZ"))) year<-substring(datemean,0,4) month<-substring(datemean,6,7) # prepare final data set dat.varSA<-data.frame(rep(as.integer(year,nrow(dat.varSAtmp))),rep(as.integer(month,nrow(dat.varSAtmp))), dat.varSAtmp,rep(unit,nrow(dat.varSAtmp)),rep(var,nrow(dat.varSAtmp))) names(dat.varSA)<-c("year","month","lon","lat","value","unit","var") # save csv file fe<-file.exists("MODISA_chl.csv") write.table(dat.varSA,"MODISA_chl.csv",row.names=FALSE,col.names=!fe,sep=";",dec=",",append=fe) # close connection nc_close(data) # clean workspace rm(data,lon,lat,value,unit,dat.var,dat.varSAtmp,dateini,dateend,datemean,year,month,dat.varSA,fe) } rm(var,f,i,latmax,latmin,lf,lonmax,lonmin) [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo We value your opinion. Please take a few minutes to shar...{{dropped:5}} From Navinder.Singh at slu.se Wed Sep 30 01:24:51 2015 From: Navinder.Singh at slu.se (Navinder Singh) Date: Tue, 29 Sep 2015 23:24:51 +0000 Subject: [R-sig-Geo] Levelplot (raster) and xyplot (SpatialPoints) together with both legends in a single plot Message-ID: <65333A28-B729-4729-ADCC-AAEAAEC7FC94@slu.se> Hi List, I am trying to overlay a xyplot of spatialpoints on top of a level plot of a raster stack. My code looks like : >p<-levelplot(allYrStack.diff,layout=c(6,2),main="Differences", par.settings=RdBuTheme) # allYrStack.diff is a raster stack >striptext = factor(inds.mig$month, levels = unique(inds.mig$month)) >p+xyplot(y~x|striptext,groups=COUNTRY, type="o",data = inds.mig, pch = 20, size=0.2, colour = inds.mig$id,alpha=0.5) # y=y coordinate, x=xcoordinate, etc..Country is a fatcor variable which can have 10 levels. so is the id variable. I now intend to have both the legends on the plot (one for the continuous values from the raster and another for colour coded variable country with a line and a dot in the middle), but i am unable to add the legend of data plotted in the xyplot on the main plot. I understand that to get the legend of xyplot also, i should probably create an empty space first, and then add both the level plot and xyplot and their legends, so that i have space for both. However, my skills are failing me this time. Any suggestions are most helpful. Thanks and best wishes, Navi Navinder J Singh Associate Professor Department of Wildlife, Fish, and Environmental Studies Faculty of Forest Sciences Swedish University of Agricultural Sciences SE-901 83 Umea, Sweden O: +46 (0)90 786 8538; M: +46 (0)70 676 0103 email: navinder.singh at slu.se Web: navinderjsingh.weebly.com www.slu.se/viltfiskmiljo/navinder_singh http://slu-se.academia.edu/NSingh Moose Work: http://moose-research.se/ Golden Eagles: http://www.goldeneaglesweden.com/ Beyond Moose: http://wildsamm.weebly.com/ [[alternative HTML version deleted]] From aolinto.lst at gmail.com Wed Sep 30 15:48:59 2015 From: aolinto.lst at gmail.com (Antonio Silva) Date: Wed, 30 Sep 2015 10:48:59 -0300 Subject: [R-sig-Geo] SST and chlorophyll data extraction in R In-Reply-To: References: Message-ID: Thanks Joseph, they are already there. https://gist.github.com/aolinto/79e184f6c156c6ab21b3 https://gist.github.com/aolinto/436d9d69798dd95e5ab0 Regards AO 2015-09-29 17:41 GMT-03:00 Stachelek, Joseph : > Hi Antonio, > > My suggestion would be turn your scripts into Github "gists" so they could > be more widely accessible. > > https://gist.github.com/ > > Joseph Stachelek > [[alternative HTML version deleted]] From mmarsik at ufl.edu Wed Sep 30 16:49:13 2015 From: mmarsik at ufl.edu (Marsik,Matthew P) Date: Wed, 30 Sep 2015 14:49:13 +0000 Subject: [R-sig-Geo] Package MODIS error in runMrt( ) and getHdf - 'Problems with online connections try a little later' Message-ID: Hello I am having trouble running the function runMrt from the package MODIS. This was working as of last Friday morning, 25 Sept. I've done Google searches for help (https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=r-modis+%22Problems+with+online+connections%22), with no success. Any help would be appreciated! I have a time series of downloaded MODIS MOD13Q1 hdfs from 2000-2014 for tiles h=09-12, v=05-06 for the southeastern US and stored on a networked drive. I want to process them clipping to a spatial extent and project them into Albers USGS for the conterminous US with a pixel size of 250 meters. I've set my localArcPath to the networked drive containing the MOD13Q1 hdf files, and the outDirPath to my local computer's C drive. I've specified the following MODISoptions: MODIS:::MODISoptions(localArcPath = modis_archive_path, outDirPath = modis_out_path, systemwide=FALSE, save=FALSE, stubbornness=1) When I execute the following runMrt() function runMrt(job=job, product=product, begin=begin, end=end, localArcPath=modis_archive_path, outDirPath=modis_out_path, extent=extent(boundary), SDSstring=out_SDSstring, outProj='AEA', projPara='6378137.0 6356752.314140356 29.5 45.5 96.0 23.0 0 0 0 0 0 0 0 0 0', datum='NAD83', pixelSize=out_pixel, resamplingType=resample, stubbornness=stubbornness) I receive an error with getHdf noting there is an error with the online connection: Output projection: Albers Equal Area Output pixel size: 250 Resampling method: nn Output projection parameters specified! Using: 6378137.0 6356752.314140356 29.5 45.5 96.0 23.0 0 0 0 0 0 0 0 0 0 Error in MODIS:::getHdf(product = opts$product$PRODUCT[z], collection = strsplit(todo[u], : Problems with online connections try a little later In addition: Warning message: In dir.create(outDir) : 'R:\MACROS~1\Data\M2ENLS~L\M7L986~Z\data\M248XV~A\PMS9ML~B\\SEUS' already exists > [1] "Elapsed Time: 4.32000000000016 seconds" The following are my R session specifications: R version 3.1.1 (2014-07-10) Platform: x86_64-w64-mingw32/x64 (64-bit) RCurl_1.95-4.7 bitops_1.0-6 rgeos_0.3-11 rgdal_1.0-6 MODIS_0.10-18 raster_2.4-18 sp_1.1-1 regards, Matthew Marsik, PhD Research Scientist Land Use and Environmental Change Institute (LUECI) 3141 Turlington Hall Gainesville, FL 32611 Email: mmarsik at ufl.edu Tel: 352-294-7604 Web: lueci.clas.ufl.edu [[alternative HTML version deleted]] From pedroapablazabastias at gmail.com Wed Sep 30 17:18:19 2015 From: pedroapablazabastias at gmail.com (=?UTF-8?Q?Pedro_Apablaza_Bast=C3=ADas?=) Date: Wed, 30 Sep 2015 12:18:19 -0300 Subject: [R-sig-Geo] Package MODIS error in runMrt( ) and getHdf - 'Problems with online connections try a little later' In-Reply-To: References: Message-ID: good morning friends Dear : In summary , I have the following problem, I want to validate the spherical , exponential and gaussian semivariogram models for Which it has-been made ??a Box - Cox transformation to the original the data. Can anyone give me an example of how it Should write the script for the following example xvalid ??? variograma <- variog(D, max.dist=200, uvec=30, lambda=0.14146, estimator.type="modulus") ini.vals_amarillo <- expand.grid(seq(0, 120, by=0.25), seq(0, 40, by=0.2)) vario.wls <- variofit(variograma, ini = ini.vals_amarillo, cov.model = "spherical", fix.nugget = FALSE, nugget = 50, weights = "cressie") xv.wls <- xvalid(.......................................................) ################################################################################ he probado, pero ninguna de las siguientes lineas ha resultado, enuncio algunas de ellas: ?################################################################################ xv.wls1 <- xvalid(D, model = vario.wls) xv.wls1 <- xvalid(D, coords = D$coords, data = D$data, model = vario.wls) xv.wls1 <- xvalid(D, coords = D$coords, data = D$data+1, model = vario.wls) xv.wls1 <- xvalid(D, coords = D$coords, data = D$data+1, model = vario.wls, reestimate=true, +vario.obj=variograma) xv.wls1 <- xvalid(D, coords = D$coords, data = D$data+1, model = vario.wls, reestimate=true, +vario.obj=variograma), ini = ini.vals_amarillo, cov.model = "gaussian", fix.nugget = FALSE, nugget = 50, weights = "cressie") but does not run properly ################################################################################# All this led me to the following idea: ############################################################################################# if transform matrix D ( in other words, the data transformed by boxcox data = D$data and call the new matrix Dt then : variograma_t <- variog(Dt, max.dist=200, uvec=30, estimator.type="modulus") #### LA MATRIZ TRANSFORMADA It should be the same as: variograma <- variog(D, max.dist=200, uvec=30, lambda=0.14146, estimator.type="modulus") # LA MATRIZ ORIGINAL aplicando TRANSFORMACION BOX-COX but it turns out not, someone can explain me why ?????? l so that it would expect the following expressions give me the same result: vario.wls <- variofit(variograma, ini = ini.vals_amarillo, cov.model = "spherical", fix.nugget = FALSE, nugget = 50, weights = "cressie") vario.wls_t <- variofit(variograma_t, ini = ini.vals_amarillo, cov.model = "spherical", fix.nugget = FALSE, nugget = 50, weights = "cressie") I appreciate any feedback and help BEST REGARDS 2015-09-30 11:49 GMT-03:00 Marsik,Matthew P : > Hello > > I am having trouble running the function runMrt from the package MODIS. > This was working as of last Friday morning, 25 Sept. I've done Google > searches for help > ( > https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=r-modis+%22Problems+with+online+connections%22), > with no success. Any help would be appreciated! > > I have a time series of downloaded MODIS MOD13Q1 hdfs from 2000-2014 for > tiles h=09-12, v=05-06 for the southeastern US and stored on a networked > drive. I want to process them > clipping to a spatial extent and project them into Albers USGS for the > conterminous US with a pixel size of 250 meters. I've set my localArcPath > to the networked drive > containing the MOD13Q1 hdf files, and the outDirPath to my local > computer's C drive. I've specified the following MODISoptions: > > MODIS:::MODISoptions(localArcPath = modis_archive_path, outDirPath = > modis_out_path, systemwide=FALSE, save=FALSE, stubbornness=1) > > When I execute the following runMrt() function > > runMrt(job=job, product=product, > begin=begin, > end=end, > localArcPath=modis_archive_path, > outDirPath=modis_out_path, > extent=extent(boundary), > SDSstring=out_SDSstring, > outProj='AEA', > projPara='6378137.0 6356752.314140356 29.5 > 45.5 96.0 23.0 0 0 0 0 0 0 0 0 0', > datum='NAD83', > pixelSize=out_pixel, > resamplingType=resample, > stubbornness=stubbornness) > > I receive an error with getHdf noting there is an error with the online > connection: > > Output projection: Albers Equal Area > Output pixel size: 250 > Resampling method: nn > Output projection parameters specified! > Using: > 6378137.0 6356752.314140356 29.5 45.5 96.0 23.0 0 0 0 0 0 0 0 0 0 > Error in MODIS:::getHdf(product = opts$product$PRODUCT[z], collection = > strsplit(todo[u], : > Problems with online connections try a little later > In addition: Warning message: > In dir.create(outDir) : > 'R:\MACROS~1\Data\M2ENLS~L\M7L986~Z\data\M248XV~A\PMS9ML~B\\SEUS' > already exists > > [1] "Elapsed Time: 4.32000000000016 seconds" > > The following are my R session specifications: > > R version 3.1.1 (2014-07-10) > Platform: x86_64-w64-mingw32/x64 (64-bit) > RCurl_1.95-4.7 > bitops_1.0-6 > rgeos_0.3-11 > rgdal_1.0-6 > MODIS_0.10-18 > raster_2.4-18 > sp_1.1-1 > > regards, > > Matthew Marsik, PhD > Research Scientist > Land Use and Environmental > Change Institute (LUECI) > 3141 Turlington Hall > Gainesville, FL 32611 > Email: mmarsik at ufl.edu > Tel: 352-294-7604 > Web: lueci.clas.ufl.edu > > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo at r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Pedro Apablaza Bastias Oceanografo Pontificia Universidad de Valpara?so Master en Gesti?n de Areas Litorales Universidad de C?diz Espa?a Fono: 82960872 [[alternative HTML version deleted]]