Create line segments at point coordinates in QGIS

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7















I have a point vector layer with angle field. How can I create line segments at these points with certain length and angle?



I did this with style options but I need this physically as lines vector layer:
enter image description here










share|improve this question


























    7















    I have a point vector layer with angle field. How can I create line segments at these points with certain length and angle?



    I did this with style options but I need this physically as lines vector layer:
    enter image description here










    share|improve this question
























      7












      7








      7


      1






      I have a point vector layer with angle field. How can I create line segments at these points with certain length and angle?



      I did this with style options but I need this physically as lines vector layer:
      enter image description here










      share|improve this question














      I have a point vector layer with angle field. How can I create line segments at these points with certain length and angle?



      I did this with style options but I need this physically as lines vector layer:
      enter image description here







      qgis point vector






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 10 at 14:22









      KaRolthasKaRolthas

      654




      654




















          2 Answers
          2






          active

          oldest

          votes


















          12














          One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.



          enter image description here



          A Geometry expression to create lines (length= 100 m) is as below:



          make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))



          • project($geometry, 50, radians("angle")) part creates a new point by moving your points to "angle" direction by 50 meters.


          • project($geometry, 50, radians("angle"+180)) creates another point to the oposite direction.


          • make_line() ties the above two points, so the total line length is 100 meters.


          • project() function assumes that your "angle" is measured clockwise from north, so this expression may require edits depending on how your "angle" field is made.

          enter image description here



          NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.






          share|improve this answer























          • Thank You! Thats exactly what I needed.

            – KaRolthas
            Feb 10 at 15:58











          • @KaRolthas Thanks! I am glad it worked out.

            – Kazuhito
            Feb 11 at 11:35


















          6














          I put an example of solving the same task with a pyqgis (3.2) standalone application.
          Below the python code



          from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
          from PyQt5.QtWidgets import QApplication
          import sys
          import math

          def main():
          print('Start program')

          qgis_prefix_path = 'C:\OSGeo4W64\apps\qgis'
          app = QApplication(sys.argv)
          QgsApplication.setPrefixPath(qgis_prefix_path, True)

          QgsApplication.initQgis()

          point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
          line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
          point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
          layer = QgsVectorLayer(line_path, "linelayer", "ogr")


          for feature in point_layer.getFeatures():
          geom: QgsGeometry = feature.geometry()
          pnt: QgsPointXY = geom.asPoint()
          length = feature['distance']
          bearing = feature['bearing']
          id = feature['id']
          print('id=', id)
          pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
          pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
          points =
          points.append(pnt0)
          points.append(pnt1)
          fields = layer.dataProvider().fields()
          feature = QgsFeature()
          feature.setGeometry(QgsGeometry.fromPolylineXY(points))
          feature.setFields(fields)
          feature.setAttribute('id', id)
          layer.dataProvider().addFeature(feature)

          # layer.commitChanges()

          QgsApplication.exitQgis()

          def direct_geodetic_task(pnt, dist, bear):
          if bear > 360.0:
          bear = bear - 360
          if bear < 0:
          bear = 360 + bear

          deg = bear * math.pi / 180

          dx = dist * math.sin(deg)
          dy = dist * math.cos(deg)
          x = pnt.x() + dx
          y = pnt.y() + dy

          return QgsPointXY(x, y)

          if __name__ == '__main__':
          main()


          The result is the same
          enter image description here






          share|improve this answer






















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "79"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f311664%2fcreate-line-segments-at-point-coordinates-in-qgis%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            12














            One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.



            enter image description here



            A Geometry expression to create lines (length= 100 m) is as below:



            make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))



            • project($geometry, 50, radians("angle")) part creates a new point by moving your points to "angle" direction by 50 meters.


            • project($geometry, 50, radians("angle"+180)) creates another point to the oposite direction.


            • make_line() ties the above two points, so the total line length is 100 meters.


            • project() function assumes that your "angle" is measured clockwise from north, so this expression may require edits depending on how your "angle" field is made.

            enter image description here



            NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.






            share|improve this answer























            • Thank You! Thats exactly what I needed.

              – KaRolthas
              Feb 10 at 15:58











            • @KaRolthas Thanks! I am glad it worked out.

              – Kazuhito
              Feb 11 at 11:35















            12














            One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.



            enter image description here



            A Geometry expression to create lines (length= 100 m) is as below:



            make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))



            • project($geometry, 50, radians("angle")) part creates a new point by moving your points to "angle" direction by 50 meters.


            • project($geometry, 50, radians("angle"+180)) creates another point to the oposite direction.


            • make_line() ties the above two points, so the total line length is 100 meters.


            • project() function assumes that your "angle" is measured clockwise from north, so this expression may require edits depending on how your "angle" field is made.

            enter image description here



            NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.






            share|improve this answer























            • Thank You! Thats exactly what I needed.

              – KaRolthas
              Feb 10 at 15:58











            • @KaRolthas Thanks! I am glad it worked out.

              – Kazuhito
              Feb 11 at 11:35













            12












            12








            12







            One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.



            enter image description here



            A Geometry expression to create lines (length= 100 m) is as below:



            make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))



            • project($geometry, 50, radians("angle")) part creates a new point by moving your points to "angle" direction by 50 meters.


            • project($geometry, 50, radians("angle"+180)) creates another point to the oposite direction.


            • make_line() ties the above two points, so the total line length is 100 meters.


            • project() function assumes that your "angle" is measured clockwise from north, so this expression may require edits depending on how your "angle" field is made.

            enter image description here



            NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.






            share|improve this answer













            One possible tool is Geometry by expression in the Processing Toolbox > Vector geometry.



            enter image description here



            A Geometry expression to create lines (length= 100 m) is as below:



            make_line(project($geometry, 50, radians("angle")), project($geometry, 50, radians("angle"+180)))



            • project($geometry, 50, radians("angle")) part creates a new point by moving your points to "angle" direction by 50 meters.


            • project($geometry, 50, radians("angle"+180)) creates another point to the oposite direction.


            • make_line() ties the above two points, so the total line length is 100 meters.


            • project() function assumes that your "angle" is measured clockwise from north, so this expression may require edits depending on how your "angle" field is made.

            enter image description here



            NB. Do not forget saving created Modified geometry layer as a new dataset, otherwise it will be lost when you finish QGIS session.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 10 at 15:52









            KazuhitoKazuhito

            16k41882




            16k41882












            • Thank You! Thats exactly what I needed.

              – KaRolthas
              Feb 10 at 15:58











            • @KaRolthas Thanks! I am glad it worked out.

              – Kazuhito
              Feb 11 at 11:35

















            • Thank You! Thats exactly what I needed.

              – KaRolthas
              Feb 10 at 15:58











            • @KaRolthas Thanks! I am glad it worked out.

              – Kazuhito
              Feb 11 at 11:35
















            Thank You! Thats exactly what I needed.

            – KaRolthas
            Feb 10 at 15:58





            Thank You! Thats exactly what I needed.

            – KaRolthas
            Feb 10 at 15:58













            @KaRolthas Thanks! I am glad it worked out.

            – Kazuhito
            Feb 11 at 11:35





            @KaRolthas Thanks! I am glad it worked out.

            – Kazuhito
            Feb 11 at 11:35













            6














            I put an example of solving the same task with a pyqgis (3.2) standalone application.
            Below the python code



            from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
            from PyQt5.QtWidgets import QApplication
            import sys
            import math

            def main():
            print('Start program')

            qgis_prefix_path = 'C:\OSGeo4W64\apps\qgis'
            app = QApplication(sys.argv)
            QgsApplication.setPrefixPath(qgis_prefix_path, True)

            QgsApplication.initQgis()

            point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
            line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
            point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
            layer = QgsVectorLayer(line_path, "linelayer", "ogr")


            for feature in point_layer.getFeatures():
            geom: QgsGeometry = feature.geometry()
            pnt: QgsPointXY = geom.asPoint()
            length = feature['distance']
            bearing = feature['bearing']
            id = feature['id']
            print('id=', id)
            pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
            pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
            points =
            points.append(pnt0)
            points.append(pnt1)
            fields = layer.dataProvider().fields()
            feature = QgsFeature()
            feature.setGeometry(QgsGeometry.fromPolylineXY(points))
            feature.setFields(fields)
            feature.setAttribute('id', id)
            layer.dataProvider().addFeature(feature)

            # layer.commitChanges()

            QgsApplication.exitQgis()

            def direct_geodetic_task(pnt, dist, bear):
            if bear > 360.0:
            bear = bear - 360
            if bear < 0:
            bear = 360 + bear

            deg = bear * math.pi / 180

            dx = dist * math.sin(deg)
            dy = dist * math.cos(deg)
            x = pnt.x() + dx
            y = pnt.y() + dy

            return QgsPointXY(x, y)

            if __name__ == '__main__':
            main()


            The result is the same
            enter image description here






            share|improve this answer



























              6














              I put an example of solving the same task with a pyqgis (3.2) standalone application.
              Below the python code



              from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
              from PyQt5.QtWidgets import QApplication
              import sys
              import math

              def main():
              print('Start program')

              qgis_prefix_path = 'C:\OSGeo4W64\apps\qgis'
              app = QApplication(sys.argv)
              QgsApplication.setPrefixPath(qgis_prefix_path, True)

              QgsApplication.initQgis()

              point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
              line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
              point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
              layer = QgsVectorLayer(line_path, "linelayer", "ogr")


              for feature in point_layer.getFeatures():
              geom: QgsGeometry = feature.geometry()
              pnt: QgsPointXY = geom.asPoint()
              length = feature['distance']
              bearing = feature['bearing']
              id = feature['id']
              print('id=', id)
              pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
              pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
              points =
              points.append(pnt0)
              points.append(pnt1)
              fields = layer.dataProvider().fields()
              feature = QgsFeature()
              feature.setGeometry(QgsGeometry.fromPolylineXY(points))
              feature.setFields(fields)
              feature.setAttribute('id', id)
              layer.dataProvider().addFeature(feature)

              # layer.commitChanges()

              QgsApplication.exitQgis()

              def direct_geodetic_task(pnt, dist, bear):
              if bear > 360.0:
              bear = bear - 360
              if bear < 0:
              bear = 360 + bear

              deg = bear * math.pi / 180

              dx = dist * math.sin(deg)
              dy = dist * math.cos(deg)
              x = pnt.x() + dx
              y = pnt.y() + dy

              return QgsPointXY(x, y)

              if __name__ == '__main__':
              main()


              The result is the same
              enter image description here






              share|improve this answer

























                6












                6








                6







                I put an example of solving the same task with a pyqgis (3.2) standalone application.
                Below the python code



                from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
                from PyQt5.QtWidgets import QApplication
                import sys
                import math

                def main():
                print('Start program')

                qgis_prefix_path = 'C:\OSGeo4W64\apps\qgis'
                app = QApplication(sys.argv)
                QgsApplication.setPrefixPath(qgis_prefix_path, True)

                QgsApplication.initQgis()

                point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
                line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
                point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
                layer = QgsVectorLayer(line_path, "linelayer", "ogr")


                for feature in point_layer.getFeatures():
                geom: QgsGeometry = feature.geometry()
                pnt: QgsPointXY = geom.asPoint()
                length = feature['distance']
                bearing = feature['bearing']
                id = feature['id']
                print('id=', id)
                pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
                pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
                points =
                points.append(pnt0)
                points.append(pnt1)
                fields = layer.dataProvider().fields()
                feature = QgsFeature()
                feature.setGeometry(QgsGeometry.fromPolylineXY(points))
                feature.setFields(fields)
                feature.setAttribute('id', id)
                layer.dataProvider().addFeature(feature)

                # layer.commitChanges()

                QgsApplication.exitQgis()

                def direct_geodetic_task(pnt, dist, bear):
                if bear > 360.0:
                bear = bear - 360
                if bear < 0:
                bear = 360 + bear

                deg = bear * math.pi / 180

                dx = dist * math.sin(deg)
                dy = dist * math.cos(deg)
                x = pnt.x() + dx
                y = pnt.y() + dy

                return QgsPointXY(x, y)

                if __name__ == '__main__':
                main()


                The result is the same
                enter image description here






                share|improve this answer













                I put an example of solving the same task with a pyqgis (3.2) standalone application.
                Below the python code



                from qgis.core import QgsPointXY, QgsApplication, QgsVectorLayer, QgsFeature, QgsGeometry
                from PyQt5.QtWidgets import QApplication
                import sys
                import math

                def main():
                print('Start program')

                qgis_prefix_path = 'C:\OSGeo4W64\apps\qgis'
                app = QApplication(sys.argv)
                QgsApplication.setPrefixPath(qgis_prefix_path, True)

                QgsApplication.initQgis()

                point_path = 'd:/Users/Bogomolov/Qgis/Test_prj/point.shp'
                line_path = 'd:/Users/Bogomolov/Qgis/Test_prj/lines.shp'
                point_layer = QgsVectorLayer(point_path, "pointlayer", "ogr")
                layer = QgsVectorLayer(line_path, "linelayer", "ogr")


                for feature in point_layer.getFeatures():
                geom: QgsGeometry = feature.geometry()
                pnt: QgsPointXY = geom.asPoint()
                length = feature['distance']
                bearing = feature['bearing']
                id = feature['id']
                print('id=', id)
                pnt0 = direct_geodetic_task(pnt, length / 2, bearing + 180)
                pnt1 = direct_geodetic_task(pnt, length / 2, bearing)
                points =
                points.append(pnt0)
                points.append(pnt1)
                fields = layer.dataProvider().fields()
                feature = QgsFeature()
                feature.setGeometry(QgsGeometry.fromPolylineXY(points))
                feature.setFields(fields)
                feature.setAttribute('id', id)
                layer.dataProvider().addFeature(feature)

                # layer.commitChanges()

                QgsApplication.exitQgis()

                def direct_geodetic_task(pnt, dist, bear):
                if bear > 360.0:
                bear = bear - 360
                if bear < 0:
                bear = 360 + bear

                deg = bear * math.pi / 180

                dx = dist * math.sin(deg)
                dy = dist * math.cos(deg)
                x = pnt.x() + dx
                y = pnt.y() + dy

                return QgsPointXY(x, y)

                if __name__ == '__main__':
                main()


                The result is the same
                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 10 at 17:27









                VadymVadym

                61618




                61618



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f311664%2fcreate-line-segments-at-point-coordinates-in-qgis%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)