Example #1
0
def roads():
    # Search specific items using keywords
    search_string = request.values.get('search')

    try:

        # get the register length from the online DB
        sql = 'SELECT COUNT(*) FROM "transportroads"'
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("name") LIKE '%{search_string}%';
                   '''.format(search_string=search_string.strip().upper())

        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

        # get the id and name for each record in the database
        sql = '''SELECT "id", "name" FROM "transportroads"'''
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("name") LIKE '%{search_string}%'
                   '''.format(search_string=search_string.strip().upper())
        sql += '''ORDER BY "name"
                OFFSET {} LIMIT {}'''.format(offset, per_page)

        items = []
        for item in conf.db_select(sql):
            items.append((item[0], item[1]))
    except Exception as e:
        print(e)
        return Response('The Roads database is offline',
                        mimetype='text/plain',
                        status=500)

    return ContainerRenderer(
        request=request,
        instance_uri=request.url,
        label='Roads Register',
        comment='A register of Roads',
        parent_container_uri=
        'http://linked.data.gov.au/def/placenames/PlaceName',
        parent_container_label='QLD_Roads',
        members=items,
        members_total_count=no_of_items,
        profiles=None,
        default_profile_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 #2
0
def get_register_items():
    # Search specific items using keywords
    search_string = request.values.get('search')
    try:
        # get the register length from the online DB
        # sql = 'SELECT COUNT(*) FROM "AEIP_SA1join84"'
        sql = 'SELECT COUNT(*) FROM "{table}"'.format(table=TABLE_NAME)
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("{name}") LIKE '%{search_string}%';
                   '''.format(name=NAME_FIELD, search_string=search_string.strip().upper())

        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

        # get the id and name for each record in the database
        sql = '''SELECT "id", "{name}" FROM "{table}"'''.format(name=NAME_FIELD, table=TABLE_NAME)
        if search_string:
            sql += '''WHERE UPPER(cast("id" as text)) LIKE '%{search_string}%' OR UPPER("{name}") LIKE '%{search_string}%'
                   '''.format(name=NAME_FIELD, search_string=search_string.strip().upper())
        sql += '''ORDER BY "{name}"
                OFFSET {offset} LIMIT {per_page}'''.format(name=NAME_FIELD, offset=offset, per_page=per_page)

        items = []
        for item in conf.db_select(sql):
            items.append(
                (item[0], item[1])
            )
    except Exception as e:
        print(e)
        return Response('The database is offline', mimetype='text/plain', status=500)

    return ContainerRenderer(request=request,
                            instance_uri=request.url,
                            label='SA1 with AEIP Register',
                            comment='A register of SA1s with info from AEIP (Australian Exposure Information Platform)',
                            parent_container_uri='http://linked.data.gov.au/def/placenames/PlaceName',
                            parent_container_label='SA1',
                            members=items,
                            members_total_count=no_of_items,
                            profiles=None,
                            default_profile_token=None,
                            super_register=None,
                            page_size_max=1000,
                            register_template=None,
                            per_page=per_page,
                            search_query=search_string,
                            search_enabled=True
                            ).render()
    def __init__(self, request, uri):
        format_list = ['text/html', 'text/turtle', 'application/ld+json', 'application/rdf+xml']
        views = {
            'Power substation': Profile(
                'http://linked.data.gov.au/def/power/',
                'Power Station View',
                'This view is for power station delivered by the power sub station dataset'
                ' in accordance with the Power Station Profile',
                format_list,
                'text/html'
            )
        }

        super(Power_substation, self).__init__(request, uri, views, 'Power substation')

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

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

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

        # self.uri = None
        # self.feature_type = None
        # self.operational_status = None
        # self.custodian_agency = None
        # self.physical_condition = None
        # self.power_source = None
        # self.substation_class = None
        # self.structuretype = None
        # self.voltage = None
        # self.address = None
        # self.textnote = None
        # self.wkt = None


        q = '''
            SELECT
                "name",
                "uri",
                "feature_type",
                "operational_status",
                "custodian_agency",
                "physical_condition",
                "power_source",
                "class",
                "structuretype",
                "voltage",
                "address",
                "textnote",
                "feature_date",
                "feature_source",
                "attribute_date",
                "attribute_source",
                "vertical_accuracy",
                "planimetric_accuracy",
                "source_ufi",
                "source_jurisdiction",                                
                "custodian_licensing",
                "loading_date",
                ST_AsEWKT(geom) As geom_wkt,                
                ST_AsGeoJSON(geom) As geom
            FROM "power_substation_points84"
            WHERE "id" = '{}'
        '''.format(self.id)

        for row in conf.db_select(q):
            self.hasName['value'] = str(row[0])
            self.uri = row[1]
            self.feature_type = row[2]
            self.operational_status = row[3]
            self.custodian_agency = row[4]
            self.physical_condition = row[5]
            self.power_source = row[6]
            self.substation_class = row[7]
            self.structuretype = row[8]
            self.voltage = row[9]
            self.address = row[10]
            self.textnote = row[11]
            self.feature_date = row[12]
            self.feature_source = row[13]
            self.attribute_date = row[14]
            self.attribute_source = row[15]
            self.vertical_accuracy = row[16]
            self.planimetric_accuracy = row[17]
            self.source_ufi = row[18]
            self.source_jurisdiction = row[19]
            self.custodian_licensing = row[20]
            self.loading_date = row[21]

            # get geometry from database
            self.geom = ast.literal_eval(row[-1])
            self.coords = self.geom['coordinates']
            self.wkt = row[-2]

            DGGS_uri = 'http://ec2-52-63-73-113.ap-southeast-2.compute.amazonaws.com/AusPIX-DGGS-dataset/ausPIX/'
            resolution = 11
            coords = (self.coords[0], self.coords[1])
            self.thisDGGSCell = rdggs.cell_from_point(resolution, coords,
                                                      plane=False)  # false = on the elipsoidal curve
            self.thisCell['label'] = str(self.thisDGGSCell)
            self.thisCell['uri'] = '{}{}'.format(DGGS_uri, str(self.thisDGGSCell))
    def __init__(self, request, uri):
        format_list = ['text/html', 'text/turtle', 'application/ld+json', 'application/rdf+xml']
        profiles = {
            'Facilities': Profile(
                'http://linked.data.gov.au/def/facilities/',
                'Facilities View',
                'This view is for facilities delivered by the facilities dataset'
                ' in accordance with the Facilities Profile',
                format_list,
                'text/html'
            )
        }

        super(Facilities, self).__init__(request, uri, profiles, 'Facilities')

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

        q = '''
               SELECT
                   "f_name",
                   "auspix_dggs",
                   "uri_auspix",
                   "cellsarea_m2",                   
                   "featuresubtype",
                   "feature_date",
                   "feature_source",
                   "attribute_date",
                   "attribute_source",
                   "source_ufi",
                   "source_jurisdiction",
                   "custodian_agency",
                   "custodian_licensing",
                   "loading_date",
                   "building_id",
                   "main_function",
                   "operationalstatus",
                   "height",
                   "address",
                   "suburb",
                   "local_construction_type",
                   "local_year_built",
                   "state",
                   "category",
                   "facility_type",
                   "xcoord84",
                   "ycoord84",
                   "uri_facility",
                   ST_AsEWKT(geom) As geom_wkt,
                   ST_AsGeoJSON(geom) As geom
               FROM "{}"
               WHERE "id" = '{}'
           '''.format(TABLE_NAME, self.id)

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

        self.thisFeature = []
        self.featureCords = []

        for row in conf.db_select(q):
            self.hasName['value'] = str(row[0])
            self.AusPIX_DGGS = str(row[1])
            self.uri_auspix = row[2]
            self.cellsarea_m2 = str(row[3])
            self.featuresubtype = row[4]
            self.feature_date = str(row[5])
            self.feature_source = row[6]
            self.attribute_date = str(row[7])
            self.attribute_source = row[8]
            self.source_ufi = str(row[9])
            self.source_jurisdiction = row[10]
            self.custodian_agency = row[11]
            self.custodian_licensing = row[12]
            self.loading_date = row[13]
            self.building_id = str(row[14])
            self.main_function = row[15]
            self.operationalstatus = row[16]
            self.height = row[17]
            self.address = row[18]
            self.suburb = row[19]
            self.local_construction_type = row[20]
            self.local_year_built = row[21]
            self.state = row[22]
            self.category = str(row[23])
            self.facility_type = row[24]
            self.xcoord84 = str(row[25])
            self.ycoord84 = row[26]
            self.uri_facility = row[27]

            # get geometry from database
            self.geom = ast.literal_eval(row[-1])
            self.featureCords = self.geom['coordinates']
            self.wkt = row[-2]
            self.geometry_type = self.geom['type']
            self.thisFeature.append({'label': str(self.AusPIX_DGGS),
                                      'uri': self.uri_auspix})
Example #5
0
    def __init__(self, request, uri):
        format_list = [
            'text/html', 'text/turtle', 'application/ld+json',
            'application/rdf+xml'
        ]
        views = {
            # 'NCGA': Profile(
            #     'http://linked.data.gov.au/def/placenames/',
            #     'Place Names View',
            #     'This is the combined view of places and placenmaes delivered by the Place Names dataset in '
            #     'accordance with the Place Names Profile',
            #     format_list,
            #     'text/html'
            # ),
            'Roads':
            Profile(
                'http://linked.data.gov.au/def/roads/', 'Roads View',
                'This view is for roads delivered by the roads dataset'
                ' in accordance with the Roads Profile', format_list,
                'text/html')
        }

        super(Roads, self).__init__(request, uri, views, 'Roads')

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

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

        # self.thisLine = {
        #     'label': None,
        #     'uri': None
        # }

        self.functional_class = None,
        self.surface = None
        self.custodian_agency = None
        self.state_route_number = None
        self.road_direction = None
        self.speedlimit = None
        self.operational_status = None
        self.trafficability = None
        self.national_route_number = None

        self.thisLine = []
        self.lineCords = []

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

        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",
                "uri",
                "functional_class",
                "surface",
                "custodian_agency",
                "state_route_number",
                "road_direction",
                "speedlimit",
                "operational_status",
                "trafficability",
                "national_route_number",
                "featuresubtype", 
                "feature_date",
                "feature_source",
                "attribute_date",
                "attribute_source",
                "vertical_accuracy",
                "planimetric_accuracy",
                "source_ufi",
                "source_jurisdiction",                
                "custodian_licensing",
                "loading_date",
                "shape_length",
                "road_type",
                "road_suffix",
                "ground_relationship",
                "number_of_lanes",
                "seasonality",
                "alternative_name",
                "divided",
                "authority",
                "useraccess",
                ST_AsGeoJSON(geom) As geom
            FROM "transportroads"
            WHERE "id" = '{}'
        '''.format(self.id)

        for road in conf.db_select(q):
            self.hasName['value'] = str(road[0])
            self.uri = road[1]

            self.functional_class = road[2],
            self.surface = road[3]
            self.custodian_agency = road[4]
            self.state_route_number = road[5]
            self.road_direction = road[6]
            self.speedlimit = road[7]
            self.operational_status = road[8]
            self.trafficability = road[9]
            self.national_route_number = road[10]

            # self.authority['label'] = (NAME_AUTHORITIES[str(road[-3])]['label'])
            # self.authority['web'] = (NAME_AUTHORITIES[str(road[-3])]['web'])
            # self.email = (NAME_AUTHORITIES[str(road[-3])]['email'])
            #
            # self.register['uri'] = (GAZETTEERS[str(road[-3])]['uri_id'])
            # self.register['label'] = (GAZETTEERS[str(road[-3])]['label'])

            # get geometry from database
            self.geom = ast.literal_eval(road[-1])
            self.lineCords = self.geom['coordinates']

            # using the web API to find the DGGS cells for the geojson
            dggs_api_param = {'resolution': 9, "dggs_as_polygon": False}

            geo_json = {
                "type": "FeatureCollection",
                "features": [{
                    "type": "Feature",
                    "geometry": self.geom
                }]
            }

            try:
                res = requests.post(
                    '{}find_dggs_by_geojson'.format(DGGS_API_URI),
                    params=dggs_api_param,
                    json=geo_json)
                self.listOfCells = res.json()['dggs_cells']
            except:
                self.listOfCells = get_cells_in_json_and_return_in_json(
                    geo_json, dggs_api_param['resolution'],
                    dggs_api_param['dggs_as_polygon'])['dggs_cells']

            for cell in self.listOfCells:
                self.thisLine.append({
                    'label': str(cell),
                    'uri': '{}{}'.format(DGGS_uri, str(cell))
                })
    def __init__(self, request, uri):
        format_list = [
            'text/html', 'text/turtle', 'application/ld+json',
            'application/rdf+xml'
        ]
        views = {
            # 'NCGA': Profile(
            #     'http://linked.data.gov.au/def/placenames/',
            #     'Place Names View',
            #     'This is the combined view of places and placenmaes delivered by the Place Names dataset in '
            #     'accordance with the Place Names Profile',
            #     format_list,
            #     'text/html'
            # ),
            'Power line':
            Profile(
                'http://linked.data.gov.au/def/power/', 'Power Line View',
                'This view is for power line delivered by the power line dataset'
                ' in accordance with the Power Line Profile', format_list,
                'text/html')
        }

        super(Power_line, self).__init__(request, uri, views, 'Power line')

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

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

        # self.thisLine = {
        #     'label': None,
        #     'uri': None
        # }

        # self.featuretype = None
        # self.descripton = None
        # self.lineclass = None
        # self.operationalstatus = None,
        # self.capacitykv = None
        # self.planimetricaccuracy = None
        # self.state = None
        # self.attributesource = None
        # self.attributedate = None
        # self.featuresource = None
        # self.featuredate = None
        # self.spatialconfidence = None
        # self.wkt = None

        self.thisLine = []
        self.lineCords = []

        q = '''
            SELECT
                "NAME",
                "FEATURETYPE",
                "DESCRIPTON",
                "CLASS",
                "OPERATIONALSTATUS",
                "CAPACITYKV",
                "PLANIMETRICACCURACY",
                "STATE",
                "ATTRIBUTESOURCE",
                "ATTRIBUTEDATE",
                "FEATURESOURCE",
                "FEATUREDATE",
                "SPATIALCONFIDENCE",
                "REVISED",
                "COMMENT",
                "Shape_Length",
                ST_AsEWKT(geom) As geom_wkt,
                ST_AsGeoJSON(geom) As geom
            FROM "Transmission_linesV3source84"
            WHERE "id" = '{}'
        '''.format(self.id)

        for power_line in conf.db_select(q):
            self.hasName['value'] = str(power_line[0])
            # self.uri = power_line[1]
            self.featuretype = '_'.join(str(power_line[1]).split())
            self.descripton = power_line[2]
            self.lineclass = power_line[3]

            self.operationalstatus = power_line[4],
            if type(self.operationalstatus) is tuple:
                self.operationalstatus = self.operationalstatus[0]
            self.capacitykv = power_line[5]
            self.planimetricaccuracy = power_line[6]
            self.state = power_line[7]
            self.attributesource = power_line[8]
            self.attributedate = power_line[9]
            self.featuresource = power_line[10]
            self.featuredate = power_line[11]
            self.spatialconfidence = power_line[12]

            # get geometry from database
            self.geom = ast.literal_eval(power_line[-1])
            self.lineCords = self.geom['coordinates']
            self.wkt = power_line[-2]
            self.geometry_type = self.geom['type']

            # using the web API to find the DGGS cells for the geojson
            dggs_api_param = {'resolution': 9, "dggs_as_polygon": False}

            geo_json = {
                "type": "FeatureCollection",
                "features": [{
                    "type": "Feature",
                    "geometry": self.geom
                }]
            }

            try:
                res = requests.post(
                    '{}find_dggs_by_geojson'.format(DGGS_API_URI),
                    params=dggs_api_param,
                    json=geo_json)
                self.listOfCells = res.json()['dggs_cells']
            except:
                self.listOfCells = get_cells_in_json_and_return_in_json(
                    geo_json, dggs_api_param['resolution'],
                    dggs_api_param['dggs_as_polygon'])['dggs_cells']

            for cell in self.listOfCells:
                self.thisLine.append({
                    'label': str(cell),
                    'uri': '{}{}'.format(DGGS_uri, str(cell))
                })