?Dear all,
I have three shapefiles that I want to intersect. Any body with an idea on
how to do the intersection? Shapefiles below;
library(rgdal)
library(rgeos)
library(maptools)
library(sp)
###shape1
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/Rain_poly_merge.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape2
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2002.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape3
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2008.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
Intersect shapefiles
11 messages · Loïc Dutrieux, A. Marcia BARBOSA, Chris English +4 more
Hi, Have you tried gIntersection from the rgeos package. Given 3 SpatialPolygon* objects you can probably do something like: sp12 <- gIntersection(sp1, sp2) sp123 <- gIntersection(sp12, sp3) Cheers, Lo?c
On 02/18/2016 10:25 AM, John Wasige wrote:
?Dear all,
I have three shapefiles that I want to intersect. Any body with an idea on
how to do the intersection? Shapefiles below;
library(rgdal)
library(rgeos)
library(maptools)
library(sp)
###shape1
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/Rain_poly_merge.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape2
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2002.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape3
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2008.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
[[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
Check out also function joinPolys in the PBSmapping package (http://www.inside-r.org/packages/cran/pbsmapping/docs/joinPolys) - - - A. M?rcia BARBOSA, post-doctoral fellow CIBIO/InBIO - University of ?vora (Portugal) http://modtools.wordpress.com/barbosa 2016-02-18 10:04 GMT+00:00 Lo?c Dutrieux <loic.dutrieux at wur.nl>:
Hi, Have you tried gIntersection from the rgeos package. Given 3 SpatialPolygon* objects you can probably do something like: sp12 <- gIntersection(sp1, sp2) sp123 <- gIntersection(sp12, sp3) Cheers, Lo?c On 02/18/2016 10:25 AM, John Wasige wrote:
?Dear all,
I have three shapefiles that I want to intersect. Any body with an idea on
how to do the intersection? Shapefiles below;
library(rgdal)
library(rgeos)
library(maptools)
library(sp)
###shape1
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/Rain_poly_merge.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape2
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2002.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape3
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/yield_maize_average2008.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
[[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
John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris On Thu, Feb 18, 2016 at 1:58 PM, A. Marcia BARBOSA <barbosa at uevora.pt> wrote:
Check out also function joinPolys in the PBSmapping package (http://www.inside-r.org/packages/cran/pbsmapping/docs/joinPolys) - - - A. M?rcia BARBOSA, post-doctoral fellow CIBIO/InBIO - University of ?vora (Portugal) http://modtools.wordpress.com/barbosa 2016-02-18 10:04 GMT+00:00 Lo?c Dutrieux <loic.dutrieux at wur.nl>:
Hi, Have you tried gIntersection from the rgeos package. Given 3 SpatialPolygon* objects you can probably do something like: sp12 <- gIntersection(sp1, sp2) sp123 <- gIntersection(sp12, sp3) Cheers, Lo?c On 02/18/2016 10:25 AM, John Wasige wrote:
?Dear all, I have three shapefiles that I want to intersect. Any body with an idea
on
how to do the intersection? Shapefiles below;
library(rgdal)
library(rgeos)
library(maptools)
library(sp)
###shape1
Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/Rain_poly_merge.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape2
Rain_poly_merge <-
readOGR(dsn="G:/EPIC_CUP/yield_maize_average2002.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
###shape3
Rain_poly_merge <-
readOGR(dsn="G:/EPIC_CUP/yield_maize_average2008.shp",
layer="Rain_poly_merge")
Rain_poly_merge <- spTransform(Rain_poly_merge, CRS("+init=epsg:4326"))
[[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
[[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
Thanks so much On Thu, Feb 18, 2016 at 3:23 PM, chris english <
englishchristophera at gmail.com> wrote:
John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris On Thu, Feb 18, 2016 at 1:58 PM, A. Marcia BARBOSA <barbosa at uevora.pt> wrote:
Check out also function joinPolys in the PBSmapping package (http://www.inside-r.org/packages/cran/pbsmapping/docs/joinPolys) - - - A. M?rcia BARBOSA, post-doctoral fellow CIBIO/InBIO - University of ?vora (Portugal) http://modtools.wordpress.com/barbosa 2016-02-18 10:04 GMT+00:00 Lo?c Dutrieux <loic.dutrieux at wur.nl>:
Hi, Have you tried gIntersection from the rgeos package. Given 3 SpatialPolygon* objects you can probably do something like: sp12 <- gIntersection(sp1, sp2) sp123 <- gIntersection(sp12, sp3) Cheers, Lo?c On 02/18/2016 10:25 AM, John Wasige wrote:
?Dear all, I have three shapefiles that I want to intersect. Any body with an
idea
on
how to do the intersection? Shapefiles below; library(rgdal) library(rgeos) library(maptools) library(sp) ###shape1 Rain_poly_merge <- readOGR(dsn="G:/EPIC_CUP/Rain_poly_merge.shp", layer="Rain_poly_merge") Rain_poly_merge <- spTransform(Rain_poly_merge,
CRS("+init=epsg:4326"))
###shape2 Rain_poly_merge <-
readOGR(dsn="G:/EPIC_CUP/yield_maize_average2002.shp",
layer="Rain_poly_merge") Rain_poly_merge <- spTransform(Rain_poly_merge,
CRS("+init=epsg:4326"))
###shape3 Rain_poly_merge <-
readOGR(dsn="G:/EPIC_CUP/yield_maize_average2008.shp",
layer="Rain_poly_merge") Rain_poly_merge <- spTransform(Rain_poly_merge,
CRS("+init=epsg:4326"))
[[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
[[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
John Wasige "There are no REGRATES in LIFE, just lessons (Jennifer Aniston)? [[alternative HTML version deleted]]
I would have thought gUnaryUnion, but then I can't understand from the documentation what the difference is between that and gIntersection. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of chris english Sent: Thursday, February 18, 2016 7:24 AM John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
Union creates a merged shape including all parts of input objects. Intersection creates a shape of the overlapping portions of input objects. I'm not clear on the goal from the initial email so I don't know which is better in this case. Enjoy, Alex
On 02/18/2016 07:55 AM, Worrall, James -FS wrote:
I would have thought gUnaryUnion, but then I can't understand from the documentation what the difference is between that and gIntersection. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of chris english Sent: Thursday, February 18, 2016 7:24 AM John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Such a clear and simple explanation - thank you. I wish the function documentation was written like that. -----Original Message----- From: Alex Mandel [mailto:tech_dev at wildintellect.com] Sent: Thursday, February 18, 2016 9:59 AM To: Worrall, James -FS <jworrall at fs.fed.us>; chris english <englishchristophera at gmail.com>; A. Marcia BARBOSA <barbosa at uevora.pt> Cc: Help R-Sig_Geo <r-sig-geo at r-project.org> Subject: Re: [R-sig-Geo] Intersect shapefiles Union creates a merged shape including all parts of input objects. Intersection creates a shape of the overlapping portions of input objects. I'm not clear on the goal from the initial email so I don't know which is better in this case. Enjoy, Alex
On 02/18/2016 07:55 AM, Worrall, James -FS wrote:
I would have thought gUnaryUnion, but then I can't understand from the documentation what the difference is between that and gIntersection. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of chris english Sent: Thursday, February 18, 2016 7:24 AM John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
And so for John 's completion we should ask: Union or intersection? I assume union but of course could be wrong. What i especially like about the sp and rgeos documentation is that if you take the time to run the examples in the documentation you just might see your use case. Or, rather likely. Chris
On Feb 18, 2016 8:11 PM, "Worrall, James -FS" <jworrall at fs.fed.us> wrote:
Such a clear and simple explanation - thank you. I wish the function documentation was written like that. -----Original Message----- From: Alex Mandel [mailto:tech_dev at wildintellect.com] Sent: Thursday, February 18, 2016 9:59 AM To: Worrall, James -FS <jworrall at fs.fed.us>; chris english < englishchristophera at gmail.com>; A. Marcia BARBOSA <barbosa at uevora.pt> Cc: Help R-Sig_Geo <r-sig-geo at r-project.org> Subject: Re: [R-sig-Geo] Intersect shapefiles Union creates a merged shape including all parts of input objects. Intersection creates a shape of the overlapping portions of input objects. I'm not clear on the goal from the initial email so I don't know which is better in this case. Enjoy, Alex On 02/18/2016 07:55 AM, Worrall, James -FS wrote:
I would have thought gUnaryUnion, but then I can't understand from the
documentation what the difference is between that and gIntersection.
-----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of chris english Sent: Thursday, February 18, 2016 7:24 AM John, As Loic suggests, rgeos::gIntersection will get you there. Look closely
at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach.
Chris This electronic message contains information generated by the USDA
solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
_______________________________________________ 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
On Thu, 18 Feb 2016, Worrall, James -FS wrote:
Such a clear and simple explanation - thank you. I wish the function documentation was written like that.
Please feel free to contribute; the description section shall be short, what you seem to want is in the details a little further down the page: "Returns an sp object with intersecting geometries merged. If geometries do not intersect then both are returned as distinct subgeometries." Note that gUnion is a binary operator (union of two objects) while gUnaryUnion is a unary operator with an id argument to map input subgeometries to output subgeometries. I guess this is easier to grasp than the JTS original describing the binary union operator: "Computes a Geometry representing all the points in this Geometry and other" at http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#union%28com.vividsolutions.jts.geom.Geometry%29 Roger
-----Original Message----- From: Alex Mandel [mailto:tech_dev at wildintellect.com] Sent: Thursday, February 18, 2016 9:59 AM To: Worrall, James -FS <jworrall at fs.fed.us>; chris english <englishchristophera at gmail.com>; A. Marcia BARBOSA <barbosa at uevora.pt> Cc: Help R-Sig_Geo <r-sig-geo at r-project.org> Subject: Re: [R-sig-Geo] Intersect shapefiles Union creates a merged shape including all parts of input objects. Intersection creates a shape of the overlapping portions of input objects. I'm not clear on the goal from the initial email so I don't know which is better in this case. Enjoy, Alex On 02/18/2016 07:55 AM, Worrall, James -FS wrote:
I would have thought gUnaryUnion, but then I can't understand from the documentation what the difference is between that and gIntersection. -----Original Message----- From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of chris english Sent: Thursday, February 18, 2016 7:24 AM John, As Loic suggests, rgeos::gIntersection will get you there. Look closely at his naming of objects and your example code using spTransform. With his approach, each object has its own name; whereas your approach overwrites Rain_poly_merge the second and third time and the final object (third) is the 2008 maize yield. So read your shapefiles into differently named objects and use Loic's approach. Chris This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
_______________________________________________ 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 http://orcid.org/0000-0003-2392-6140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en http://depsy.org/person/434412
-----Original Message----- From: Roger Bivand [mailto:Roger.Bivand at nhh.no] Sent: Thursday, February 18, 2016 12:01 PM To: Worrall, James -FS <jworrall at fs.fed.us> Cc: Help R-Sig_Geo <r-sig-geo at r-project.org> Subject: Re: [R-sig-Geo] Intersect shapefiles Please feel free to contribute; the description section shall be short, what you seem to want is in the details a little further down the page: "Returns an sp object with intersecting geometries merged. If geometries do not intersect then both are returned as distinct subgeometries."
I think this was the confusing part to me, but I am easily confused. If two polygons overlap, in my mind the two polygons are intersecting geometries, and thus gIntersection should return the two polygons, in their entirety, merged. Of course, this is the same as gUnion, so that doesn't make sense. I made some simple polygons and tested to make sure gIntersection and gUnion behave as I now think they do. Maybe it would be clearer to say something like, "Returns an sp object with intersecting (overlapping) portions of intersecting geometries merged. Non-intersecting portions of intersecting geometries are removed. If geometries do not intersect then both are returned as distinct subgeometries."
I guess this is easier to grasp than the JTS original describing the binary union operator: "Computes a Geometry representing all the points in this Geometry and other" at http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geo metry.html#union%28com.vividsolutions.jts.geom.Geometry%29
Yes indeed! This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.