Part of the database-driven approach to web mapping that will be demonstrated here is to output the data retrieved from the database in XML format. XML is often used in this way as a language- and platform-independent way to pass data between applications. As an example, here are the Jen and Barry's candidate city data stored in XML format [1]. And here is an alternate way of storing these same data [2].
Either form can be used to supply data for a mashup. However, I recommend using the first form for two reasons:
So, how do you go about putting the data into this format? Before we see how to do that in a database context, let's ease our way into the usage of XML in web mapping by working with a tool that I wrote for ArcToolbox. This tool can be used to export any point, line or polygon shapefile into the format shown above. This part of the lesson will guide you through the installation and usage of this tool.
XP/Win2000: \Documents and Settings\<your user name>\Application Data\ESRI\ArcToolbox\My Toolboxes Vista or Windows 7/8 (make sure you have hidden files and folders displayed): \Users\<user name>\AppData\Roaming\ESRI\Desktop<version>\ArcToolbox\My ToolboxesYou should see at least three files: Mashup Tools.tbx, shp2xml.py and shp2csv.py.
I used the Python programming language to create this tool. If you're interested in learning more about automating geoprocessing tasks with Python, check out our course on the topic (GEOG 485) [4].
The Mashup Tools toolbox contains a tool called Export Shapefile to XML. Its usage is straightforward, though here are some details, using the candidate_cities shapefile as an example:
When you use the tool on a line or polygon layer, the x and y attributes represent the centroid of the feature. Beneath each feature is then a list of the vertices that delineate that feature. For example, here are the coordinates of Pennsylvania's counties in XML format [5].
Now that you've seen how to convert GIS data to XML format, let's see how to write JavaScript that reads point data from an XML file and adds markers to a Google Map.
Links
[1] http://www.personal.psu.edu/jed124/candidate_cities.xml
[2] http://www.personal.psu.edu/jed124/candidate_cities_alt.xml
[3] https://www.e-education.psu.edu/geog863_gmaps/sites/www.e-education.psu.edu.geog863_gmaps/files/mashup_tools.zip
[4] http://www.e-education.psu.edu/geog485
[5] http://www.personal.psu.edu/jed124/pa_counties.xml