Skip to main content
edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
deleted 28 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I can get this value in the code from the server file (see sublayerref below). My problem is I cannot find a way to set this programmatically. 

Does anybody know how to do this?

Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId' field. Any help is much appreciated.

I can get this value in the code from the server file (see sublayerref below). My problem is I cannot find a way to set this programmatically. Does anybody know how to do this?

Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId' field. Any help is much appreciated.

I can get this value in the code from the server file (see sublayerref below). My problem is I cannot find a way to set this programmatically. 

Does anybody know how to do this?

Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId' field.

formatting
Source Link
csk
  • 25.1k
  • 3
  • 33
  • 72

The way it works is, there is a separate application written in asp.net. On On one of the web pages there is a button called 'Digitize'. When the user clicks this it saves a file with the details of the current record, onto the web server.

The user then opens QGIS via a shortcut on their desktop. The QGIS app is locked down with only minimal functionality.

When the project has finished loading, a plugin button becomes available on the toolbar. This button creates a new Vector Layer by connecting to a mssql database. The vector layer name is based on dynamic values in the file on the server, so changes each time. The layer is also removed every time QGIS is started. It displays the features/polygons that have already been added (if there are any).

The user clicks the pencil to begin editing. The user draws a polygon. The user clicks save.

The user is always prompted to enter an id which the record needs as a foreign key in the database. However, the user will never have access to this ID which is a long string e.g. '0000000001-0000000000000264100' that is hidden in the code.

  • When the user clicks this it saves a file with the details of the current record, onto the web server.

  • The user then opens QGIS via a shortcut on their desktop. The QGIS app is locked down with only minimal functionality.

  • When the project has finished loading, a plugin button becomes available on the toolbar. This button creates a new Vector Layer by connecting to a mssql database.

  • The vector layer name is based on dynamic values in the file on the server, so it changes each time.

  • The layer is also removed every time QGIS is started.

  • It displays the features/polygons that have already been added (if there are any).

  • The user clicks the pencil to begin editing.

  • The user draws a polygon.

  • The user clicks save.

  • The user is always prompted to enter an id which the record needs as a foreign key in the database. However, the user will never have access to this ID which is a long string e.g. '0000000001-0000000000000264100' that is hidden in the code.

I can get this value in the code from the server file (see sublayerrefsublayerref below). My problem is I cannot find a way to set this programmatically. Does anybody know how to do this  ? Here

Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted''editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId''ForeignKeyFieldId' field.Any Any help is much appreciated.

    {
    def feedback2():
    print("XXXFEEDBACK2 ACTIVATED:" + sublayerref)
    df = QgsDefaultValue('var("varsublayerref")', True)
    for field in vlayer.fields():
        print("LayerField:" + field.name())
        if field.name() == "ForeignKeyFieldId":
            field.setDefaultValueDefinition(df)
            print("Job done")
crs = QgsCoordinateReferenceSystem("EPSG:27700")
uri = QgsDataSourceUri()
uri.setConnection(servername, portnumber, databasename, logon, password)
uri.setDataSource( schemaname, tablename, geometryfieldname,  sublayerid + " = '" + sublayerref + "'" ) 
uri.setSrid("EPSG: 27700")
uri.setUseEstimatedMetadata(True)
uri.setWkbType(QgsWkbTypes.Polygon)
primaryKeyColumn = "RecordId"
uri.setKeyColumn(primaryKeyColumn)

symbol = QgsFillSymbol.createSimple({'line_style': 'dash', 'color': layercolour })
symbol.setOpacity(0.5)
vlayer = QgsVectorLayer()
vlayer.setCrs(crs)
vlayer.setCustomProperty("labeling", "pal")
vlayer.setCustomProperty("labeling/enabled", "true")
vlayer.setCustomProperty("labeling/isExpression", True)
vlayer.setCustomProperty("labeling/fontFamily", "Arial")
vlayer.setCustomProperty("labeling/fontSize", "10")
vlayer.setCustomProperty("labeling/fontWeight", "2")
vlayer.setCustomProperty("labeling/fontBold", True)
vlayer.setCustomProperty("labeling/placement", "1")
vlayer.setCustomProperty("labeling/fieldName", "'" + labelprefix + " ' || " + '"' + pkfieldname + '"')
vlayer.setOpacity(0.5)
vlayer.updateExtents()
vlayer = iface.addVectorLayer(uri.uri(), layername, 'mssql')
vlayer.renderer().setSymbol(symbol)
vlayer = iface.activeLayer()
vlayer.editingStarted.connect(feedback2) ##testcode
}

crs = QgsCoordinateReferenceSystem("EPSG:27700") uri = QgsDataSourceUri() uri.setConnection(servername, portnumber, databasename, logon, password) uri.setDataSource( schemaname, tablename, geometryfieldname, sublayerid + " = '" + sublayerref + "'" ) uri.setSrid("EPSG: 27700") uri.setUseEstimatedMetadata(True) uri.setWkbType(QgsWkbTypes.Polygon) primaryKeyColumn = "RecordId" uri.setKeyColumn(primaryKeyColumn)

symbol = QgsFillSymbol.createSimple({'line_style': 'dash', 'color': layercolour }) symbol.setOpacity(0.5) vlayer = QgsVectorLayer() vlayer.setCrs(crs) vlayer.setCustomProperty("labeling", "pal") vlayer.setCustomProperty("labeling/enabled", "true") vlayer.setCustomProperty("labeling/isExpression", True) vlayer.setCustomProperty("labeling/fontFamily", "Arial") vlayer.setCustomProperty("labeling/fontSize", "10") vlayer.setCustomProperty("labeling/fontWeight", "2") vlayer.setCustomProperty("labeling/fontBold", True) vlayer.setCustomProperty("labeling/placement", "1") vlayer.setCustomProperty("labeling/fieldName", "'" + labelprefix + " ' || " + '"' + pkfieldname + '"') vlayer.setOpacity(0.5) vlayer.updateExtents() vlayer = iface.addVectorLayer(uri.uri(), layername, 'mssql') vlayer.renderer().setSymbol(symbol) vlayer = iface.activeLayer() vlayer.editingStarted.connect(feedback2) ##testcode }

The way it works is, there is a separate application written in asp.net. On one of the web pages there is a button called 'Digitize'. When the user clicks this it saves a file with the details of the current record, onto the web server.

The user then opens QGIS via a shortcut on their desktop. The QGIS app is locked down with only minimal functionality.

When the project has finished loading, a plugin button becomes available on the toolbar. This button creates a new Vector Layer by connecting to a mssql database. The vector layer name is based on dynamic values in the file on the server, so changes each time. The layer is also removed every time QGIS is started. It displays the features/polygons that have already been added (if there are any).

The user clicks the pencil to begin editing. The user draws a polygon. The user clicks save.

The user is always prompted to enter an id which the record needs as a foreign key in the database. However, the user will never have access to this ID which is a long string e.g. '0000000001-0000000000000264100' that is hidden in the code.

I can get this value in the code from the server file (see sublayerref below). My problem is I cannot find a way to set this programmatically. Does anybody know how to do this  ? Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId' field.Any help is much appreciated.

{
def feedback2():
print("XXXFEEDBACK2 ACTIVATED:" + sublayerref)
df = QgsDefaultValue('var("varsublayerref")', True)
for field in vlayer.fields():
    print("LayerField:" + field.name())
    if field.name() == "ForeignKeyFieldId":
        field.setDefaultValueDefinition(df)
        print("Job done")

crs = QgsCoordinateReferenceSystem("EPSG:27700") uri = QgsDataSourceUri() uri.setConnection(servername, portnumber, databasename, logon, password) uri.setDataSource( schemaname, tablename, geometryfieldname, sublayerid + " = '" + sublayerref + "'" ) uri.setSrid("EPSG: 27700") uri.setUseEstimatedMetadata(True) uri.setWkbType(QgsWkbTypes.Polygon) primaryKeyColumn = "RecordId" uri.setKeyColumn(primaryKeyColumn)

symbol = QgsFillSymbol.createSimple({'line_style': 'dash', 'color': layercolour }) symbol.setOpacity(0.5) vlayer = QgsVectorLayer() vlayer.setCrs(crs) vlayer.setCustomProperty("labeling", "pal") vlayer.setCustomProperty("labeling/enabled", "true") vlayer.setCustomProperty("labeling/isExpression", True) vlayer.setCustomProperty("labeling/fontFamily", "Arial") vlayer.setCustomProperty("labeling/fontSize", "10") vlayer.setCustomProperty("labeling/fontWeight", "2") vlayer.setCustomProperty("labeling/fontBold", True) vlayer.setCustomProperty("labeling/placement", "1") vlayer.setCustomProperty("labeling/fieldName", "'" + labelprefix + " ' || " + '"' + pkfieldname + '"') vlayer.setOpacity(0.5) vlayer.updateExtents() vlayer = iface.addVectorLayer(uri.uri(), layername, 'mssql') vlayer.renderer().setSymbol(symbol) vlayer = iface.activeLayer() vlayer.editingStarted.connect(feedback2) ##testcode }

The way it works is, there is a separate application written in asp.net. On one of the web pages there is a button called 'Digitize'.

  • When the user clicks this it saves a file with the details of the current record, onto the web server.

  • The user then opens QGIS via a shortcut on their desktop. The QGIS app is locked down with only minimal functionality.

  • When the project has finished loading, a plugin button becomes available on the toolbar. This button creates a new Vector Layer by connecting to a mssql database.

  • The vector layer name is based on dynamic values in the file on the server, so it changes each time.

  • The layer is also removed every time QGIS is started.

  • It displays the features/polygons that have already been added (if there are any).

  • The user clicks the pencil to begin editing.

  • The user draws a polygon.

  • The user clicks save.

  • The user is always prompted to enter an id which the record needs as a foreign key in the database. However, the user will never have access to this ID which is a long string e.g. '0000000001-0000000000000264100' that is hidden in the code.

I can get this value in the code from the server file (see sublayerref below). My problem is I cannot find a way to set this programmatically. Does anybody know how to do this?

Here is the code so far, the best I can come up with at the moment is using the signal 'editingStarted', but I haven't found any success setting the value of 'ForeignKeyFieldId' field. Any help is much appreciated.

    {
    def feedback2():
    print("XXXFEEDBACK2 ACTIVATED:" + sublayerref)
    df = QgsDefaultValue('var("varsublayerref")', True)
    for field in vlayer.fields():
        print("LayerField:" + field.name())
        if field.name() == "ForeignKeyFieldId":
            field.setDefaultValueDefinition(df)
            print("Job done")
crs = QgsCoordinateReferenceSystem("EPSG:27700")
uri = QgsDataSourceUri()
uri.setConnection(servername, portnumber, databasename, logon, password)
uri.setDataSource( schemaname, tablename, geometryfieldname,  sublayerid + " = '" + sublayerref + "'" ) 
uri.setSrid("EPSG: 27700")
uri.setUseEstimatedMetadata(True)
uri.setWkbType(QgsWkbTypes.Polygon)
primaryKeyColumn = "RecordId"
uri.setKeyColumn(primaryKeyColumn)

symbol = QgsFillSymbol.createSimple({'line_style': 'dash', 'color': layercolour })
symbol.setOpacity(0.5)
vlayer = QgsVectorLayer()
vlayer.setCrs(crs)
vlayer.setCustomProperty("labeling", "pal")
vlayer.setCustomProperty("labeling/enabled", "true")
vlayer.setCustomProperty("labeling/isExpression", True)
vlayer.setCustomProperty("labeling/fontFamily", "Arial")
vlayer.setCustomProperty("labeling/fontSize", "10")
vlayer.setCustomProperty("labeling/fontWeight", "2")
vlayer.setCustomProperty("labeling/fontBold", True)
vlayer.setCustomProperty("labeling/placement", "1")
vlayer.setCustomProperty("labeling/fieldName", "'" + labelprefix + " ' || " + '"' + pkfieldname + '"')
vlayer.setOpacity(0.5)
vlayer.updateExtents()
vlayer = iface.addVectorLayer(uri.uri(), layername, 'mssql')
vlayer.renderer().setSymbol(symbol)
vlayer = iface.activeLayer()
vlayer.editingStarted.connect(feedback2) ##testcode
}
Source Link
Kai_B
  • 31
  • 4
Loading