Ejemplo n.º 1
0
    def export_html(self, view='geofabric'):
        bbox = self.get_bbox(pad=12)
        bbox_string = ",".join(str(i) for i in bbox)
        centrepoint = []
        centrepoint.append(bbox[0] + ((bbox[2] - bbox[0]) / 2))
        centrepoint.append(bbox[1] + ((bbox[3] - bbox[1]) / 2))
        hydroid = self.hydroid
        try:
            concatid = self.concatid
        except AttributeError:
            concatid = None
        wms_url = config.GF_OWS_ENDPOINT +\
                  "?service=wms&version=2.0.0&request=GetMap" \
                  "&width=800&height=600" \
                  "&format=text/html;+subtype=openlayers" \
                  "&CRS=EPSG:4326" \
                  "&layers=osm_au,ahgf_hrc:AHGFContractedCatchment" \
                  "&style=ahgfcatchment" \
                  "&bbox=" + bbox_string +\
                  "&CQL_FILTER=INCLUDE;hydroid="+str(hydroid)
        m2_area = degrees_area_to_m2(self.shape_area, centrepoint[1])
        if view == 'geofabric':
            view_html = render_template(
                'class_contracted_catchment_geof.html',
                wms_url=wms_url,
                bbox=bbox,
                centrepoint=centrepoint,
                hydroid=hydroid,
                concatid=concatid,
                rrid=self.rrid,
                awraddid=self.awraddid,
                shape_length=self.shape_length,
                shape_area=self.shape_area,
                m2_area=m2_area,
                albers_area=self.albersarea,
            )
        elif view == "hyfeatures":
            view_html = render_template(
                'class_contracted_catchment_hyf.html',
                wms_url=wms_url,
                bbox=bbox,
                centrepoint=centrepoint,
                hydroid=hydroid,
                concatid=concatid,
                rrid=self.rrid,
                awraddid=self.awraddid,
                shape_length=self.shape_length,
                shape_area=self.shape_area,
                m2_area=m2_area,
                albers_area=self.albersarea,
            )
        else:
            return NotImplementedError(
                "HTML representation of View '{}' is not implemented.".format(
                    view))

        return view_html
Ejemplo n.º 2
0
    def export_html(self, view='geofabric'):
        bbox = self.get_bbox(pad=12)
        bbox_string = ",".join(str(i) for i in bbox)
        centrepoint = [
            bbox[0] + ((bbox[2] - bbox[0]) / 2),
            bbox[1] + ((bbox[3] - bbox[1]) / 2)
        ]
        hydroid = self.hydroid
        wms_url = config.GF_OWS_ENDPOINT +\
                  "?service=wms&version=2.0.0&request=GetMap" \
                  "&width=800&height=600" \
                  "&format=text/html;+subtype=openlayers" \
                  "&CRS=EPSG:4326" \
                  "&layers=osm_au,ahgf_hrr:AWRADrainageDivision" \
                  "&style=ahgfcatchment" \
                  "&bbox=" + bbox_string +\
                  "&CQL_FILTER=INCLUDE;hydroid="+str(hydroid)
        m2_area = degrees_area_to_m2(self.shape_area, centrepoint[1])
        if view == 'geofabric':
            view_html = render_template(
                'class_awradrainagedivision_geof.html',
                bbox=bbox,
                centrepoint=centrepoint,
                wms_url=wms_url,
                hydroid=hydroid,
                division=self.division,
                divnumber=self.divnumber,
                shape_length=self.shape_length,
                shape_area=self.shape_area,
                albers_area=self.albersarea,
                m2_area=m2_area
            )
        elif view == "hyfeatures":
            view_html = render_template(
                'class_awradrainagedivision_hyf.html',
                bbox=bbox,
                centrepoint=centrepoint,
                wms_url=wms_url,
                hydroid=hydroid,
                division=self.division,
                divnumber=self.divnumber,
                shape_length=self.shape_length,
                shape_area=self.shape_area,
                albers_area=self.albersarea,
                m2_area=m2_area
            )
        else:
            return NotImplementedError("HTML representation of View '{}' is not implemented.".format(view))

        return view_html
Ejemplo n.º 3
0
def contracted_catchment_geofabric_converter(model, wfs_features):
    if len(wfs_features) < 1:
        return None

    if isinstance(wfs_features, (dict, )):
        features_source = wfs_features.items()
    elif isinstance(wfs_features, (list, set)):
        features_source = iter(wfs_features)
    else:
        features_source = [wfs_features]

    triples = set()

    for hydroid, catchment_element in features_source:  # type: int, etree._Element
        feature_uri = rdflib.URIRef("".join(
            [config.URI_CONTRACTED_CATCHMENT_INSTANCE_BASE,
             str(hydroid)]))
        triples.add((feature_uri, RDF_a, GEOF.ContractedCatchment))

        for c in catchment_element.iterchildren():  # type: etree._Element
            var = c.tag.replace('{{{}}}'.format(ns['x']), '')

            # common Geofabric properties
            if var == 'shape_area':
                A = BNode()
                triples.add(
                    (A, QUDTS.numericValue, Literal(c.text,
                                                    datatype=XSD.float)))
                triples.add((A, QUDTS.unit, UNIT.DEG2))
                triples.add((feature_uri, GEOF.shapeArea, A))
                try:
                    A = BNode()
                    degree_area = float(c.text)
                    # Add in the extra converted m2 area
                    bbox = model.get_bbox(pad=12)
                    centrepointX = (bbox[0] + ((bbox[2] - bbox[0]) / 2))
                    centrepointY = (bbox[1] + ((bbox[3] - bbox[1]) / 2))
                    m2_area = degrees_area_to_m2(degree_area, centrepointY)
                    triples.add((A, DATA.value,
                                 Literal(str(Decimal(str(m2_area))),
                                         datatype=XSD.decimal)))
                    triples.add((A, QB4ST.crs, EPSG['4938']))
                    triples.add((feature_uri, GEOX.hasAreaM2, A))
                except ValueError:
                    pass
            elif var == 'albersarea':
                A = BNode()
                triples.add((A, DATA.value,
                             Literal(str(Decimal(str(c.text))),
                                     datatype=XSD.decimal)))
                triples.add((A, QB4ST.crs, EPSG['3577']))
                triples.add((feature_uri, GEOX.hasAreaM2, A))
            elif var == 'shape_length':
                L = BNode()
                triples.add(
                    (L, QUDTS.numericValue, Literal(c.text,
                                                    datatype=XSD.float)))
                triples.add((L, QUDTS.unit, UNIT.DEG))
                triples.add(
                    (feature_uri, GEOF.perimeterLength,
                     L))  # URIRef('http://dbpedia.org/property/length')
            elif var == 'shape':
                #try:
                #    _triples, geometry = gml_extract_geom_to_geosparql(c)
                #    for (s, p, o) in iter(_triples):
                #        triples.add((s, p, o))
                #except KeyError:
                #    val = c.text
                #    geometry = Literal(val)
                #triples.add((feature_uri, GEO_hasGeometry, geometry))
                # TODO: Reenable asGML or asWKT for Geofabric view
                pass
            elif var == 'attrsource':
                triples.add((feature_uri, DC.source, Literal(c.text)))

        # the CC register
        triples.add((feature_uri,
                     URIRef('http://purl.org/linked-data/registry#register'),
                     URIRef(config.URI_CONTRACTED_CATCHMENT_INSTANCE_BASE)))

    return triples, None