Esempio n. 1
0
    def decorate_queryset(
        cls,
        feature_type: FeatureType,
        queryset: models.QuerySet,
        output_crs: CRS,
        **params,
    ):
        """Update the queryset to let the database render the GML output.
        This is far more efficient then GeoDjango's logic, which performs a
        C-API call for every single coordinate of a geometry.
        """
        queryset = super().decorate_queryset(feature_type, queryset,
                                             output_crs, **params)

        # Retrieve geometries as pre-rendered instead.
        gml_elements = feature_type.xsd_type.geometry_elements
        geo_selects = get_db_geometry_selects(gml_elements, output_crs)
        if geo_selects:
            queryset = queryset.defer(*geo_selects.keys()).annotate(
                _as_envelope_gml=cls.get_db_envelope_as_gml(
                    feature_type, queryset, output_crs),
                **build_db_annotations(geo_selects, "_as_gml_{name}", AsGML),
            )

        return queryset
Esempio n. 2
0
    def decorate_queryset(
        cls,
        feature_type: FeatureType,
        queryset: models.QuerySet,
        output_crs: CRS,
        **params,
    ) -> models.QuerySet:
        queryset = super().decorate_queryset(feature_type, queryset,
                                             output_crs, **params)

        # Instead of reading the binary geometry data,
        # ask the database to generate EWKT data directly.
        geo_selects = get_db_geometry_selects(
            feature_type.xsd_type.geometry_elements, output_crs)
        if geo_selects:
            queryset = queryset.defer(*geo_selects.keys()).annotate(
                **build_db_annotations(geo_selects, "_as_ewkt_{name}", AsEWKT))

        return queryset
Esempio n. 3
0
    def decorate_queryset(
        cls,
        feature_type: FeatureType,
        queryset: models.QuerySet,
        output_crs: CRS,
        **params,
    ):
        queryset = super().decorate_queryset(feature_type, queryset,
                                             output_crs, **params)

        # Other geometries can be excluded as these are not rendered by 'properties'
        other_geometries = [
            model_field.name for model_field in feature_type.geometry_fields
            if model_field is not feature_type.geometry_field
        ]
        if other_geometries:
            queryset = queryset.defer(*other_geometries)

        return queryset