There doesn't seem to be a simple way to do this with the GUI, because of the (paired) data structure your data have.
However, I found the use case interesting and had attempted a script before the other answer published (although, I didn't published it waiting for other answers using the GUI).
This is the result with an azimuthal projection:
And this is the script I ended up with:
stars = QgsProject.instance().mapLayersByName("stars6")[0]
stars_dict = {str(feature["HIP"]):feature.geometry() for feature in stars.getFeatures()}
# Prepare constellation layer
layer = QgsVectorLayer("MultiLineString?crs={}".format(stars.crs().authid()), "constellations", "memory")
layer.dataProvider().addAttributes([QgsField("name", QVariant.String)])
layer.updateFields()
new_features = list()
constellations_file = open('/path/to/constellationship.fab', 'r')
for line in constellations_file:
constellation_name, hip_part = line.split(" ")
constellation_name = constellation_name.split(" ")[0]
hip_list = hip_part.strip().split(" ")
# Build constellation lines
mls = QgsMultiLineString()
for start, end in zip(hip_list[::2], hip_list[1::2]):
if not (start in stars_dict and end in stars_dict):
print("Pair {}-{} not found in stars layer! Skipping...".format(start, end))
continue
g = QgsGeometry.fromPolyline([stars_dict[start].get(), stars_dict[end].get()])
mls.addGeometry(g.get().clone())
new_feature = QgsFeature()
new_feature.setGeometry(mls)
new_feature.setAttributes([constellation_name])
new_features.append(new_feature)
constellations_file.close()
layer.dataProvider().addFeatures(new_features)
QgsProject.instance().addMapLayer(layer)
It creates a segment per each pair of stars; it doesn't create segments with length 0; and, the resulting layer has the corresponding constellation name.
Issues with the data
- In
constellationship.fab
, the line CMa 17...
doesn't have two spaces after number of points (CMa 17 33160 34045...
). I had to adjust it manually (find the modified file here).
- Star 33165 does not exist!
Usage
- Load the
stars6.shp
file into QGIS.
- Adjust the
/path/to/constellationship.fab
to reflect your local path. (Use the modified file mentioned above when talking about issues with the data.)
- Run the script from the QGIS Python console.