Example #1
0
def placenames():
    # get the total register count from the XML API
    try:
        # get the register length from the online DB
        no_of_items = conf.db_select(
            'SELECT COUNT(*) FROM "PLACENAMES";')[0][0]

        page = request.values.get('page') if request.values.get(
            'page') is not None else 1
        per_page = request.values.get('per_page') if request.values.get(
            'per_page') is not None else 30
        offset = (page - 1) * per_page
        items = []
        q = '''
            SELECT "ID", "NAME" FROM "PLACENAMES"
            ORDER BY "ID"
            OFFSET {}
            LIMIT {}
        '''.format(offset, per_page)
        for item in conf.db_select(q):
            items.append((item[0], item[1]))
    except Exception as e:
        print(e)
        return Response('The Place Names Register is offline',
                        mimetype='text/plain',
                        status=500)

    return RegisterRenderer(
        request, request.url, 'Place Names Register',
        'A register of Place Names', items,
        ['http://linked.data.gov.au/def/placenames/PlaceName'],
        no_of_items).render()
Example #2
0
def placenames():
    # Search
    search_string = request.values.get('search')
    # get the total register count from the XML API
    try:
        # get the register length from the online DB
        sql = '''SELECT COUNT(*) FROM "PLACENAMES"
'''
        if search_string:
            sql += '''WHERE UPPER("ID") LIKE '%{search_string}%' OR UPPER("NAME") LIKE '%{search_string}%';
'''.format(search_string=search_string.strip().upper())
        #print(sql)
        no_of_items = conf.db_select(sql)[0][0]

        page = int(request.values.get('page')) if request.values.get('page') is not None else 1
        per_page = int(request.values.get('per_page')) if request.values.get('per_page') is not None else DEFAULT_ITEMS_PER_PAGE
        offset = (page - 1) * per_page
        items = []
        sql = '''SELECT "ID", "NAME" 
FROM "PLACENAMES"
'''
        if search_string:
            sql += '''WHERE UPPER("ID") LIKE '%{search_string}%' OR UPPER("NAME") LIKE '%{search_string}%'
'''.format(search_string=search_string.strip().upper())
            
        sql += '''ORDER BY "AUTHORITY", cast('0' || regexp_replace("AUTH_ID", '\D+', '') as integer), "AUTH_ID"
OFFSET {}
LIMIT {}
'''.format(offset, per_page)
        #print(sql)
        for item in conf.db_select(sql):
            items.append(
                (item[0], item[1])
            )
    except Exception as e:
        print(e)
        return Response('The Place Names database is offline', mimetype='text/plain', status=500)

    return RegisterRenderer(request=request, 
                            uri=request.url, 
                            label='Place Names Register', 
                            comment='A register of Place Names', 
                            register_items=items,
                            contained_item_classes=['http://linked.data.gov.au/def/placenames/PlaceName'], 
                            register_total_count=no_of_items, 
                            views=None, 
                            default_view_token=None, 
                            super_register=None,
                            page_size_max=1000, 
                            register_template=None, 
                            per_page=per_page, 
                            search_query=search_string,
                            search_enabled=True
                            ).render()
Example #3
0
    def __init__(self, request, uri):
        views = {
            'pn': View(
                'Place Names View',
                'This view is the standard view delivered by the Place Names dataset in accordance with the '
                'Place Names Profile',
                ['text/html', 'text/turtle', 'application/ld+json'],
                'text/html'
            )
        }

        super(Placename, self).__init__(request, uri, views, 'pn', None)

        self.id = uri.split('/')[-1]

        self.hasName = {
            'uri': 'http://linked.data.gov.au/def/placenames/',
            'label': 'from National Composite Gazetteer of Australia (beta version 0.2):',
            'comment': 'The Entity has a name (label) which is a text sting.',
            'value': None
        }

        self.register = {
            'label': None,
            'uri': None
        }

        self.featureType = {
            'label': None,
            'uri': None
        }

        self.hasCategory = {
            'label': None,
            'uri': None
        }

        self.hasGroup = {
            'label': None,
            'uri': None
        }


        self.wasNamedBy = {
            'label': None,
            'uri': None
        }

        self.hasNameFormality = {
            'label': 'Official',
            'uri': 'http://linked.data.gov.au/def/placenames/nameFormality/Official'
        }

        self.authority = {
            'label': None,
            'web': None
        }
        self.email = None

        self.modifiedDate = None

        self.hasPronunciation = None   # None == don't display
        # pronunciation will only be displyed on webpage if it exists

        q = '''
            SELECT 
              	"NAME",
                "AUTHORITY",
                "SUPPLY_DATE", 
                "FEATURE",
                "CATEGORY",
                "GROUP",
                "LATITUDE",
                "LONGITUDE"
            FROM "PLACENAMES"
            WHERE "ID" = '{}'
        '''.format(self.id)
        for placename in conf.db_select(q):
            # for item in placename:
            #     print(item)
            #print(placename)
            #print(placename[0], placename[1], placename[2], placename[3], placename[4], placename[5]), placename[6], placename[7]
            # set up x y location from database
            self.y = placename[6]
            self.x = placename[7]

            self.hasName['value'] = str(placename[0]) + " (" + str(placename[3]).capitalize() + ")"

            self.featureType['label'] = str(placename[3])
            self.featureType['uri'] = 'http://vocabs.ands.org.au/repository/api/lda/ga/place-type/v1-0/resource?uri=http://pid.geoscience.gov.au/def/voc/ga/PlaceType/' + str(placename[3]).replace(' ','_')

            #self.hasCategory = str(placename[4])
            self.hasCategory['label'] = str(placename[4])
            self.hasCategory['uri'] = 'http://vocabs.ands.org.au/repository/api/lda/ga/place-type/v1-0/resource?uri=http://pid.geoscience.gov.au/def/voc/ga/PlaceType/' + str(placename[4]).replace(' ','_')

            #self.hasGroup = str(placename[5])
            self.hasGroup['label'] = str(placename[5])
            self.hasGroup['uri'] = 'http://vocabs.ands.org.au/repository/api/lda/ga/place-type/v1-0/resource?uri=http://pid.geoscience.gov.au/def/voc/ga/PlaceType/' + str(placename[5]).replace(' ','_')

            self.authority['label'] = (NAME_AUTHORITIES[str(placename[1])]['label'])
            self.authority['web'] = (NAME_AUTHORITIES[str(placename[1])]['web'])
            self.email = (NAME_AUTHORITIES[str(placename[1])]['email'])

            #print('authority', self.authority)

            self.register['uri'] = (GAZETTEERS[str(placename[1])]['uri_id'])
            self.register['label'] = (GAZETTEERS[str(placename[1])]['label'])

            #self.register['uri'] = 'http://linked.data.gov.au/dataset/placenames/gazetteer/' + str(placename[1])

            #print('name auth', naming_authorities[str(placename[1])]['label'])

            self.supplyDate = placename[2]
            #DGGS function
            resolution = 9
            # coords = (longi, lati)  # format required like this
            coords = (self.x, self.y)
            self.thisCell = rdggs.cell_from_point(resolution, coords, plane=False)  # false = on the elipsoidal curve
Example #4
0
    def __init__(self, request, uri):
        views = {
            'pn':
            View(
                'Plane Names View',
                'This view is the standard view delivered by the Place Names dataset in accordance with the '
                'Place Names Profile',
                ['text/html', 'text/turtle', 'application/ld+json'],
                'text/html')
        }

        super(Placename, self).__init__(request, uri, views, 'pn', None)
        self.id = uri.split('/')[-1]

        self.hasName = {
            'uri': 'http://linked.data.gov.au/def/placename/hasName',
            'label': 'has name',
            'comment': 'The Entity has a name (label) which is a text sting.',
            'value': None
        }

        gazetteers = {
            'AAD': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'ACT': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'AHO': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'NSW': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'NT': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'QLD': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'SA': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'TAS': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'VIC': {
                'label': 'Australian Antarctica Gazetteer',
                'uri_id': 'aag'
            },
            'WA': {
                'label': 'Western Australia\'s Place Names Gazetteer',
                'uri_id': 'wa'
            }
        }

        self.register = {'label': None, 'uri': None}

        self.wasNamedBy = {'label': None, 'uri': None}

        self.hasNameFormality = {
            'label':
            'Official',
            'uri':
            'http://linked.data.gov.au/def/placenames/nameFormality/Official'
        }

        self.modifiedDate = None

        self.hasPronunciation = 'abcABCabc'

        q = '''
            SELECT 
              	"NAME",
                "AUTHORITY",
                "SUPPLY_DATE"
            FROM "PLACENAMES"
            WHERE "ID" = '{}'
        '''.format(self.id)
        for placename in conf.db_select(q):
            self.hasName['value'] = str(placename[0])
            self.register['label'] = str(placename[1])
            self.register[
                'uri'] = 'http://linked.data.gov.au/dataset/placenames/gazetteer/' + str(
                    placename[1])
            self.modifiedDate = placename[2]

        naming_authorities = {
            'ACT': {
                'label': 'Australian Capital Territory',
                'uri_id': 'act'
            },
            'AAD': {
                'label': 'Australian Antarctic Division',
                'uri_id': 'aad'
            },
            'WA': {
                'label': 'Western Australian Government',
                'uri_id': 'wa'
            }
        }