# Drawing boundary of set of points using QGIS?

I have a set of points which I would like to change into a polygon.  I tried concave hull but do not get the intended polygon as you can see below, And when I use Denaulay Triangulation I need to delete the outer triangles. Is there an efficient way of doing the same?

I also tried Convex hull. • Do you try Vector -> Geoprocessing tools -> Convex hull(s)... or Geoprocessing toolbox -> Vector geometry tools -> Convex hull ? – Dmitry Baryshnikov Nov 15 '17 at 7:56
• Yes, I did try that. However, I thought this doesn't apply to the shape I require. I will update the question. – Stephen Jacob Nov 15 '17 at 8:21
• do you have the lines shown on your first image or only the points ? – radouxju Nov 15 '17 at 8:31
• I have a question : what is your goal ? what does the data represent ? river ? road ? I'm afraid that if you have "S" shapes or twisted shapes, it will not work, even with python ... – Keiko Nov 15 '17 at 10:28
• @StephenJacob - How are your points ordered? If they have an order going clockwise or anti-clockwise then it's possible to first convert your points to lines (e.g. using SAGA's Convert points to line(s) tool) and then convert the lines to a poygon (e.g. Lines to polygons tool). – Joseph Nov 15 '17 at 10:37

I assume that you know which points belong to the "left" or "right", because otherwise there are many solutions. If so, you could use the delaunay triangulation followed with a selection of the "central" triangles. With this method, no need to have the points in a specific order. All you need to consider is the fact that the triangles you need must touch at least one point from each side.

open attribute table > select by expression > "code" = 1

vector > research tool > select by location (new selection, intersect) open attribute table > invert the selection of the points (ctrl + R)

vector > research tool > select by location (remove from selection, disjoint) vector > geoprocessing tool > dissolve I have the same result as @radouxju.

Operations :

1. Select 1 polyline [select on click]
2. Update your polyline table and affect a number to each feature [field calculator]
3. Select the points which intersects one polyline [spatial query tool]
4. Update the selected points by the polyline value previously affected [field calculator]
5. Keep the selection point and select the delaunay triangles which intersects these selected points [spatial query tool]  6. Invert the point selection or select the points which intersect the other polyline [selection by expression] or [invert selection]

7. Remove from the current selection the delaunay triangles which are disjoint with the other points [spatial query tool]  8. Merge the features by selection [geoprocessing tool > dissolve]  IMPORTANT : You MUST have the polylines to obtain this result !

• You're welcome @StephenJacob ! It just was teamwork ! ;-) – Keiko Nov 17 '17 at 7:04

If you have experience with python, you could use the Shapely library and create a Polygon from the points in the two lines. You will need to tell python what the start and end points of both lines are.

``````from shapely.geometry import Point, Polygon, LineString
import geopandas as gpd
import pandas as pd
line1 = [(1,1),(2,1.2),(3,1)]
line2 = [(1,2),(2,2.2),(3,2)]
# you need to reverse the order of one line to make it a polygon
line2reverse = list(reversed(line2))
polgonList2 = line1 + line2reverse
Polygon(polgonList2)
``````

Even better: you can also use geopandas to do this. geopandas allows you to easily save to multiple formats including shapefiles

``````d = {'identifier' : [1, 2],
'name' : ["Netherlands", "Germany"],
"line1": [[(1,1),(2,1.2),(3,1)], [(1,1),(2,1.2),(3,1)]],
"line2": [[(1.1,2.1),(2.1,2.3),(3.1,2.2)],[(1,2),(2,2.2),(3,2)]]
}

df = pd.DataFrame(d)
def makePolygon(row):
line2reverse = list(reversed(row["line2"]))
return Polygon(line1+line2reverse)
geometries = []

for index, row in df.iterrows():
geometries.append(makePolygon(row))
crs = {'init': 'epsg:4326'}
gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometries)
gdf.to_file('MyGeometries.shp', driver='ESRI Shapefile')
``````