2

Is there a way to automatically georeference fromPoint features upon creation?

I use this layer URI:

      self.pinLayer =  QgsVectorLayer(
          "Point?crs=epsg:3857&field=id:integer&field=description:string(120)&field=x:double&field=y:double&field=pluscode:string(20)&index=yes",
          "Pins",
          "memory")

I then set the pins using the QgsGeometry.fromPoint method:

        feature = QgsFeature()
        feature.setGeometry(QgsGeometry.fromPoint(point))

Which works fine as you can see:

enter image description here

But the points are not georeferenced. Is there a way to add / do that right during creation?

I've found this old entry but its for raster layers and it also requires some user interaction (setting ground control points) I want to do it programmatically

  • Hello cmon_sig, Are you setting point = QgsPoint(x, y, z) or point = QgsPointXY(x,y) where x and y are from your feature['x'] and feature['y'] fields? – Cary H Feb 25 at 22:10
  • Hi @CaryH not sure I understand your question, but if you are referring to a z dimension coordinate: I'm not using or setting a z coordinate – cmon_sig Feb 26 at 22:30
  • OK cmon_sig. How are you setting the geometry for <point> in your program? You are using it here - feature.setGeometry(QgsGeometry.fromPoint(point)). Somewhere in your program you need to either get the geometry from an existing Qgspoint or you need to set it with - point = QgsPointXY(1024477.6376,5996078.71604) – Cary H Feb 27 at 19:38
  • 1
    hi Cary H I'm setting it like this: ###### self.pinTool = QgsMapToolEmitPoint(self.canvas) ###### QObject.connect(self.pinTool, SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"), self.place_pin) ###### def place_pin(self, point, button): (desc,ok) = QInputDialog.getText( # (desc) = QInputDialog.getText( self.iface.mainWindow(), "Description", "Description for pin at %.2f, %.2f" % (float(str(point.x())),float(str(point.y()))), – cmon_sig Feb 28 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.