Look for your address or location in gvSIG using Scripting!

In an previous post, we spoke about the utility of the “geopy” library for Geocoding in gvSIG 2 using scripting.

Now, with the next script we are going to search addresses or towns and gvSIG will zoom to that point.


The first step will be to install the GeoPy library in our computer. For that we have to download the “geopy-1.7.1-patched-for-gvSIG-2.1.0.zip” file and unzip it in the folder:


at the home folder of our user (in that lib folder we will have the geopy and simplejson folders finally). If we had gvSIG opened we have to close it and run it again.

Depending on the operating system, we can find that gvSIG folder in:

  • Linux: /home/MY_USER
  • Windows: C:\Document and Settings\MY_USER or C:\Users\MY_USER

We remember that this library uses the Google addresses browser. It also has its defects like confusions in addresses or the necessity to have an online connection.

Look for any address in gvSIG!capture27

Once the libraries are installed, we will run gvSIG, and we will go to the Scripting Composer (Tools->Scripting->Scripting Composer menu), we will create a script (File->New), with the name that we want (for example ‘Address browser’), and we will add this source code on it:

from gvsig import *
from geopy.geocoders import get_geocoder_for_service
from commonsdialog import *
from geom import *

def main(*args):

    # Google v3: from address to coordinates
    address = inputbox("Search Address", "Search Address",1)
    geolocator = get_geocoder_for_service("googlev3")
    location = geolocator().geocode(address)

    print"Address: ", (location.address), "Coordinates: ", ((location.latitude, location.longitude))

    geomPoint = createPoint(location.longitude, location.latitude,)
    centerView(currentView(), geomPoint.buffer(0.0005))

def centerView(view, geom):

Then we will open a View in gvSIG, that will be in geographical coordinates on WGS84 (EPSG: 4326) for the correct working, because they are the coodinates that the library gives.

On the View, with the layers included, we will open the scripting launcher (Tools->Scripting->Scripting Launcher menu), and we will run the script that we have created (doble-clicking on it). Once the script has been run, it will ask for the address or town through a text box, and it will center the View to the point finally.

We hope you enjoy this tool!

This entry was posted in development, english, gvSIG Desktop, scripting. Bookmark the permalink.

2 Responses to Look for your address or location in gvSIG using Scripting!

  1. Pingback: Look for your address or location in #gvSIG using Scripting | Geo-How-To News

  2. Pingback: Converting a table of addresses to a point layer using gvSIG 2.x | gvSIG blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s