Contributor(s): Andres Montano
Since ArcGIS client software only runs in Windows (as of 2014), the following instructions will assume that you are connecting through a Windows machine.
Will be used to create a tunnel. Can be downloaded from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html (select putty.exe under Binaries -> For Windows on Intel x86). putty.exe does not use an installer and is the actual program.
After downloading it, move it to a folder location that makes sense such as My Documents\Applications .
psql libraries do not come with ArcGIS, so have to be downloaded separately. Can be downloaded from: http://www.enterprisedb.com/products-services-training/pgbindownload (select Binaries from installer version 9.1.13 -> Win86-32). Select 32bit version even if you are running Windows under 64bits, since ArcGIS which will use such libraries runs under 32bits (as of 10.2.1) and 64bits won't work!
After having downloaded it double click and navigate to folder \pgsql\bin . From there copy the following files to C:\Program Files (x86)\ArcGIS\Desktop10.2\bin (you may not see the extensions of files, depending on how your windows machine is configured)
cd "\Program Files (x86)\ArcGIS\Desktop10.2\bin\" psql.exe -U postgres --password -h localhost -d shanti_places_production -p 5430
Only the shanti_places_production db is accessible using this method.
Also see Ron Bentley's documentation on accessing PostgreSQL-PostGIS databases.
To return all features (fid and roman popular name) that have Aufschnaiter map data (code auf.id):
SELECT features.fid, feature_names.name FROM features, feature_geo_codes, feature_names, cached_feature_names WHERE cached_feature_names.feature_id = features.id AND cached_feature_names.feature_name_id = feature_names.id AND features.id = feature_geo_codes.feature_id AND cached_feature_names.view_id = (SELECT id FROM simple_props WHERE simple_props.type = 'View' AND simple_props.code = 'roman.popular') AND feature_geo_codes.geo_code_type_id = (SELECT id FROM simple_props WHERE simple_props.type = 'GeoCodeType' AND simple_props.code = 'auf.id');
An example record that this query should return is: features.id = 16473. The fid = 16409 and the record on the public website is: http://places.kmaps.virginia.edu/features/16409 . Names can be returned for the following view codes: roman.popular, roman.scholar, pri.tib.sec.roman, pri.tib.sec.chi, simp.chi, trad.chi, deva.
To query all features with Aufschnaiter map data that have location data:
SELECT features.fid, feature_names.name, shapes.geometry FROM features, feature_geo_codes, feature_names, cached_feature_names, shapes WHERE cached_feature_names.feature_id = features.id AND shapes.fid = features.fid AND cached_feature_names.feature_name_id = feature_names.id AND features.id = feature_geo_codes.feature_id AND cached_feature_names.view_id = (SELECT id FROM simple_props WHERE simple_props.type = 'View' AND simple_props.code = 'roman.popular') AND feature_geo_codes.geo_code_type_id = (SELECT id FROM simple_props WHERE simple_props.type = 'GeoCodeType' AND simple_props.code = 'auf.id');
To query all features that intersect (this includes all features within Lhasa and all features that contain Lhasa) with Lhasa Municipality (fid=317) that have location data:
SELECT features.fid, feature_names.name, shapes.geometry FROM features, shapes, feature_names, cached_feature_names, simple_props WHERE shapes.fid = features.fid AND cached_feature_names.feature_id = features.id AND cached_feature_names.feature_name_id = feature_names.id AND cached_feature_names.view_id = simple_props.id AND simple_props.type = 'View' AND simple_props.code = 'roman.popular' AND shapes.geometry && (SELECT shapes.geometry FROM shapes WHERE shapes.fid = 317)
To query all natural features (feature type 62 and below, see http://subjects.kmaps.virginia.edu/features/62 ) that intersect with Lhasa Municipality (fid=317) that have location data:
SELECT features.fid, feature_names.name, shapes.geometry FROM features, shapes, feature_names, cached_feature_names, simple_props, cumulative_category_feature_associations WHERE shapes.fid = features.fid AND cached_feature_names.feature_id = features.id AND cached_feature_names.feature_name_id = feature_names.id AND cached_feature_names.view_id = simple_props.id AND simple_props.type = 'View' AND simple_props.code = 'roman.popular' AND cumulative_category_feature_associations.feature_id = features.id AND cumulative_category_feature_associations.category_id = 62 AND shapes.geometry && (SELECT shapes.geometry FROM shapes WHERE shapes.fid = 317)