NewCartographers / NCDatapalooza

Extension of the CityCamp winning idea -- historic markers and tours for NC
3 stars 1 forks source link

User can search for markers by a theme #5

Open ajturner opened 9 years ago

ajturner commented 9 years ago

As a User, when searching for markers, I can choose from a list of themes such as "Presidents" or "Jazz" that show me only markers related to that topic.

See http://www.africanamericanmusicnc.com/

ajturner commented 9 years ago

The WAB has a "Query Tool" that lets you add filters for layers. However your Historic Markers don't have any thematic topics or descriptions. Maybe you can talk with the

uploads/56ec81bf-5af6-4717-a98e-86562527fa7a/NC_Data_Experiments_and_Apple_Store_on_the_App_Store_on_iTunes.png

ajturner commented 9 years ago
# Small script to query NC Historic Markers related data table
# June 17, 2015

require 'open-uri'
require 'json'

keyword_list_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=1%3D1&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outSR=&outFields=&f=pjson"

keywords = JSON.parse(open(keyword_list_url).read)

keywords["features"].each do |keyword|
  puts keyword["attributes"]["Keyword"]
end

keyword = "Agriculture"

keyword_records_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/query?returnGeometry=true&where=Keyword%20%3D%20%27#{keyword}%27&f=json&outSR=102100&outFields=OBJECTID%2CKeywordID%2CKeyword&returnDistinctValues=false"

keyword_record = JSON.parse(open(keyword_records_url).read)

keyword_id = keyword_record['features'][0]['attributes']["OBJECTID"]

markers_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/queryRelatedRecords?relationshipId=0&returnGeometry=false&outFields=ID%2CMarkerTitle%2CMarkerText%2COBJECTID&objectIds=#{keyword_id}&f=json"

markers = JSON.parse(open(markers_url).read)

markers['relatedRecordGroups'][0]['relatedRecords'].each do |record|
  puts (record['attributes']["MarkerTitle"] || "") + "|" + record['attributes']["MarkerText"]
end
ajturner commented 9 years ago

Count of Markers by Keyword


African Methodist Episcopal Zion: 7
Agriculture: 54
Anglican: 11
Anglican Episcopal: 6
Archaeology: 3
Architects: 9
Arts: 31
Aviation: 10
Baptist: 33
Blacks: 123
Books: 28
Botany: 16
Business: 44
Catholic: 6
Cemeteries: 16
Cherokees: 4
Christian: 4
Christian Colleges: 2
Civil War: 252
Cold War: 1
Colleges: 75
Congregational: 1
Conservation: 9
Courthouses: 7
Diplomats: 30
Disciples of Christ: 4
Education: 219
Episcopal: 22
Espionage: 2
Evangelical Luthern: 1
Evangelical And Reformed: 4
Exploration: 61
Finance: 25
Folklore: 7
Free Will Baptist: 3
Generals: 117
Geography: 60
German Baptist: 1
German Reformed: 6
Governors: 145
Health: 12
Historians: 28
History: 2
Hostelry: 36
Indian Wars: 36
Indians: 99
Industry: 68
Institutions: 28
Invention: 19
Jewish: 2
Journalism: 48
Kirk-Holden War: 2
Law: 83
Libraries: 9
Literature: 48
Lumbees: 3
Lutheran: 17
Maritime: 116
Marriages: 4
Medicine: 51
Methodist: 43
Mexican War: 3
Military: 452
Mining: 27
Missionary Baptist: 1
Moravian: 5
Museum: 1
Music: 17
Organizations: 46
Parks: 12
Particular Baptist: 3
Politics: 364
Postal: 8
Presbyterian: 59
Primitive Baptist: 5
Prisons: 8
Quaker: 18
Railroads: 3
Regulation: 20
Religion: 206
Revolution: 154
Roman Catholic: 1
Science: 15
Senators: 64
Sites: 81
Spanish-American War: 3
Sports: 6
Textiles: 19
Tobacco: 11
Transportation: 120
United Church of Christ: 1
Waldenses: 1
War of 1812: 13
Women: 91
Women Organizations: 4
World War I: 19
World War II: 26
Civil Rights: 13
Canals: 7
Health Resorts: 7
Cherokee Towns: 5
University of North Carolina: 31
Battles: 124
Camps: 15
United States, Presidents of: 33
Duels: 2
Arsenals: 3
Ambassadors, United States: 8
Mills: 17
Iron Works: 8
Firsts: 108
Ferries: 3
Plank Roads: 10
Oldest: 14
Conventions, Members of: 26
Last: 8
Orphanages: 5
Lighthouses: 4
Forts: 44
Museums: 6
Confederate Hospitals: 11
Mexico: 4

calculated with

import urllib
import urllib2
import json

keyword_list_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=1%3D1&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outSR=&outFields=&f=pjson"

response = urllib2.urlopen(keyword_list_url)
keyword_response = response.read()

keywords = json.loads(keyword_response)
for keyword in keywords["features"]:

    #   Get the Marker IDs for a given Keyword
    params = {'where': "Keyword='" + keyword["attributes"]["Keyword"] + "'", 'returnGeometry': 'false', 'f': 'json', 'outFields': 'OBJECTID'}
    keyword_records_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/query?" + urllib.urlencode(params)
    keyword_record = json.loads(urllib2.urlopen(keyword_records_url).read())
    keyword_id = keyword_record['features'][0]['attributes']["OBJECTID"]

    #   Get the Markers that relate to the Keyword
    markers_url = "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Markers/MapServer/3/queryRelatedRecords?relationshipId=0&returnGeometry=false&outFields=*&objectIds=%(keyword_id)s&f=json" % locals()
    markers = json.loads(urllib2.urlopen(markers_url).read())

    #   Count the length of the markers and output
    keyword_count = len(markers['relatedRecordGroups'][0]['relatedRecords'])
    print keyword["attributes"]["Keyword"] + ": " + str(keyword_count)