Exemple #1
0
def fetch_countries_count():
    """Get list of countries and total objects"""
    URL = "api/1.0/features/countries"
    r = query_georegistry(URL)
    countries = json.loads(r)
    cl = []
    for c in countries:
        URL = "api/1.0/counters/cached-country/%s" % (c['country_code'])
        count = query_georegistry(URL)
        count = json.loads(count)

        if count.has_key('count'):
            c.update({'count': count['count']})
            cl.append(c)
    """Get list of categories and total objects in each"""
    return cl
Exemple #2
0
def browse(request, country_code):
    """
        Plot multiple points based on a kwarg dict
    """
    #data = urllib.urlencode(kwargs)
    if country_code:
        URL = "api/1.0/features/locations?country_code=%s" % (country_code)
    else:
        URL = "api/1.0/features/locations"
    r = query_georegistry(URL)

    locations = json.loads(r)
    #print type(locations)

    country_name = locations.keys()[0]
    locations = locations[country_name]['children']
    return render_to_response(
        "web/browse.html",
        {
            'country_name': country_name.title(),
            'country_code': country_code,
            'locations': locations
        },
        context_instance=RequestContext(request),
    )
Exemple #3
0
def table_points(request, kwargs):
    """
        Plot multiple points based on a kwarg dict
    """
    data = urllib.urlencode(kwargs) 
    URL="api/1.0/features/search?%s" % (data)
    r= query_georegistry(URL)
    d=json.loads(r)
    if d['status']==200:
        total=d['total']
        gr_id_list=[]
        column_names= d.keys()
        
        for i in d['features']:
            c=0
            pointsitems=[]
            column_names.append(i.keys())
            column_names.append(i['geometry'].keys())
            print column_names
            geomtype=i['geometry']['type']
            if geomtype=="Point": 
                gr_id=i['properties']['id']
                gr_name=i['properties']['name']
                
                gr_id_list.append({'gr_id': gr_id, 'gr_name': gr_name })
    else:
        jsonstr = json.dumps(d, indent=4)	
        return HttpResponse(jsonstr, status=d['status'],
                                mimetype='application/json')
        
    return render_to_response("list.html", {'gr_id_list': gr_id_list,
                                            'total': total },
                              context_instance = RequestContext(request),)
Exemple #4
0
def list_points(request, kwargs):
    """
        Plot multiple points based on a kwarg dict
    """
    data = urllib.urlencode(kwargs)
    URL = "api/1.0/features/search?%s" % (data)
    r = query_georegistry(URL)
    d = json.loads(r)
    if d['status'] == 200:
        total = d['total']
        gr_id_list = []

        for i in d['features']:
            c = 0
            pointsitems = []
            geomtype = i['geometry']['type']
            if geomtype == "Point":
                gr_id = i['id']
                gr_name = i['properties']['name']

                gr_id_list.append({'gr_id': gr_id, 'gr_name': gr_name})
    else:
        jsonstr = json.dumps(d, indent=4)
        return HttpResponse(jsonstr,
                            status=d['status'],
                            mimetype='application/json')

    return render_to_response(
        "list.html",
        {
            'gr_id_list': gr_id_list,
            'total': total
        },
        context_instance=RequestContext(request),
    )
Exemple #5
0
def fetch_countries_count():
    """Get list of countries and total objects"""
    URL="api/1.0/features/countries"
    r= query_georegistry(URL)
    countries=json.loads(r)
    cl=[]
    for c in countries:
        URL="api/1.0/counters/cached-country/%s" % (c['country_code'])
        count= query_georegistry(URL)
        count=json.loads(count)

        if count.has_key('count'):
            c.update({'count':count['count']})
            cl.append(c)

    """Get list of categories and total objects in each"""
    return cl
Exemple #6
0
def fetch_categories_count():
    URL = "api/1.0/features/classifiers"
    r = query_georegistry(URL)
    classifiers = json.loads(r)
    catlist = []
    countlist = []
    for cl in classifiers:
        catlist.append(cl['category'])
    catlist = list(set(catlist))

    for i in catlist:
        URL = "api/1.0/counters/cached-classifier/category/%s" % (i)
        r = query_georegistry(URL)
        cat = json.loads(r)
        if cat.has_key('count'):
            if cat['count'] > 0:
                countlist.append({i: cat['count']})

    return countlist
Exemple #7
0
def browsecountries(request):
    """
        Plot multiple points based on a kwarg dict
    """
    # data = urllib.urlencode(kwargs)

    URL = "api/1.0/features/countries"
    l = query_georegistry(URL)
    countries = json.loads(l)
    return render_to_response("web/countries.html", {"countries": countries}, context_instance=RequestContext(request))
Exemple #8
0
def fetch_categories_count():
    URL="api/1.0/features/classifiers"
    r= query_georegistry(URL)
    classifiers=json.loads(r)
    catlist=[]
    countlist=[]
    for cl in classifiers:
        catlist.append(cl['category'])
    catlist=list(set(catlist))
    
    for i in catlist:
        URL="api/1.0/counters/cached-classifier/category/%s" % (i)
        r= query_georegistry(URL)
        cat=json.loads(r)
        if cat.has_key('count'):
            if cat['count'] > 0:
                countlist.append({i :cat['count']})

    return countlist
Exemple #9
0
def fetch_country_count(country_code):
    """Get count for a country"""
    URL = "api/1.0/counters/cached-country/%s" % (country_code)
    count = query_georegistry(URL)
    try:
        count = json.loads(count)
        if count.has_key('count'):
            return count
        return None
    except ():
        return None
Exemple #10
0
def fetch_country_count(country_code):
    """Get count for a country"""
    URL="api/1.0/counters/cached-country/%s" % (country_code)
    count= query_georegistry(URL)
    try:
        count=json.loads(count)
        if count.has_key('count'):
            return count
        return None
    except():
        return None
Exemple #11
0
def browsecountries(request):
    """
        Plot multiple points based on a kwarg dict
    """
    #data = urllib.urlencode(kwargs)

    URL = "api/1.0/features/countries"
    l = query_georegistry(URL)
    countries = json.loads(l)
    return render_to_response(
        "web/countries.html",
        {'countries': countries},
        context_instance=RequestContext(request),
    )
Exemple #12
0
def displaylist_points(request, kwargs):
    """
        Plot multiple points based on a kwarg dict
    """
    data = urllib.urlencode(kwargs) 
    URL="api/1.0/features/search?%s" % (data)
    r= query_georegistry(URL)
    d=json.loads(r)
    if d['status']==200:

        return render_to_response("web/display.html", {'d': r},
                              context_instance = RequestContext(request),)
        
    else:
        jsonstr = json.dumps(d, indent=4)	
        return HttpResponse(jsonstr, status=d['status'],
                                mimetype='application/json')
Exemple #13
0
def displaylist_points(request, kwargs):
    """
        Plot multiple points based on a kwarg dict
    """
    data = urllib.urlencode(kwargs)
    URL = "api/1.0/features/search?%s" % (data)
    r = query_georegistry(URL)
    d = json.loads(r)
    if d['status'] == 200:

        return render_to_response(
            "web/display.html",
            {'d': r},
            context_instance=RequestContext(request),
        )

    else:
        jsonstr = json.dumps(d, indent=4)
        return HttpResponse(jsonstr,
                            status=d['status'],
                            mimetype='application/json')
Exemple #14
0
def browse(request, country_code):
    """
        Plot multiple points based on a kwarg dict
    """
    # data = urllib.urlencode(kwargs)
    if country_code:
        URL = "api/1.0/features/locations?country_code=%s" % (country_code)
    else:
        URL = "api/1.0/features/locations"
    r = query_georegistry(URL)

    locations = json.loads(r)
    # print type(locations)

    country_name = locations.keys()[0]
    locations = locations[country_name]["children"]
    return render_to_response(
        "web/browse.html",
        {"country_name": country_name.title(), "country_code": country_code, "locations": locations},
        context_instance=RequestContext(request),
    )
Exemple #15
0
def fetch_total_count():
    """Get list of countries and total objects"""
    URL = "api/1.0/counters/cached-total"
    r = query_georegistry(URL)
    total = json.loads(r)
    return total['count']
Exemple #16
0
def fetch_total_count():
    """Get list of countries and total objects"""
    URL="api/1.0/counters/cached-total"
    r= query_georegistry(URL)
    total=json.loads(r)
    return total['count']