An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120816/cb9927fb/attachment.pl>
interacting with plots
9 messages · Frazier, Tyler James, Karl Ove Hufthammer, Greg Snow
You could try something like: library(rgdal) library(sp) scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG") plot(scot_BNG) tmp <- SpatialPoints(locator(1)) proj4string(tmp) <- proj4string(scot_BNG) over(tmp, scot_BNG) # or tmp2 <- over(scot_BNG, tmp) plot( scot_BNG[!is.na(tmp2),], add=TRUE, col='green') Does that do what you want? On Thu, Aug 16, 2012 at 9:05 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hello,
I am new to this group and am still working to figure out many things. I have a kind of basic question, regarding using R and interacting with plots. I have been exploring using the spplot in the sp package as a means to interact with plots, but haven't figured out how to use the function to identify specific attributes associated with an individual polygons. My code is really basic, I simply
ea <- readOGR(".","ghana_eas_ft")
plot(ea)
is it possible to plot the map in a way where I can use the cursor in R to chose and identify attributes associated with a polygon. Also here is the output of str(ea) which follows with a lot of information after the @polygons which I assume is part of the sp class structure.
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 12438 obs. of 3 variables:
.. ..$ EA_NOS : Factor w/ 1133 levels "001-005, 340-342",..: 1110 986 985 976 982 983 978 741 974 975 ...
.. ..$ REG_CODE : Factor w/ 10 levels "01","02","03",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ DIST_CODE: Factor w/ 18 levels "01","02","03",..: 9 9 9 9 9 9 9 9 9 9 ...
..@ polygons :List of 12438
I am wondering if there are newer packages which provide the identify function for polygons. Currently I am referencing the Applied Spatial Data Analysis with R text.
Thanks!
Ty
---------------------------------------------------
Dr. Tyler Frazier, AICP
Senior Research Scientist
Department of Transportation System Planning and Telematics
Technische Universit?t Berlin
Sekretariat SG 12
Salzufer 17-19
10587 Berlin
fon: +49 30 314 22418
fax: +49 30 314 26269
www.vsp.tu-berlin.de<http://www.vsp.tu-berlin.de>
www.matsim.org<http://www.matsim.org>
[[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
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120816/ee8c1c7b/attachment.pl>
My example used locator(1) to get one click, but if you just use locator() (without the 1) then you can click in as many places as you want, then it should show you the info for all of them). If you want to click and see the results, then click again and see the new results, etc. then you could put my code into a while loop. Panning and zooming using the mouse would be a bit more difficult, but you might get a similar effect by setting the limits when plotting (and you can get limits to set using the locator function again). On Thu, Aug 16, 2012 at 11:09 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hi Greg,
That works but I can only chose one polygon and have its attributes
identified. I want to plot my map, then be able to pan and zoom, and chose
several polygons to have their attributes identified (one at a time would be
fine).
Should I be exploring maptools?
Thanks,
Ty
On Aug 16, 2012, at 6:33 PM, Greg Snow wrote:
You could try something like:
library(rgdal)
library(sp)
scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG")
plot(scot_BNG)
tmp <- SpatialPoints(locator(1))
proj4string(tmp) <- proj4string(scot_BNG)
over(tmp, scot_BNG)
# or
tmp2 <- over(scot_BNG, tmp)
plot( scot_BNG[!is.na(tmp2),], add=TRUE, col='green')
Does that do what you want?
On Thu, Aug 16, 2012 at 9:05 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hello,
I am new to this group and am still working to figure out many things. I
have a kind of basic question, regarding using R and interacting with plots.
I have been exploring using the spplot in the sp package as a means to
interact with plots, but haven't figured out how to use the function to
identify specific attributes associated with an individual polygons. My
code is really basic, I simply
ea <- readOGR(".","ghana_eas_ft")
plot(ea)
is it possible to plot the map in a way where I can use the cursor in R to
chose and identify attributes associated with a polygon. Also here is the
output of str(ea) which follows with a lot of information after the
@polygons which I assume is part of the sp class structure.
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 12438 obs. of 3 variables:
.. ..$ EA_NOS : Factor w/ 1133 levels "001-005, 340-342",..: 1110 986 985
976 982 983 978 741 974 975 ...
.. ..$ REG_CODE : Factor w/ 10 levels "01","02","03",..: 1 1 1 1 1 1 1 1 1
1 ...
.. ..$ DIST_CODE: Factor w/ 18 levels "01","02","03",..: 9 9 9 9 9 9 9 9 9
9 ...
..@ polygons :List of 12438
I am wondering if there are newer packages which provide the identify
function for polygons. Currently I am referencing the Applied Spatial Data
Analysis with R text.
Thanks!
Ty
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120816/c98de99a/attachment.pl>
Frazier, Tyler James skreiv:
That works but I can only chose one polygon and have its attributes identified. I want to plot my map, then be able to pan and zoom, and chose several polygons to have their attributes identified (one at a time would be fine).
I would recommend using QGIS instead of R for these kinds of tasks: http://www.qgis.org/ It?s very easy to use, and supports both panning, zooming and clicking to show polygon attributes (and has a whole lot of other useful features). You can even integrate QGIS and R.
Karl Ove Hufthammer E-mail: karl at huftis.org Jabber: huftis at jabber.no
Determining if a point is in a polygon is not as simple a task as might be assumed (I can see that it is in there, why can't the computer?). So the computer has to do this check for all (or maybe just some) 12,438 features, so it is not surprising if it is a little slow. The people who created and maintain the sp package would be better able to address issues of how to speed it up (I am not one of those who get that credit). For this task it may be better to use a tool outside of R, qgis has been mentioned and there may be others. On Thu, Aug 16, 2012 at 12:47 PM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hi Greg,
The example works fine, but running the
tmp <- SpatialPoints(locator())
takes a really long time to execute on my map of 12,438 features each with 3
fields.
Is there anyway to speed it up?
BTW -- I'm running on MacOS Lion with R 2.14.0.
Also, the output plots to Quartz, which doesn't seem to have a pan function
and the zoom function is very very limited.
Thanks!
Ty
On Aug 16, 2012, at 7:30 PM, Greg Snow wrote:
My example used locator(1) to get one click, but if you just use
locator() (without the 1) then you can click in as many places as you
want, then it should show you the info for all of them). If you want
to click and see the results, then click again and see the new
results, etc. then you could put my code into a while loop. Panning
and zooming using the mouse would be a bit more difficult, but you
might get a similar effect by setting the limits when plotting (and
you can get limits to set using the locator function again).
On Thu, Aug 16, 2012 at 11:09 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hi Greg,
That works but I can only chose one polygon and have its attributes
identified. I want to plot my map, then be able to pan and zoom, and chose
several polygons to have their attributes identified (one at a time would be
fine).
Should I be exploring maptools?
Thanks,
Ty
On Aug 16, 2012, at 6:33 PM, Greg Snow wrote:
You could try something like:
library(rgdal)
library(sp)
scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG")
plot(scot_BNG)
tmp <- SpatialPoints(locator(1))
proj4string(tmp) <- proj4string(scot_BNG)
over(tmp, scot_BNG)
# or
tmp2 <- over(scot_BNG, tmp)
plot( scot_BNG[!is.na(tmp2),], add=TRUE, col='green')
Does that do what you want?
On Thu, Aug 16, 2012 at 9:05 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:
Hello,
I am new to this group and am still working to figure out many things. I
have a kind of basic question, regarding using R and interacting with plots.
I have been exploring using the spplot in the sp package as a means to
interact with plots, but haven't figured out how to use the function to
identify specific attributes associated with an individual polygons. My
code is really basic, I simply
ea <- readOGR(".","ghana_eas_ft")
plot(ea)
is it possible to plot the map in a way where I can use the cursor in R to
chose and identify attributes associated with a polygon. Also here is the
output of str(ea) which follows with a lot of information after the
@polygons which I assume is part of the sp class structure.
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 12438 obs. of 3 variables:
.. ..$ EA_NOS : Factor w/ 1133 levels "001-005, 340-342",..: 1110 986 985
976 982 983 978 741 974 975 ...
.. ..$ REG_CODE : Factor w/ 10 levels "01","02","03",..: 1 1 1 1 1 1 1 1 1
1 ...
.. ..$ DIST_CODE: Factor w/ 18 levels "01","02","03",..: 9 9 9 9 9 9 9 9 9
9 ...
..@ polygons :List of 12438
I am wondering if there are newer packages which provide the identify
function for polygons. Currently I am referencing the Applied Spatial Data
Analysis with R text.
Thanks!
Ty
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com
---------------------------------------------------
Dr. Tyler Frazier, AICP
Senior Research Scientist
Department of Transportation System Planning and Telematics
Technische Universit?t Berlin
Sekretariat SG 12
Salzufer 17-19
10587 Berlin
fon: +49 30 314 22418
fax: +49 30 314 26269
www.vsp.tu-berlin.de
www.matsim.org
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120817/41eb7ce5/attachment.pl>
1 day later
Frazier, Tyler James wrote:
I installed QGIS and the optional GRASS 6.4.2 with the GDAL 1.9 framework and GSL, and agree this is much simpler than attempting to use R as a stand alone GIS. Very easy to load my data, pan, zoom and identify attributes of polygons. Regarding integrating QGIS and R, is there a package or plugin I need to add. I noticed some comments on stackexchange regarding manageR, is this the best way to go? FYI, I am running R 2.14.0 on MacOS Lion.
I haven?t used it myself, but yes, I believe mangeR is the best solution.
Karl Ove Hufthammer E-mail: karl at huftis.org Jabber: huftis at jabber.no