예제 #1
0
def stats(dataset_name, query):
    try:
        area = query.get('area')
        data = None

        for idx, a in enumerate(area):
            if isinstance(a, str):
                sp = a.split('/', 1)
                if data is None:
                    data = list_areas(sp[0], simplify=False)

                b = [x for x in data if x.get('key') == a]
                a = b[0]
                area[idx] = a
                
        points_lat =[]
        for p in area[0]['polygons'][0]:
            points_lat.append(p[1])
    except Exception as e:
        raise ServerError(gettext("Unknown Error: you have tried something that we did not expect. \
                                Please try again or try something else. If you would like to report \
                                this error please contact [email protected]. ") + str(e))
    
    if (max(points_lat)-min(points_lat))>360:
        raise ClientError(gettext("Error: you are trying to create a plot that is wider than the world. \
        The desired information is ambiguous please select a smaller area and try again"))
    elif any((p > 180 or p < -180) for p in points_lat) and any(-180 <= p <= 180 for p in points_lat): #if there area points on both sides of the date line 
        return wrap_computer_stats(query, dataset_name, points_lat)
    else:   # no world wrap
        return computer_stats(area, query, dataset_name)   

    raise ServerError(gettext("Unknown Error: you have tried something that we did not expect. \
                        Please try again or try something else. If you would like to report \
                        this error please contact [email protected]"))
예제 #2
0
    def parse_query(self, query):
        super(MapPlotter, self).parse_query(query)

        self.projection = query.get('projection')

        self.area = query.get('area')

        names = []
        centroids = []
        all_rings = []
        data = None
        for idx, a in enumerate(self.area):
            if isinstance(a, str):

                sp = a.split('/', 1)
                if data is None:
                    data = list_areas(sp[0], simplify=False)

                b = [x for x in data if x.get('key') == a]
                a = b[0]
                self.area[idx] = a
            else:
                self.points = copy.deepcopy(np.array(a['polygons']))
                a['polygons'] = self.points.tolist()
                a['name'] = " "

            rings = [LinearRing(po) for po in a['polygons']]
            if len(rings) > 1:
                u = cascaded_union(rings)
            else:
                u = rings[0]

            all_rings.append(u)
            if a.get('name'):
                names.append(a.get('name'))
                centroids.append(u.centroid)
        nc = sorted(zip(names, centroids))
        self.names = [n for (n, c) in nc]
        self.centroids = [c for (n, c) in nc]
        data = None

        if len(all_rings) > 1:
            combined = cascaded_union(all_rings)
        else:
            combined = all_rings[0]

        self.combined_area = combined
        combined = combined.envelope

        self.centroid = list(combined.centroid.coords)[0]
        self.bounds = combined.bounds

        self.show_bathymetry = bool(query.get('bathymetry'))
        self.show_area = bool(query.get('showarea'))

        self.quiver = query.get('quiver')

        self.contour = query.get('contour')
    def parse_query(self, query):
        super().parse_query(query)

        if len(self.variables) > 1:
            raise ClientError(f"MapPlotter only supports 1 variable. \
                    Received multiple: {self.variables}")

        self.projection = query.get("projection")

        self.area = query.get("area")

        names = []
        centroids = []
        all_rings = []
        data = None
        for idx, a in enumerate(self.area):
            if isinstance(a, str):

                sp = a.split("/", 1)
                if data is None:
                    data = list_areas(sp[0], simplify=False)

                b = [x for x in data if x.get("key") == a]
                a = b[0]
                self.area[idx] = a
            else:
                self.points = copy.deepcopy(np.array(a["polygons"]))
                a["polygons"] = self.points.tolist()
                a["name"] = " "

            rings = [LinearRing(po) for po in a["polygons"]]
            if len(rings) > 1:
                u = cascaded_union(rings)
            else:
                u = rings[0]

            all_rings.append(u)
            if a.get("name"):
                names.append(a.get("name"))
                centroids.append(u.centroid)
        nc = sorted(zip(names, centroids))
        self.names = [n for (n, c) in nc]
        self.centroids = [c for (n, c) in nc]
        data = None

        if len(all_rings) > 1:
            combined = cascaded_union(all_rings)
        else:
            combined = all_rings[0]

        self.combined_area = combined
        combined = combined.envelope

        self.centroid = list(combined.centroid.coords)[0]
        self.bounds = combined.bounds

        self.show_bathymetry = bool(query.get("bathymetry"))
        self.show_area = bool(query.get("showarea"))

        self.quiver = query.get("quiver")

        self.contour = query.get("contour")