Create mid point from line layer The Next CEO of Stack OverflowIs QgsMapLayerRegistry removed in QGIS3?Finding middle point (midpoint) of line in QGIS?Copying point features along line features by predetermined distancepoint created on a line not precisely on lineParts of the lines aren't split when using Split Line At PointQGIS plugin that adds a point along a line at a specified distance?Length of line on specific point (from point layer)Adding M values to point feature attribute table in ArcmapConvert Line to central point in QGIS?Plot points along a line at specific distance value?QGIS points or line vertexCreate multiple paths by joining a set of start points in one layer to a single end destination in another layer?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

Is there a reasonable and studied concept of reduction between regular languages?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Aggressive Under-Indexing and no data for missing index

What does "shotgun unity" refer to here in this sentence?

IC has pull-down resistors on SMBus lines?

How to Implement Deterministic Encryption Safely in .NET

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

What flight has the highest ratio of timezone difference to flight time?

Physiological effects of huge anime eyes

Help/tips for a first time writer?

Purpose of level-shifter with same in and out voltages

What connection does MS Office have to Netscape Navigator?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

How to find image of a complex function with given constraints?

From jafe to El-Guest

It is correct to match light sources with the same color temperature?

Is there an equivalent of cd - for cp or mv

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Spaces in which all closed sets are regular closed

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?



Create mid point from line layer



The Next CEO of Stack OverflowIs QgsMapLayerRegistry removed in QGIS3?Finding middle point (midpoint) of line in QGIS?Copying point features along line features by predetermined distancepoint created on a line not precisely on lineParts of the lines aren't split when using Split Line At PointQGIS plugin that adds a point along a line at a specified distance?Length of line on specific point (from point layer)Adding M values to point feature attribute table in ArcmapConvert Line to central point in QGIS?Plot points along a line at specific distance value?QGIS points or line vertexCreate multiple paths by joining a set of start points in one layer to a single end destination in another layer?










5















In QGIS I am trying to create a new point layer based on the mid point of a line layer (and keep all the feature attributes in the table).



For example, one line feature becomes one point, located on the mid/center point of the line. Points to lines only seems to work on nodes, and Create points along lines only seems to work at fixed distances?










share|improve this question




























    5















    In QGIS I am trying to create a new point layer based on the mid point of a line layer (and keep all the feature attributes in the table).



    For example, one line feature becomes one point, located on the mid/center point of the line. Points to lines only seems to work on nodes, and Create points along lines only seems to work at fixed distances?










    share|improve this question


























      5












      5








      5








      In QGIS I am trying to create a new point layer based on the mid point of a line layer (and keep all the feature attributes in the table).



      For example, one line feature becomes one point, located on the mid/center point of the line. Points to lines only seems to work on nodes, and Create points along lines only seems to work at fixed distances?










      share|improve this question
















      In QGIS I am trying to create a new point layer based on the mid point of a line layer (and keep all the feature attributes in the table).



      For example, one line feature becomes one point, located on the mid/center point of the line. Points to lines only seems to work on nodes, and Create points along lines only seems to work at fixed distances?







      qgis point line distance points-to-line






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      Kadir Şahbaz

      4,52721331




      4,52721331










      asked Oct 12 '17 at 14:48









      user107128user107128

      264




      264




















          4 Answers
          4






          active

          oldest

          votes


















          5














          If python is Ok for you, you can easily do that with that code snippet.
          Copy/paste this code in the editor of the python console, select your line layer and run the script!



          layer = iface.activeLayer()

          temp = QgsVectorLayer("Point?crs=epsg:2154", "result", "memory")
          temp.startEditing()

          attrs = layer.dataProvider().fields().toList()
          temp_prov = temp.dataProvider()
          temp_prov.addAttributes(attrs)
          temp.updateFields()

          for elem in layer.getFeatures():
          feat = QgsFeature()
          geom = elem.geometry().interpolate(elem.geometry().length()/2)
          feat.setGeometry(geom)
          feat.setAttributes(elem.attributes())
          temp.addFeatures([feat])
          temp.updateExtents()

          temp.commitChanges()
          QgsMapLayerRegistry.instance().addMapLayer(temp)


          This code also take care about keeping the attributes of the line Layer.
          Here is my result on a set of line :



          enter image description here






          share|improve this answer























          • Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

            – TeddyTedTed
            Jan 3 at 12:03












          • @TeddyTedTed You are right, thanks for pointing this!

            – YoLecomte
            Jan 3 at 22:03


















          5














          You can use the GDAL/OGR tool: Create points along lines.



          Make sure you specify 0.5 as the distance. This calculates the fraction of the total length (not the distance) as the tool incorporates the ST_Line_Interpolate_Point function.




          Here is the default settings shown for me using QGIS 2.18.2 for Win7 64-bit:



          Default settings



          The attributes are also carried over to the output point layer.






          share|improve this answer






























            1














            I would suggest you use MMQGIS plugin that will allow you to find the mid point of the layer.



            This provide a great resource to learn more about the plugin and the features. You would need to add the plugin via the repository in QGIS Describes use of MMQGIS, a set of Python vector map layer plugins for Quantum GIS






            share|improve this answer






























              0














              I use a two steps solution:



              -First I make count densification with a count equals to one, this adds a mid point to every segment.
              -Then I extract specific nodes, indicating node number 1.



              I use this solution because I keep not only the mid point, also the angle of the segment comes as an attribute.
              I have a model with the two steps inside, I only have to insert the lines layer






              share|improve this answer








              New contributor




              Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                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%2f258308%2fcreate-mid-point-from-line-layer%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                5














                If python is Ok for you, you can easily do that with that code snippet.
                Copy/paste this code in the editor of the python console, select your line layer and run the script!



                layer = iface.activeLayer()

                temp = QgsVectorLayer("Point?crs=epsg:2154", "result", "memory")
                temp.startEditing()

                attrs = layer.dataProvider().fields().toList()
                temp_prov = temp.dataProvider()
                temp_prov.addAttributes(attrs)
                temp.updateFields()

                for elem in layer.getFeatures():
                feat = QgsFeature()
                geom = elem.geometry().interpolate(elem.geometry().length()/2)
                feat.setGeometry(geom)
                feat.setAttributes(elem.attributes())
                temp.addFeatures([feat])
                temp.updateExtents()

                temp.commitChanges()
                QgsMapLayerRegistry.instance().addMapLayer(temp)


                This code also take care about keeping the attributes of the line Layer.
                Here is my result on a set of line :



                enter image description here






                share|improve this answer























                • Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                  – TeddyTedTed
                  Jan 3 at 12:03












                • @TeddyTedTed You are right, thanks for pointing this!

                  – YoLecomte
                  Jan 3 at 22:03















                5














                If python is Ok for you, you can easily do that with that code snippet.
                Copy/paste this code in the editor of the python console, select your line layer and run the script!



                layer = iface.activeLayer()

                temp = QgsVectorLayer("Point?crs=epsg:2154", "result", "memory")
                temp.startEditing()

                attrs = layer.dataProvider().fields().toList()
                temp_prov = temp.dataProvider()
                temp_prov.addAttributes(attrs)
                temp.updateFields()

                for elem in layer.getFeatures():
                feat = QgsFeature()
                geom = elem.geometry().interpolate(elem.geometry().length()/2)
                feat.setGeometry(geom)
                feat.setAttributes(elem.attributes())
                temp.addFeatures([feat])
                temp.updateExtents()

                temp.commitChanges()
                QgsMapLayerRegistry.instance().addMapLayer(temp)


                This code also take care about keeping the attributes of the line Layer.
                Here is my result on a set of line :



                enter image description here






                share|improve this answer























                • Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                  – TeddyTedTed
                  Jan 3 at 12:03












                • @TeddyTedTed You are right, thanks for pointing this!

                  – YoLecomte
                  Jan 3 at 22:03













                5












                5








                5







                If python is Ok for you, you can easily do that with that code snippet.
                Copy/paste this code in the editor of the python console, select your line layer and run the script!



                layer = iface.activeLayer()

                temp = QgsVectorLayer("Point?crs=epsg:2154", "result", "memory")
                temp.startEditing()

                attrs = layer.dataProvider().fields().toList()
                temp_prov = temp.dataProvider()
                temp_prov.addAttributes(attrs)
                temp.updateFields()

                for elem in layer.getFeatures():
                feat = QgsFeature()
                geom = elem.geometry().interpolate(elem.geometry().length()/2)
                feat.setGeometry(geom)
                feat.setAttributes(elem.attributes())
                temp.addFeatures([feat])
                temp.updateExtents()

                temp.commitChanges()
                QgsMapLayerRegistry.instance().addMapLayer(temp)


                This code also take care about keeping the attributes of the line Layer.
                Here is my result on a set of line :



                enter image description here






                share|improve this answer













                If python is Ok for you, you can easily do that with that code snippet.
                Copy/paste this code in the editor of the python console, select your line layer and run the script!



                layer = iface.activeLayer()

                temp = QgsVectorLayer("Point?crs=epsg:2154", "result", "memory")
                temp.startEditing()

                attrs = layer.dataProvider().fields().toList()
                temp_prov = temp.dataProvider()
                temp_prov.addAttributes(attrs)
                temp.updateFields()

                for elem in layer.getFeatures():
                feat = QgsFeature()
                geom = elem.geometry().interpolate(elem.geometry().length()/2)
                feat.setGeometry(geom)
                feat.setAttributes(elem.attributes())
                temp.addFeatures([feat])
                temp.updateExtents()

                temp.commitChanges()
                QgsMapLayerRegistry.instance().addMapLayer(temp)


                This code also take care about keeping the attributes of the line Layer.
                Here is my result on a set of line :



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 12 '17 at 15:10









                YoLecomteYoLecomte

                2,085218




                2,085218












                • Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                  – TeddyTedTed
                  Jan 3 at 12:03












                • @TeddyTedTed You are right, thanks for pointing this!

                  – YoLecomte
                  Jan 3 at 22:03

















                • Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                  – TeddyTedTed
                  Jan 3 at 12:03












                • @TeddyTedTed You are right, thanks for pointing this!

                  – YoLecomte
                  Jan 3 at 22:03
















                Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                – TeddyTedTed
                Jan 3 at 12:03






                Thanks for this. Just to note that the last line doesn't work in QGIS 3, the following works instead: QgsProject.instance().addMapLayer(temp) Credit to Abhijit Gujar.

                – TeddyTedTed
                Jan 3 at 12:03














                @TeddyTedTed You are right, thanks for pointing this!

                – YoLecomte
                Jan 3 at 22:03





                @TeddyTedTed You are right, thanks for pointing this!

                – YoLecomte
                Jan 3 at 22:03













                5














                You can use the GDAL/OGR tool: Create points along lines.



                Make sure you specify 0.5 as the distance. This calculates the fraction of the total length (not the distance) as the tool incorporates the ST_Line_Interpolate_Point function.




                Here is the default settings shown for me using QGIS 2.18.2 for Win7 64-bit:



                Default settings



                The attributes are also carried over to the output point layer.






                share|improve this answer



























                  5














                  You can use the GDAL/OGR tool: Create points along lines.



                  Make sure you specify 0.5 as the distance. This calculates the fraction of the total length (not the distance) as the tool incorporates the ST_Line_Interpolate_Point function.




                  Here is the default settings shown for me using QGIS 2.18.2 for Win7 64-bit:



                  Default settings



                  The attributes are also carried over to the output point layer.






                  share|improve this answer

























                    5












                    5








                    5







                    You can use the GDAL/OGR tool: Create points along lines.



                    Make sure you specify 0.5 as the distance. This calculates the fraction of the total length (not the distance) as the tool incorporates the ST_Line_Interpolate_Point function.




                    Here is the default settings shown for me using QGIS 2.18.2 for Win7 64-bit:



                    Default settings



                    The attributes are also carried over to the output point layer.






                    share|improve this answer













                    You can use the GDAL/OGR tool: Create points along lines.



                    Make sure you specify 0.5 as the distance. This calculates the fraction of the total length (not the distance) as the tool incorporates the ST_Line_Interpolate_Point function.




                    Here is the default settings shown for me using QGIS 2.18.2 for Win7 64-bit:



                    Default settings



                    The attributes are also carried over to the output point layer.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 12 '17 at 15:12









                    JosephJoseph

                    58.5k7100205




                    58.5k7100205





















                        1














                        I would suggest you use MMQGIS plugin that will allow you to find the mid point of the layer.



                        This provide a great resource to learn more about the plugin and the features. You would need to add the plugin via the repository in QGIS Describes use of MMQGIS, a set of Python vector map layer plugins for Quantum GIS






                        share|improve this answer



























                          1














                          I would suggest you use MMQGIS plugin that will allow you to find the mid point of the layer.



                          This provide a great resource to learn more about the plugin and the features. You would need to add the plugin via the repository in QGIS Describes use of MMQGIS, a set of Python vector map layer plugins for Quantum GIS






                          share|improve this answer

























                            1












                            1








                            1







                            I would suggest you use MMQGIS plugin that will allow you to find the mid point of the layer.



                            This provide a great resource to learn more about the plugin and the features. You would need to add the plugin via the repository in QGIS Describes use of MMQGIS, a set of Python vector map layer plugins for Quantum GIS






                            share|improve this answer













                            I would suggest you use MMQGIS plugin that will allow you to find the mid point of the layer.



                            This provide a great resource to learn more about the plugin and the features. You would need to add the plugin via the repository in QGIS Describes use of MMQGIS, a set of Python vector map layer plugins for Quantum GIS







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Oct 12 '17 at 15:02









                            whyzarwhyzar

                            10.7k92866




                            10.7k92866





















                                0














                                I use a two steps solution:



                                -First I make count densification with a count equals to one, this adds a mid point to every segment.
                                -Then I extract specific nodes, indicating node number 1.



                                I use this solution because I keep not only the mid point, also the angle of the segment comes as an attribute.
                                I have a model with the two steps inside, I only have to insert the lines layer






                                share|improve this answer








                                New contributor




                                Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.
























                                  0














                                  I use a two steps solution:



                                  -First I make count densification with a count equals to one, this adds a mid point to every segment.
                                  -Then I extract specific nodes, indicating node number 1.



                                  I use this solution because I keep not only the mid point, also the angle of the segment comes as an attribute.
                                  I have a model with the two steps inside, I only have to insert the lines layer






                                  share|improve this answer








                                  New contributor




                                  Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.






















                                    0












                                    0








                                    0







                                    I use a two steps solution:



                                    -First I make count densification with a count equals to one, this adds a mid point to every segment.
                                    -Then I extract specific nodes, indicating node number 1.



                                    I use this solution because I keep not only the mid point, also the angle of the segment comes as an attribute.
                                    I have a model with the two steps inside, I only have to insert the lines layer






                                    share|improve this answer








                                    New contributor




                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.










                                    I use a two steps solution:



                                    -First I make count densification with a count equals to one, this adds a mid point to every segment.
                                    -Then I extract specific nodes, indicating node number 1.



                                    I use this solution because I keep not only the mid point, also the angle of the segment comes as an attribute.
                                    I have a model with the two steps inside, I only have to insert the lines layer







                                    share|improve this answer








                                    New contributor




                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    share|improve this answer



                                    share|improve this answer






                                    New contributor




                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered 2 days ago









                                    Juan Francisco Garrido RiteJuan Francisco Garrido Rite

                                    1




                                    1




                                    New contributor




                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    Juan Francisco Garrido Rite is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.



























                                        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%2f258308%2fcreate-mid-point-from-line-layer%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

                                        រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

                                        QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

                                        PDF-ში გადმოწერა სანავიგაციო მენიუproject page