{"id":494,"date":"2015-10-05T11:16:51","date_gmt":"2015-10-05T11:16:51","guid":{"rendered":"http:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=494"},"modified":"2015-10-07T16:04:54","modified_gmt":"2015-10-07T16:04:54","slug":"r-rstudio-postgis-xubuntu-14-04debian-jessie","status":"publish","type":"post","link":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=494","title":{"rendered":"R + RStudio + PostGIS + Xubuntu 14.04\/Debian jessie"},"content":{"rendered":"<a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"http:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;t=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;text=Check%20this%20out%20%2F%20Mira%20esto\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"http:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;title=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-pinterest nolightbox\" data-provider=\"pinterest\" target=\"_blank\" rel=\"nofollow\" title=\"Pin it with Pinterest\" href=\"http:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;media=&#038;description=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"pinterest\" title=\"Pin it with Pinterest\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/pinterest.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"http:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494&#038;title=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;margin-right:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-16 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=R%20%2B%20RStudio%20%2B%20PostGIS%20%2B%20Xubuntu%2014.04%2FDebian%20jessie&#038;body=Check%20this%20out%20%2F%20Mira%20esto:%20https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F494\" style=\"font-size: 0px; width:16px;height:16px;margin:0;margin-bottom:5px;\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"16\" height=\"16\" style=\"display: inline; width:16px;height:16px; margin: 0; padding: 0; border: none; box-shadow: none;\" src=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/32x32\/mail.png\" \/><\/a><p style=\"text-align: justify;\"><a id=\"spanish\"><\/a><br \/>\n<a href=\"#english\">[In English]<\/a><\/p>\n<p style=\"text-align: justify;\">Estos son los pasos para poder obtener datos de una base de datos PostGIS desde RStudio trabajando en Xubuntu 14.04 o en Debian jessie:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Deben estar instaladas las librer\u00edas <em>libgeos<\/em>, <em>libgeos-c1<\/em>, <em>libgeos-dev<\/em> y <em>libgeos++-dev<\/em>; las dos primeras ya las ten\u00eda instaladas tanto en Xubuntu como en jessie, pero las dos \u00faltimas las he tenido que a\u00f1adir desde Synaptics, seg\u00fan se indica en este enlace de <a href=\"http:\/\/askubuntu.com\/questions\/312294\/once-installed-geos-library-c-and-c-and-then-trying-to-install-rgeos-packa\" target=\"_blank\">AskUbuntu<\/a>.<\/li>\n<li>En RStudio, hay que instalar y despu\u00e9s cargar los paquetes <em>RPostgreSQL<\/em>, <em>rgeos<\/em> y <em>sp<\/em>.<\/li>\n<li>Despu\u00e9s hay que crear la conexi\u00f3n a la base de datos:\n<p style=\"padding-left: 30px;\"><em>drv &lt;- dbDriver(&#8220;PostgreSQL&#8221;)<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>con&lt;- dbConnect(drv,dbname=&#8217;tuBD&#8217;,host=&#8217;localhost&#8217;,port=5432,user=&#8217;tuUsuario&#8217;,password=&#8217;tuPw&#8217;)<\/em><\/p>\n<\/li>\n<li>Para obtener datos que utilicen informaci\u00f3n extra\u00edda de una tabla con datos espaciales, deben usarse las funciones PostGIS habituales de acceso a geometr\u00edas:<\/li>\n<\/ol>\n<p style=\"padding-left: 30px; text-align: justify;\"><em>data &lt;- dbGetQuery(con,&#8221;SELECT nongeocolumn, ST_AsText(geocolumn) FROM yourtable&#8221;)<\/em><\/p>\n<p style=\"padding-left: 30px; text-align: justify;\">Una vez finalizado el trabajo con la BD, se cierran conexi\u00f3n y driver:<\/p>\n<p style=\"padding-left: 30px; text-align: justify;\"><em>dbDisconnect(con)<\/em><br \/>\n<em>dbUnloadDriver(drv)<\/em><\/p>\n<p style=\"text-align: justify;\">Los pasos 2-4 est\u00e1n explicados <a href=\"http:\/\/www.r-bloggers.com\/load-postgis-geometries-in-r-without-rgdal\/\" target=\"_blank\">en este enlace de R-bloggers<\/a>. A partir de \u00e9l he subido a <a href=\"https:\/\/github.com\/WeekendArchaeo\/R\" target=\"_blank\">Github<\/a> un peque\u00f1o script R\u00a0(<em>accessDB.R<\/em>) que realiza la instalaci\u00f3n y carga de paquetes, y la conexi\u00f3n a la base de datos.<\/p>\n<p><a id=\"english\"><\/a><br \/>\n<a href=\"#spanish\">[En espa\u00f1ol]<\/a><\/p>\n<p style=\"text-align: justify;\">These are the steps for retrieving data from a PostGIS database using RStudio under Xubuntu 14.04 or under Debian jessie:<\/p>\n<ol style=\"text-align: justify;\">\n<li>Libraries <em>libgeos<\/em>, <em>libgeos-c1<\/em>, <em>libgeos-dev<\/em> y <em>libgeos++-dev<\/em> must be installed; both Xubuntu and jessie had the first two of them installed, but I had to add the last ones from Synaptics, as it is explained in this link at <a href=\"http:\/\/askubuntu.com\/questions\/312294\/once-installed-geos-library-c-and-c-and-then-trying-to-install-rgeos-packa\" target=\"_blank\">AskUbuntu<\/a>.<\/li>\n<li>In RStudio, you have to install and then load <em>RPostgreSQL<\/em>, <em>rgeos<\/em> y <em>sp <\/em>packages.<\/li>\n<li>After that, you have to create the connection to the database:\n<p style=\"padding-left: 30px;\"><em>drv &lt;- dbDriver(&#8220;PostgreSQL&#8221;)<\/em><\/p>\n<p style=\"padding-left: 30px;\"><em>con&lt;- dbConnect(drv,dbname=&#8217;yourDB&#8217;,host=&#8217;localhost&#8217;,port=5432,user=&#8217;yourUser&#8217;,password=&#8217;yourPw&#8217;)<\/em><\/p>\n<\/li>\n<li>In order to get\u00a0 information from tables which store geospatial data, you have to use the usual PostGIS functions for handling geometries:<\/li>\n<\/ol>\n<p style=\"padding-left: 30px; text-align: justify;\"><em>data &lt;- dbGetQuery(con,&#8221;SELECT nongeocolumn, ST_AsText(geocolumn) FROM yourtable&#8221;)<\/em><\/p>\n<p style=\"padding-left: 30px; text-align: justify;\">Once the work with the DB is finished, connection and driver must be closed:<\/p>\n<p style=\"padding-left: 30px; text-align: justify;\"><em>dbDisconnect(con)<\/em><br \/>\n<em>dbUnloadDriver(drv)<\/em><\/p>\n<p style=\"text-align: justify;\">Steps 2-4 are explained <a href=\"http:\/\/www.r-bloggers.com\/load-postgis-geometries-in-r-without-rgdal\/\" target=\"_blank\">in this link at R-bloggers<\/a>. From the content in this post I have uploaded to <a href=\"https:\/\/github.com\/WeekendArchaeo\/R\" target=\"_blank\">Github<\/a> a little R script (<em>accessDB.R<\/em>) that installs and load the required packages, and then connects to a database.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[In English] Estos son los pasos para poder obtener datos de una base de datos PostGIS desde RStudio trabajando en Xubuntu 14.04 o en Debian jessie: Deben estar instaladas las librer\u00edas libgeos, libgeos-c1, libgeos-dev y libgeos++-dev; las dos primeras ya las ten\u00eda instaladas tanto en Xubuntu como en jessie, pero las dos \u00faltimas las he &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=494\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;R + RStudio + PostGIS + Xubuntu 14.04\/Debian jessie&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12,20],"tags":[14,13,21],"_links":{"self":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/494"}],"collection":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=494"}],"version-history":[{"count":10,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/494\/revisions"}],"predecessor-version":[{"id":533,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/494\/revisions\/533"}],"wp:attachment":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}