예제 #1
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"
예제 #2
0
파일: mwp.py 프로젝트: yataOrg/skylines
    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")