Example #1
0
    def __init__(self, **kwargs):
        super(SweTimeSeries,self).__init__(**kwargs)

        # Parse out GML point.  Defaults to 0 depth if none specified
        self.geo_srs = Crs(testXMLAttribute(self._location.find(nsp("Point", self.GML_NS)), 'srsName'))
        geo = [float(v) for v in testXMLValue(self._location.find(nsp("Point/pos", self.GML_NS))).split(" ")]

        if self.geo_srs.axisorder == "yx":
            self.geo = sPoint(geo[1], geo[0])
        else:
            self.geo = sPoint(geo[0], geo[1])

        try:
            self.geo.z = geo[2]
        except:
            pass


        pc = PointCollection()

        for row in self.results.data:
            p = Point()

            time = None
            z = None
            lat = None
            lon = None

            for field in row:

                if field.axis == "time":
                    t = dateutil.parser.parse(field.value)
                    p.time = t.astimezone(dateutil.tz.tzutc())
                elif field.axis == "Long":
                    lon = field
                elif field.axis == "Lat":
                    lat = field
                elif field.axis == "h":
                    z = field
                else:
                    m = Member(value=field.value,
                               unit=field.units,
                               units_definition=field.units_url,
                               name=field.name,
                               definition=field.definition,
                               standard=field.definition)
                    p.add_member(m)

            # Set the spatial point
            if lon.srs != lat.srs:
                raise ValueError("Longitude and Latitude need to have the same SRS/CRS!")
            p.location = sPoint(float(lon.value), float(lat.value), float(z.value))
            pc.add_element(p)


        self.data = pc
    def calculate_bounds(self):
        """
            Calculate the time_range, bbox, and size of this collection.
            Will scan all data.
            Ensures that .size, .bbox and .time_range return non-null.

            If the collection already knows its bbox; time_range; and/or size,
            they are recomputed.
        """
        single_point_collection = PointCollection(elements=list(AsaList.flatten(self)))
        single_point_collection.calculate_bounds()
        self.bbox = single_point_collection.bbox
        self.time_range = single_point_collection.time_range
        self.depth_range = single_point_collection.depth_range
        self._point_size = single_point_collection.size
        self.size = len(self._elements)
    def calculate_bounds(self):
        """
            Calculate the time_range, bbox, and size of this collection.
            Will scan all data.
            Ensures that .size, .bbox and .time_range return non-null.

            If the collection already knows its bbox; time_range; and/or size,
            they are recomputed.
        """
        single_point_collection = PointCollection(
            elements=list(AsaList.flatten(self)))
        single_point_collection.calculate_bounds()
        self.bbox = single_point_collection.bbox
        self.time_range = single_point_collection.time_range
        self.depth_range = single_point_collection.depth_range
        self._point_size = single_point_collection.size
        self.size = len(self._elements)
Example #4
0
    def test_point_collection(self):
        dt1 = datetime.date(2007, 12, 5)
        p1 = Point()
        p1.time = dt1
        p1.location = sPoint(-180, -90, 0)
        member1 = Member(value=5.4, unit='m', name='Sea Surface Height', description='sea height', standard='sea_surface_height')
        member2 = Member(value=8.1, unit='m', name='Wave Height', description='wave height', standard='wave_height')
        p1.add_member(member1)
        p1.add_member(member2)

        dt2 = datetime.date(2008, 2, 14)
        p2 = Point()
        p2.time = dt2
        p2.location = sPoint(-120, 50, 10)
        member3 = Member(value=5.4, unit='m', name='Sea Surface Height', description='sea height', standard='sea_surface_height')
        member4 = Member(value=8.1, unit='m', name='Wave Height', description='wave height', standard='wave_height')
        p2.add_member(member3)
        p2.add_member(member4)

        pc = PointCollection(elements=[p1,p2])
        pc.calculate_bounds()

        assert pc.size == 2
        assert pc.time_range[0] == dt1
        assert pc.time_range[-1] == dt2
        assert pc.depth_range[0] == p1.location.z
        assert pc.depth_range[-1] == p2.location.z
        assert pc.upper_right().equals(sPoint(p2.location.x, p2.location.y))
        assert pc.lower_left().equals(sPoint(p1.location.x, p1.location.y))
        
Example #5
0
    def __init__(self, **kwargs):
        super(SweTimeSeries, self).__init__(**kwargs)

        # Parse out GML point.  Defaults to 0 depth if none specified
        self.geo_srs = Crs(
            testXMLAttribute(self._location.find(nsp("Point", self.GML_NS)),
                             'srsName'))
        geo = [
            float(v) for v in testXMLValue(
                self._location.find(nsp("Point/pos", self.GML_NS))).split(" ")
        ]

        if self.geo_srs.axisorder == "yx":
            self.geo = sPoint(geo[1], geo[0])
        else:
            self.geo = sPoint(geo[0], geo[1])

        try:
            self.geo.z = geo[2]
        except:
            pass

        pc = PointCollection()

        for row in self.results.data:
            p = Point()

            time = None
            z = None
            lat = None
            lon = None

            for field in row:

                if field.axis == "time":
                    t = dateutil.parser.parse(field.value)
                    p.time = t.astimezone(dateutil.tz.tzutc())
                elif field.axis == "Long":
                    lon = field
                elif field.axis == "Lat":
                    lat = field
                elif field.axis == "h":
                    z = field
                else:
                    m = Member(value=field.value,
                               unit=field.units,
                               units_definition=field.units_url,
                               name=field.name,
                               definition=field.definition,
                               standard=field.definition)
                    p.add_member(m)

            # Set the spatial point
            if lon.srs != lat.srs:
                raise ValueError(
                    "Longitude and Latitude need to have the same SRS/CRS!")
            p.location = sPoint(float(lon.value), float(lat.value),
                                float(z.value))
            pc.add_element(p)

        self.data = pc