9

I have a set of points which I would like to change into a polygon.

enter image description here

enter image description here

I tried concave hull but do not get the intended polygon as you can see below,

enter image description here

And when I use Denaulay Triangulation I need to delete the outer triangles.

enter image description here

Is there an efficient way of doing the same?

I also tried Convex hull.

enter image description here

  • 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
  • 3
    do you have the lines shown on your first image or only the points ? – radouxju Nov 15 '17 at 8:31
  • 1
    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
  • 2
    @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
5

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)

enter image description here

open attribute table > invert the selection of the points (ctrl + R)

vector > research tool > select by location (remove from selection, disjoint)

enter image description here

vector > geoprocessing tool > dissolve

enter image description here

3

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]
    enter image description here
    enter image description here

  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]
    enter image description here
    enter image description here

  8. Merge the features by selection [geoprocessing tool > dissolve]
    enter image description here
    enter image description here


IMPORTANT : You MUST have the polylines to obtain this result !

  • Thanks @Keiko your answer was useful to interpret radouxju's answer – Stephen Jacob Nov 17 '17 at 5:04
  • You're welcome @StephenJacob ! It just was teamwork ! ;-) – Keiko Nov 17 '17 at 7:04
1

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')

you can read the line geometries using geopandas gpd.read_file() function.

Order of polygon vertices in general GIS: clockwise or counterclockwise

https://nbviewer.jupyter.org/gist/rutgerhofste/b01c17aa6851ea577f10c21a4c3717bc

  • How to convert this into a shape file? – Stephen Jacob Nov 17 '17 at 5:05
  • 1
    You can use multiple tools but I am a fan of geopandas. Use gdf.to_file('MyGeometries.shp', driver='ESRI Shapefile') – RutgerH Nov 17 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.