Example #1
0
def get_waves_by_location(location):
    if not isinstance(location, Location):
        raise TypeError('Invalid `location` parameter.')

    waves = MountainWaveProject.by_location(location)
    data, errors = wave_list_schema.dump(waves, many=True)
    return data
Example #2
0
def _list():
    location = parse_location(request.args)

    airspaces = airspace_list_schema.dump(Airspace.by_location(location).all(), many=True).data
    waves = wave_list_schema.dump(MountainWaveProject.by_location(location), many=True).data

    return jsonify(airspaces=airspaces, waves=waves)
Example #3
0
def list():
    location = parse_location(request.args)

    airspaces = airspace_list_schema.dump(Airspace.by_location(location).all(),
                                          many=True).data
    waves = wave_list_schema.dump(MountainWaveProject.by_location(location),
                                  many=True).data

    return jsonify(airspaces=airspaces, waves=waves)
Example #4
0
File: api.py Project: dkm/skylines
    def mountain_wave_project(self, **kwargs):
        try:
            latitude = float(kwargs['lat'])
            longitude = float(kwargs['lon'])

        except (KeyError, ValueError):
            raise HTTPBadRequest

        location = Location(latitude=latitude,
                            longitude=longitude)

        mwp = MountainWaveProject.get_info(location)

        mwp_info = []
        for wave in mwp:
            mwp_info.append(dict(name=wave.name,
                                 main_wind_direction=wave.main_wind_direction
                                 ))

        return dict(waves=mwp_info)
Example #5
0
def main():
    mwp_center_file = ogr.Open(args.center_shapefile)
    if not mwp_center_file:
        return

    mwp_ext_file = ogr.Open(args.extend_shapefile)
    if not mwp_ext_file:
        return

    mwp_center_layer = mwp_center_file.GetLayerByIndex(0)
    mwp_ext_layer = mwp_ext_file.GetLayerByIndex(0)

    center_feature = mwp_center_layer.GetFeature(0)
    ext_feature = mwp_ext_layer.GetFeature(0)

    # it seems we have some data in the files. clear mwp table first
    db.session.query(MountainWaveProject).delete()

    i = 0
    j = 0
    while (center_feature):
        center_feature = mwp_center_layer.GetFeature(i)
        ext_feature = mwp_ext_layer.GetFeature(i)

        i += 1

        if not center_feature:
            continue

        name = center_feature.GetFieldAsString('name') \
            .strip()
        country = center_feature.GetFieldAsString('country').strip()
        vertical_value = center_feature.GetFieldAsDouble('verticalve')
        synoptical = center_feature.GetFieldAsString('synoptical').strip()

        if center_feature.GetFieldAsString('mainwinddi').strip() != "None":
            main_wind_direction = center_feature \
                .GetFieldAsString('mainwinddi').strip()
        else:
            main_wind_direction = None

        additional = center_feature.GetFieldAsString('additional').strip()
        source = center_feature.GetFieldAsString('source').strip()
        remark1 = center_feature.GetFieldAsString('remark1').strip()
        remark2 = center_feature.GetFieldAsString('remark2').strip()
        orientation = center_feature.GetFieldAsDouble('orientatio')
        rotor_height = center_feature.GetFieldAsString('rotorheigh').strip()
        weather_dir = parse_wind_direction(main_wind_direction)
        location = center_feature.geometry()

        if ext_feature:
            axis_length = ext_feature.GetFieldAsDouble('shape_leng')
            axis = ext_feature.geometry().ExportToWkt()
        else:
            axis_length = None
            axis = None

        wave = MountainWaveProject()
        wave.name = name
        wave.country = country
        wave.vertical_value = vertical_value
        wave.synoptical = synoptical
        wave.main_wind_direction = main_wind_direction
        wave.additional = additional
        wave.source = source
        wave.remark1 = remark1
        wave.remark2 = remark2
        wave.orientation = orientation
        wave.rotor_height = rotor_height
        wave.weather_dir = weather_dir
        wave.axis = WKTElement(axis, srid=4326)
        wave.axis_length = axis_length
        wave.location = WKTElement(location.ExportToWkt(), srid=4326)
        wave.ellipse = ellipse(axis_length / 2, axis_length / 8, -orientation,
                               location.GetX(), location.GetY())

        db.session.add(wave)

        if i % 100 == 0:
            print "inserting geometry " + str(i)

        j += 1

    mwp_center_file.Destroy()
    mwp_ext_file.Destroy()
    db.session.commit()

    print "added " + str(j) + " waves"
Example #6
0
    def run(self, center_shapefile, extend_shapefile):
        from osgeo import ogr

        mwp_center_file = ogr.Open(center_shapefile)
        if not mwp_center_file:
            return

        mwp_ext_file = ogr.Open(extend_shapefile)
        if not mwp_ext_file:
            return

        mwp_center_layer = mwp_center_file.GetLayerByIndex(0)
        mwp_ext_layer = mwp_ext_file.GetLayerByIndex(0)

        center_feature = mwp_center_layer.GetFeature(0)
        ext_feature = mwp_ext_layer.GetFeature(0)

        # it seems we have some data in the files. clear mwp table first
        db.session.query(MountainWaveProject).delete()

        i = 0
        j = 0
        while center_feature:
            center_feature = mwp_center_layer.GetFeature(i)
            ext_feature = mwp_ext_layer.GetFeature(i)

            i += 1

            if not center_feature:
                continue

            name = center_feature.GetFieldAsString("name").strip()
            country = center_feature.GetFieldAsString("country").strip()
            vertical_value = center_feature.GetFieldAsDouble("verticalve")
            synoptical = center_feature.GetFieldAsString("synoptical").strip()

            if center_feature.GetFieldAsString("mainwinddi").strip() != "None":
                main_wind_direction = center_feature.GetFieldAsString(
                    "mainwinddi").strip()
            else:
                main_wind_direction = None

            additional = center_feature.GetFieldAsString("additional").strip()
            source = center_feature.GetFieldAsString("source").strip()
            remark1 = center_feature.GetFieldAsString("remark1").strip()
            remark2 = center_feature.GetFieldAsString("remark2").strip()
            orientation = center_feature.GetFieldAsDouble("orientatio")
            rotor_height = center_feature.GetFieldAsString(
                "rotorheigh").strip()
            weather_dir = self.parse_wind_direction(main_wind_direction)
            location = center_feature.geometry()

            if ext_feature:
                axis_length = ext_feature.GetFieldAsDouble("shape_leng")
                axis = ext_feature.geometry().ExportToWkt()
            else:
                axis_length = None
                axis = None

            wave = MountainWaveProject()
            wave.name = name
            wave.country = country
            wave.vertical_value = vertical_value
            wave.synoptical = synoptical
            wave.main_wind_direction = main_wind_direction
            wave.additional = additional
            wave.source = source
            wave.remark1 = remark1
            wave.remark2 = remark2
            wave.orientation = orientation
            wave.rotor_height = rotor_height
            wave.weather_dir = weather_dir
            wave.axis = WKTElement(axis, srid=4326)
            wave.axis_length = axis_length
            wave.location = WKTElement(location.ExportToWkt(), srid=4326)
            wave.ellipse = self.ellipse(
                axis_length / 2,
                axis_length / 8,
                -orientation,
                location.GetX(),
                location.GetY(),
            )

            db.session.add(wave)

            if i % 100 == 0:
                print("inserting geometry " + str(i))

            j += 1

        mwp_center_file.Destroy()
        mwp_ext_file.Destroy()
        db.session.commit()

        print("added " + str(j) + " waves")
Example #7
0
def get_waves_by_location(location):
    waves = MountainWaveProject.by_location(location)
    data, errors = wave_list_schema.dump(waves, many=True)
    return data
Example #8
0
def main():
    mwp_center_file = ogr.Open(args.center_shapefile)
    if not mwp_center_file:
        return

    mwp_ext_file = ogr.Open(args.extend_shapefile)
    if not mwp_ext_file:
        return

    mwp_center_layer = mwp_center_file.GetLayerByIndex(0)
    mwp_ext_layer = mwp_ext_file.GetLayerByIndex(0)

    center_feature = mwp_center_layer.GetFeature(0)
    ext_feature = mwp_ext_layer.GetFeature(0)

    # it seems we have some data in the files. clear mwp table first
    db.session.query(MountainWaveProject).delete()

    i = 0
    j = 0
    while(center_feature):
        center_feature = mwp_center_layer.GetFeature(i)
        ext_feature = mwp_ext_layer.GetFeature(i)

        i += 1

        if not center_feature:
            continue

        name = center_feature.GetFieldAsString('name') \
            .strip()
        country = center_feature.GetFieldAsString('country').strip()
        vertical_value = center_feature.GetFieldAsDouble('verticalve')
        synoptical = center_feature.GetFieldAsString('synoptical').strip()

        if center_feature.GetFieldAsString('mainwinddi').strip() != "None":
            main_wind_direction = center_feature \
                .GetFieldAsString('mainwinddi').strip()
        else:
            main_wind_direction = None

        additional = center_feature.GetFieldAsString('additional').strip()
        source = center_feature.GetFieldAsString('source').strip()
        remark1 = center_feature.GetFieldAsString('remark1').strip()
        remark2 = center_feature.GetFieldAsString('remark2').strip()
        orientation = center_feature.GetFieldAsDouble('orientatio')
        rotor_height = center_feature.GetFieldAsString('rotorheigh').strip()
        weather_dir = parse_wind_direction(main_wind_direction)
        location = center_feature.geometry()

        if ext_feature:
            axis_length = ext_feature.GetFieldAsDouble('shape_leng')
            axis = ext_feature.geometry().ExportToWkt()
        else:
            axis_length = None
            axis = None

        wave = MountainWaveProject()
        wave.name = name
        wave.country = country
        wave.vertical_value = vertical_value
        wave.synoptical = synoptical
        wave.main_wind_direction = main_wind_direction
        wave.additional = additional
        wave.source = source
        wave.remark1 = remark1
        wave.remark2 = remark2
        wave.orientation = orientation
        wave.rotor_height = rotor_height
        wave.weather_dir = weather_dir
        wave.axis = WKTElement(axis, srid=4326)
        wave.axis_length = axis_length
        wave.location = WKTElement(location.ExportToWkt(), srid=4326)
        wave.ellipse = ellipse(axis_length / 2,
                               axis_length / 8,
                               -orientation,
                               location.GetX(),
                               location.GetY())

        db.session.add(wave)

        if i % 100 == 0:
            print "inserting geometry " + str(i)

        j += 1

    mwp_center_file.Destroy()
    mwp_ext_file.Destroy()
    db.session.commit()

    print "added " + str(j) + " waves"
Example #9
0
def get_waves_by_location(location):
    if not isinstance(location, Location):
        raise TypeError('Invalid `location` parameter.')

    waves = MountainWaveProject.by_location(location)
    return map(wave_to_dict, waves)
Example #10
0
    def run(self, center_shapefile, extend_shapefile):
        from osgeo import ogr

        mwp_center_file = ogr.Open(center_shapefile)
        if not mwp_center_file:
            return

        mwp_ext_file = ogr.Open(extend_shapefile)
        if not mwp_ext_file:
            return

        mwp_center_layer = mwp_center_file.GetLayerByIndex(0)
        mwp_ext_layer = mwp_ext_file.GetLayerByIndex(0)

        center_feature = mwp_center_layer.GetFeature(0)
        ext_feature = mwp_ext_layer.GetFeature(0)

        # it seems we have some data in the files. clear mwp table first
        db.session.query(MountainWaveProject).delete()

        i = 0
        j = 0
        while center_feature:
            center_feature = mwp_center_layer.GetFeature(i)
            ext_feature = mwp_ext_layer.GetFeature(i)

            i += 1

            if not center_feature:
                continue

            name = center_feature.GetFieldAsString("name").strip()
            country = center_feature.GetFieldAsString("country").strip()
            vertical_value = center_feature.GetFieldAsDouble("verticalve")
            synoptical = center_feature.GetFieldAsString("synoptical").strip()

            if center_feature.GetFieldAsString("mainwinddi").strip() != "None":
                main_wind_direction = center_feature.GetFieldAsString(
                    "mainwinddi"
                ).strip()
            else:
                main_wind_direction = None

            additional = center_feature.GetFieldAsString("additional").strip()
            source = center_feature.GetFieldAsString("source").strip()
            remark1 = center_feature.GetFieldAsString("remark1").strip()
            remark2 = center_feature.GetFieldAsString("remark2").strip()
            orientation = center_feature.GetFieldAsDouble("orientatio")
            rotor_height = center_feature.GetFieldAsString("rotorheigh").strip()
            weather_dir = self.parse_wind_direction(main_wind_direction)
            location = center_feature.geometry()

            if ext_feature:
                axis_length = ext_feature.GetFieldAsDouble("shape_leng")
                axis = ext_feature.geometry().ExportToWkt()
            else:
                axis_length = None
                axis = None

            wave = MountainWaveProject()
            wave.name = name
            wave.country = country
            wave.vertical_value = vertical_value
            wave.synoptical = synoptical
            wave.main_wind_direction = main_wind_direction
            wave.additional = additional
            wave.source = source
            wave.remark1 = remark1
            wave.remark2 = remark2
            wave.orientation = orientation
            wave.rotor_height = rotor_height
            wave.weather_dir = weather_dir
            wave.axis = WKTElement(axis, srid=4326)
            wave.axis_length = axis_length
            wave.location = WKTElement(location.ExportToWkt(), srid=4326)
            wave.ellipse = self.ellipse(
                axis_length / 2,
                axis_length / 8,
                -orientation,
                location.GetX(),
                location.GetY(),
            )

            db.session.add(wave)

            if i % 100 == 0:
                print("inserting geometry " + str(i))

            j += 1

        mwp_center_file.Destroy()
        mwp_ext_file.Destroy()
        db.session.commit()

        print("added " + str(j) + " waves")
Example #11
0
def main():
    mwp_center_file = ogr.Open(sys.argv[1])
    if not mwp_center_file:
        return

    mwp_ext_file = ogr.Open(sys.argv[2])
    if not mwp_ext_file:
        return

    mwp_center_layer = mwp_center_file.GetLayerByIndex(0)
    mwp_ext_layer = mwp_ext_file.GetLayerByIndex(0)

    center_feature = mwp_center_layer.GetFeature(0)
    ext_feature = mwp_ext_layer.GetFeature(0)
    i = 0
    j = 0
    while(center_feature):
        center_feature = mwp_center_layer.GetFeature(i)
        ext_feature = mwp_ext_layer.GetFeature(i)

        i += 1

        if not center_feature:
            continue

        name = unicode(center_feature.GetFieldAsString('name'), 'utf-8') \
            .strip()
        country = center_feature.GetFieldAsString('country').strip()
        vertical_value = center_feature.GetFieldAsDouble('verticalve')
        synoptical = center_feature.GetFieldAsString('synoptical').strip()
        main_wind_direction = center_feature.GetFieldAsString('mainwinddi') \
            .strip()
        additional = center_feature.GetFieldAsString('additional').strip()
        source = center_feature.GetFieldAsString('source').strip()
        remark1 = center_feature.GetFieldAsString('remark1').strip()
        remark2 = center_feature.GetFieldAsString('remark2').strip()
        orientation = center_feature.GetFieldAsDouble('orientatio')
        rotor_height = center_feature.GetFieldAsString('rotorheigh').strip()
        weather_dir = center_feature.GetFieldAsInteger('weatherdir')
        location = center_feature.geometry()

        if ext_feature:
            axis_length = ext_feature.GetFieldAsDouble('shape_leng')
            axis = ext_feature.geometry().ExportToWkt()
        else:
            axis_length = None
            axis = None

        wave = MountainWaveProject()
        wave.name = name
        wave.country = country
        wave.vertical_value = vertical_value
        wave.synoptical = synoptical
        wave.main_wind_direction = main_wind_direction
        wave.additional = additional
        wave.source = source
        wave.remark1 = remark1
        wave.remark2 = remark2
        wave.orientation = orientation
        wave.rotor_height = rotor_height
        wave.weather_dir = weather_dir
        wave.axis = WKTElement(axis, srid=4326)
        wave.axis_length = axis_length
        wave.location = WKTElement(location.ExportToWkt(), srid=4326)
        wave.ellipse = ellipse(axis_length / 2,
                               axis_length / 8,
                               -orientation,
                               location.GetX(),
                               location.GetY())

        DBSession.add(wave)

        if i % 100 == 0:
            print "inserting geometry " + str(i)

        j += 1

    mwp_center_file.Destroy()
    mwp_ext_file.Destroy()
    DBSession.flush()
    transaction.commit()

    print "added " + str(j) + " waves"
Example #12
0
def _query_waves(location):
    waves = MountainWaveProject.by_location(location)
    return map(wave_to_json, waves)