While I have used GIS software (ArcGIS and just started playing with QGIS at home), I have never looked into the code or file structure of shapefiles. I am working on a project for my work, a web-based application running on a LAMP server and written in PHP and JavaScript. The idea is a search box that will be used to search the "geographical hierarchy" of a specific location. This would allow my users to type in a city, and it would return the state, country, and continent in which the city is located. Google can provide this information and more, but this will be used on a closed network so that's not an option. I am using a MySQL database containing all continents down to the city level. I still have a little way to go, but I know what needs to be done to finish this part. I recently thought it would be nice to add the ability for my users to enter a geo-coordinate and get the same result as if they had entered the city the coordinate is located in. Right now I do not have any coordinates in my database, but I know I have to reference them somehow. I believe there is an SDE database on this network, but i have not tried to access it or see what it would take to pull data from it. I would like to just reference it to get the geo data rather than duplicating the data in my database, if possibly (to keep my database as small as possible).

Another feature I would like to provide (now, if it is not too difficult, or as a future update) is the ability for my users to dynamically build a KML (as a lot of users would be using GoogleEarth) or a shapefile based on the users' specific request (single country/multiple countries, states or cities within countries, etc). To build the KML, I know that I would need a list of decimal lat/long for the shape of the polygon. I am not sure what would be needed for the shapefile. My reasoning for this feature is to allow GoogleEarth users the ability to quickly/easily generate a KML and, for GIS users, my tool could just be another front end to the SDE to generate specific shapefiles.

So, specifically:

  1. What do I need to do to be able to look up a location based on a coordinate located within that location?
  2. What is the best way to dynamically create a KML?
  3. How can I dynamically create a shapefile keeping the data from the original database?

Since this is a closed network, I am limited to the libraries and scripts that other people have already added. I am hoping that i can code most of this by hand or transcribe it, and I would be most comfortable using PHP and/or JavaScript. However, if there is a specific script or library that I would need, there is a process to get stuff moved to this network, but it is not a simple, and then it has to be approved, which is its own process.

As this is a work in progress, I am open to suggestions to improve what I have done so far or what my thinking for the rest of my program.


reg 1: If you have a PostGIS DB you can query the geometry of the layer say, city_points. the query is SELECT city_name from city_points where the_geom = asText('your input wkt) this can be of something like 'POINT(10.5,78.3)'. you can easily make wkt string that way.

reg 2:

KML is an open standard and is an XML format. you can find OGC specs here. Also read this tutorial. The selected records from your postGIS db can be read easily using PHP and using simple select queries and create a KML file, make it available to download by users. A simple select query can be

assume the_geom is the geomtry column in your layer "db_layer"

SELECT asText(the_geom) from db_layer WHERE column1='s%';

asText(the_geom) will return the wkt of the geometry and can be set as the geometry value in KML files

Not the answer you're looking for? Browse other questions tagged or ask your own question.