Exemplo n.º 1
0
def loadAreaSourceFromSHP(filename_in,
                          mmax_data,
                          background_layer,
                          filename_out=None,
                          layer2file=False,
                          ui_mode=True):
    """Load area source layer from Shapefile, independent of QGis UI."""

    temp_area_source_layer = QgsVectorLayer(filename_in, "Area Sources", "ogr")

    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(
        4326, QgsCoordinateReferenceSystem.PostgisCrsId)

    layer = utils.shp2memory(temp_area_source_layer, "Area Sources")
    layer.setCrs(crs)

    # check if all features are okay
    _checkAreaSourceLayer(layer, ui_mode=ui_mode)

    # assign Mmax from Meletti data set
    assignMmaxfromMelettiDataset(layer, mmax_data)

    # assign attributes from background zones
    assignAttributesFromBackgroundZones(layer,
                                        background_layer,
                                        MCDIST_ATTRIBUTES,
                                        ui_mode=ui_mode)

    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs, ui_mode=ui_mode)

    return layer
Exemplo n.º 2
0
def loadAreaSourceFromSHP(filename_in, mmax_data, background_layer, 
    filename_out=None, layer2file=False, ui_mode=True):
    """Load area source layer from Shapefile, independent of QGis UI."""
    
    temp_area_source_layer = QgsVectorLayer(filename_in, "Area Sources", "ogr")

    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(4326, 
        QgsCoordinateReferenceSystem.PostgisCrsId)

    layer = utils.shp2memory(temp_area_source_layer, "Area Sources")
    layer.setCrs(crs) 

    # check if all features are okay
    _checkAreaSourceLayer(layer, ui_mode=ui_mode)

    # assign Mmax from Meletti data set
    assignMmaxfromMelettiDataset(layer, mmax_data)
    
    # assign attributes from background zones
    assignAttributesFromBackgroundZones(layer, background_layer, 
        MCDIST_ATTRIBUTES, ui_mode=ui_mode)

    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs, ui_mode=ui_mode)
        
    return layer
Exemplo n.º 3
0
def loadBackgroundZoneFromFile(background_mmax_path,
                               background_completeness_path,
                               filename_out=None,
                               layer2file=False,
                               ui_mode=True):
    """Load layer of background zones with completeness history and
    Mmax from ASCII files, independent of QGis UI. 
    """

    # read data dicts from files (coordinates from mmax file)
    background_mmax = readBackgroundMmax(background_mmax_path, ui_mode=ui_mode)
    #QMessageBox.information(None, "Mmax", "%s" % background_mmax)

    background_completeness = readBackgroundCompleteness(
        background_completeness_path, ui_mode=ui_mode)
    #QMessageBox.information(None, "Mc", "%s" % background_completeness)

    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(
        4326, QgsCoordinateReferenceSystem.PostgisCrsId)

    # create layer
    layer = QgsVectorLayer("Polygon", "Background Zones", "memory")
    layer.setCrs(crs)
    pr = layer.dataProvider()

    # add attributes
    # - ID, Mmax, completeness magnitude history
    pr.addAttributes([
        QgsField("ID", QVariant.String),
        QgsField("mmax", QVariant.Double),
        QgsField("mcdist", QVariant.String)
    ])

    # add zones as features
    for zone_id, zone in background_mmax.items():

        f = QgsFeature()

        poly = [QgsPoint(x, y) for (x, y) in zone['coord']]
        f.setGeometry(QgsGeometry.fromPolygon([poly]))

        f[0] = QVariant(zone_id)
        f[1] = QVariant(zone['mmax'])
        f[2] = QVariant(background_completeness[zone_id]['mcdist'])

        pr.addFeatures([f])

    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs, ui_mode=ui_mode)

    return layer
Exemplo n.º 4
0
def loadBackgroundZoneFromFile(background_mmax_path, 
    background_completeness_path, filename_out=None, layer2file=False,
    ui_mode=True):
    """Load layer of background zones with completeness history and
    Mmax from ASCII files, independent of QGis UI. 
    """
    
    # read data dicts from files (coordinates from mmax file)
    background_mmax = readBackgroundMmax(background_mmax_path, ui_mode=ui_mode)
    #QMessageBox.information(None, "Mmax", "%s" % background_mmax)

    background_completeness = readBackgroundCompleteness(
        background_completeness_path, ui_mode=ui_mode)
    #QMessageBox.information(None, "Mc", "%s" % background_completeness)
   
    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(4326, 
        QgsCoordinateReferenceSystem.PostgisCrsId)

    # create layer
    layer = QgsVectorLayer("Polygon", "Background Zones", "memory")
    layer.setCrs(crs) 
    pr = layer.dataProvider()

    # add attributes
    # - ID, Mmax, completeness magnitude history
    pr.addAttributes([QgsField("ID", QVariant.String),
                      QgsField("mmax", QVariant.Double),
                      QgsField("mcdist", QVariant.String)])

    # add zones as features
    for zone_id, zone in background_mmax.items():

        f = QgsFeature()

        poly = [QgsPoint(x, y) for (x, y) in zone['coord']]
        f.setGeometry(QgsGeometry.fromPolygon([poly]))
        
        f[0] = QVariant(zone_id)
        f[1] = QVariant(zone['mmax'])
        f[2] = QVariant(background_completeness[zone_id]['mcdist'])

        pr.addFeatures([f])

    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs, ui_mode=ui_mode)

    return layer
Exemplo n.º 5
0
def loadFaultSourceFromSHP(filename_in, filename_out=None, layer2file=False):
    """Load fault source layer from Shapefile, independent of QGis UI."""

    temp_fault_source_layer = QgsVectorLayer(filename_in, "Fault Sources",
                                             "ogr")

    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(
        4326, QgsCoordinateReferenceSystem.PostgisCrsId)

    layer = utils.shp2memory(temp_fault_source_layer, "Fault Sources")
    layer.setCrs(crs)

    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs)

    return layer
Exemplo n.º 6
0
def loadFaultSourceFromSHP(filename_in, filename_out=None, layer2file=False):
    """Load fault source layer from Shapefile, independent of QGis UI."""
    
    temp_fault_source_layer = QgsVectorLayer(filename_in, "Fault Sources", 
        "ogr")

    # PostGIS SRID 4326 is allocated for WGS84
    crs = QgsCoordinateReferenceSystem(4326, 
        QgsCoordinateReferenceSystem.PostgisCrsId)

    layer = utils.shp2memory(temp_fault_source_layer, "Fault Sources")
    layer.setCrs(crs) 
    
    # write memory layer to disk (as a Shapefile)
    if layer2file is True:
        utils.writeLayerToShapefile(layer, filename_out, crs)
    
    return layer