Create mid point from line layer The Next CEO of Stack OverflowIs QgsMapLayerRegistry removed...
If the heap is initialized for security, then why is the stack uninitialized?
At which OSI layer a user-generated data resides?
Preparing Indesign booklet with .psd graphics for print
A "random" question: usage of "random" as adjective in Spanish
Do I need to enable Dev Hub in my PROD Org?
How do we know the LHC results are robust?
How to avoid supervisors with prejudiced views?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Make solar eclipses exceedingly rare, but still have new moons
Is it professional to write unrelated content in an almost-empty email?
What connection does MS Office have to Netscape Navigator?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Unreliable Magic - Is it worth it?
Is it ever safe to open a suspicious html file (e.g. email attachment)?
Why am I allowed to create multiple unique pointers from a single object?
In excess I'm lethal
How to make a variable always equal to the result of some calculations?
Novel about a guy who is possessed by the divine essence and the world ends?
How to subset dataframe based on a "not equal to" criteria applied to a large number of columns?
Interfacing a button to MCU (and PC) with 50m long cable
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Between two walls
Written every which way
Create mid point from line layer
The Next CEO of Stack OverflowIs QgsMapLayerRegistry removed in QGIS3?Finding middle point (midpoint) of line in QGIS?How do I create an outline layer for multiple blocks of points?Copying point features along line features by predetermined distanceNode-line minimum distance: draw the minimum distance point locationpoint 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?Adding M values to point feature attribute table in ArcmapFinding line with minimum distance to point and update attribute of points?Finding which side of closest polyline point lies on in QGIS?Adding Points to line at certain distance using QGIS?
Apologies if this has been asked before and I’ve missed it with my searches. 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
add a comment |
Apologies if this has been asked before and I’ve missed it with my searches. 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
add a comment |
Apologies if this has been asked before and I’ve missed it with my searches. 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
Apologies if this has been asked before and I’ve missed it with my searches. 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
qgis point line distance points-to-line
edited Oct 19 '17 at 19:19
whyzar
10.7k92866
10.7k92866
asked Oct 12 '17 at 14:48
user107128user107128
264
264
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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 :

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
add a comment |
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:

The attributes are also carried over to the output point layer.
add a comment |
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
add a comment |
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
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 :

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
add a comment |
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 :

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
add a comment |
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 :

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 :

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
add a comment |
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
add a comment |
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:

The attributes are also carried over to the output point layer.
add a comment |
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:

The attributes are also carried over to the output point layer.
add a comment |
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:

The attributes are also carried over to the output point layer.
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:

The attributes are also carried over to the output point layer.
answered Oct 12 '17 at 15:12
JosephJoseph
58.5k7100205
58.5k7100205
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Oct 12 '17 at 15:02
whyzarwhyzar
10.7k92866
10.7k92866
add a comment |
add a comment |
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
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.
add a comment |
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
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.
add a comment |
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
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
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.
answered 7 mins 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.
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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