{"id":724,"date":"2017-02-01T15:53:26","date_gmt":"2017-02-01T15:53:26","guid":{"rendered":"http:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=724"},"modified":"2017-02-01T15:58:06","modified_gmt":"2017-02-01T15:58:06","slug":"gvsig-python-accesing-mysql","status":"publish","type":"post","link":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=724","title":{"rendered":"gvSIG + Python = accesing MySQL"},"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%252F724&#038;t=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F724&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL\" 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%252F724&#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%252F724&#038;title=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL\" 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%252F724&#038;media=&#038;description=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL\" 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%252F724&#038;title=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL\" 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=gvSIG%20%2B%20Python%20%3D%20accesing%20MySQL&#038;body=Check%20this%20out%20%2F%20Mira%20esto:%20https%3A%2F%2Fjafma.net%2Fana%2Ftheweekendarchaeologist%2Findex.php%3Frest_route%3D%252Fwp%252Fv2%252Fposts%252F724\" 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;\">La versi\u00f3n 2.3\u00a0de<a href=\"http:\/\/www.gvsig.com\/es\/productos\/gvsig-desktop\" target=\"_blank\"> gvSIG Desktop<\/a> no permite a\u00f1adir capas a partir de una base de datos MySQL. Esto se puede resolver de forma sencilla usando la estupenda capacidad de <a href=\"https:\/\/blog.gvsig.org\/category\/gvsig-development\/scripting\/\" target=\"_blank\">scripting Python de gvSIG<\/a>; basta con incluir el <a href=\"https:\/\/dev.mysql.com\/downloads\/connector\/j\/\" target=\"_blank\">driver JDBC apropiado<\/a> en el directorio de gvSIG, conectarse a la base de datos, y hacer la consulta deseada. A partir de ah\u00ed, pueden crearse las capas necesarias y a\u00f1adirlas a nuestro proyecto, <a href=\"http:\/\/jafma.net\/ana\/theweekendarchaeologist\/?tag=gvsig\" target=\"_blank\">como se muestra en esta otra entrada del blog<\/a>. Al final de la entrada (y tambi\u00e9n en <a href=\"https:\/\/github.com\/WeekendArchaeo\/python\/blob\/master\/mysqldbaccess.py\" target=\"_blank\">mi repositorio\u00a0GitHub<\/a>) puede verse el c\u00f3digo m\u00ednimo para acceder a la base de datos y hacer una consulta.<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/www.gvsig.com\/es\/productos\/gvsig-desktop\" target=\"_blank\">gvSIG Desktop<\/a> 2.3 does not allow to add layers from a MySQL database. This can be easily\u00a0solved using the <a href=\"https:\/\/blog.gvsig.org\/category\/gvsig-development\/scripting\/\" target=\"_blank\">great Python scripting<\/a> utilities provided by gvSIG; you just have to include the <a href=\"http:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=686\" target=\"_blank\">proper JDBC driver<\/a> in your gvSIG folder, then connect to the database and do your query. Those data can be stored\u00a0in a new layer and then added into our proyect, <a href=\"http:\/\/jafma.net\/ana\/theweekendarchaeologist\/?tag=gvsig\" target=\"_blank\">as it is shown in this previous\u00a0post<\/a>. At the end of this post (and also in<a href=\"https:\/\/github.com\/WeekendArchaeo\/python\/blob\/master\/mysqldbaccess.py\" target=\"_blank\"> my GitHub repository<\/a>) you can see the minimun code required to accesing a database and retrieving information.<\/p>\n<p>&nbsp;<\/p>\n<p>import sys<br \/>\nimport os<br \/>\nfrom gvsig import *<br \/>\nfrom gvsig import geom<br \/>\nfrom gvsig.geom import *<br \/>\nfrom java.util import Properties<\/p>\n<p>sys.path.append(&#8220;\/pathtomygvSIGfolder\/mysql-connector-java-5.1.40-bin.jar&#8221;);<br \/>\nimport org.gjt.mm.mysql.Driver as Driver<\/p>\n<p>def main():<\/p>\n<p># Connect to the database<br \/>\nprops = Properties()<br \/>\nprops.put(&#8220;user&#8221;,&#8221;myuser&#8221;)<br \/>\nprops.put(&#8220;password&#8221;,&#8221;mypasswd&#8221;)<br \/>\ndb = Driver().connect(&#8220;jdbc:mysql:\/\/localhost\/mydb&#8221;, props)<br \/>\n# Get geometry info from database and insert it into the new layer<br \/>\nc = db.createStatement()<br \/>\nrs = c.executeQuery(&#8220;select * from mytable\u00a0where somecolumn=&#8217;somevalue'&#8221;)<br \/>\nwhile rs.next():<br \/>\nid = rs.getString(&#8220;somecolumn&#8221;)<br \/>\nrs.close()<br \/>\nc.close()<br \/>\ndb.close()<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>La versi\u00f3n 2.3\u00a0de gvSIG Desktop no permite a\u00f1adir capas a partir de una base de datos MySQL. Esto se puede resolver de forma sencilla usando la estupenda capacidad de scripting Python de gvSIG; basta con incluir el driver JDBC apropiado en el directorio de gvSIG, conectarse a la base de datos, y hacer la consulta &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/?p=724\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;gvSIG + Python = accesing MySQL&#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],"tags":[43,16,55,54],"_links":{"self":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/724"}],"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=724"}],"version-history":[{"count":5,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/724\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=\/wp\/v2\/posts\/724\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jafma.net\/ana\/theweekendarchaeologist\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}