Skip to main content
added 152 characters in body
Source Link
BradHards
  • 12.9k
  • 2
  • 39
  • 72

You could, of course, do this with conversion via Well Known Text:

spatialite> SELECT AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"));
AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"))
LINESTRING(1 2, 3 4, 1 3)

However you canit is definitely possible to use MakeLine() with more than two points.

Apart from the obvious version that you know about already, there are two more optionsways to call the MakeLine() function. The first is to use a MultiPoint geometry (if you already had one, or can make one from what you have):

spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 0));
LINESTRING(1 3, 3 4, 1 2)
spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 1));
LINESTRING(1 2, 3 4, 1 3)

The last argument (0 in the first example, 1 in the second) turns on reversal of order. You usually want this set to 1 (not reorder).

The other option is to use the aggregate function form. Lets say you have a table of point geometrygeometries:

spatialite> CREATE TABLE somepoints (label);
spatialite> SELECT AddGeometryColumn('somepoints', 'geom', 0, 'POINT', 'XY');
1
spatialite> INSERT INTO somepoints VALUES('a', MakePoint(1,2));
spatialite> INSERT INTO somepoints VALUES('b', MakePoint(3,4));
spatialite> INSERT INTO somepoints VALUES('c', MakePoint(1,3));

Lets see what that looks like:

spatialite> .headers on
spatialite> SELECT label, AsText(geom) FROM somepoints;
label|AsText(geom)
a|POINT(1 2)
b|POINT(3 4)
c|POINT(1 3)

Now you can select points to turn into a linestring:

spatialite> SELECT AsText(MakeLine(geom)) FROM somepoints;
AsText(MakeLine(geom))
LINESTRING(1 2, 3 4, 1 3)

Note that the SELECT could have some condition (WHERE clause) so you can filter if that suits your needs.

You could do this with conversion via Well Known Text:

spatialite> SELECT AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"));
AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"))
LINESTRING(1 2, 3 4, 1 3)

However you can use MakeLine() with more than two points.

Apart from the obvious version that you know about already, there are two more options. The first is to use MultiPoint:

spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 0));
LINESTRING(1 3, 3 4, 1 2)
spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 1));
LINESTRING(1 2, 3 4, 1 3)

The last argument (0 in the first example, 1 in the second) turns on reversal of order. You usually want this set to 1.

The other option is to use the aggregate function form. Lets say you have a table of point geometry:

spatialite> CREATE TABLE somepoints (label);
spatialite> SELECT AddGeometryColumn('somepoints', 'geom', 0, 'POINT', 'XY');
1
spatialite> INSERT INTO somepoints VALUES('a', MakePoint(1,2));
spatialite> INSERT INTO somepoints VALUES('b', MakePoint(3,4));
spatialite> INSERT INTO somepoints VALUES('c', MakePoint(1,3));

Lets see what that looks like:

spatialite> .headers on
spatialite> SELECT label, AsText(geom) FROM somepoints;
label|AsText(geom)
a|POINT(1 2)
b|POINT(3 4)
c|POINT(1 3)

Now you can select points to turn into a linestring:

spatialite> SELECT AsText(MakeLine(geom)) FROM somepoints;
AsText(MakeLine(geom))
LINESTRING(1 2, 3 4, 1 3)

Note that the SELECT could have some condition (WHERE clause) so you can filter if that suits your needs.

You could, of course, do this with conversion via Well Known Text:

spatialite> SELECT AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"));
AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"))
LINESTRING(1 2, 3 4, 1 3)

However it is definitely possible to use MakeLine() with more than two points.

Apart from the obvious version that you know about already, there are two more ways to call the MakeLine() function. The first is to use a MultiPoint geometry (if you already had one, or can make one from what you have):

spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 0));
LINESTRING(1 3, 3 4, 1 2)
spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 1));
LINESTRING(1 2, 3 4, 1 3)

The last argument (0 in the first example, 1 in the second) turns on reversal of order. You usually want this set to 1 (not reorder).

The other option is to use the aggregate function form. Lets say you have a table of point geometries:

spatialite> CREATE TABLE somepoints (label);
spatialite> SELECT AddGeometryColumn('somepoints', 'geom', 0, 'POINT', 'XY');
1
spatialite> INSERT INTO somepoints VALUES('a', MakePoint(1,2));
spatialite> INSERT INTO somepoints VALUES('b', MakePoint(3,4));
spatialite> INSERT INTO somepoints VALUES('c', MakePoint(1,3));

Lets see what that looks like:

spatialite> .headers on
spatialite> SELECT label, AsText(geom) FROM somepoints;
label|AsText(geom)
a|POINT(1 2)
b|POINT(3 4)
c|POINT(1 3)

Now you can select points to turn into a linestring:

spatialite> SELECT AsText(MakeLine(geom)) FROM somepoints;
AsText(MakeLine(geom))
LINESTRING(1 2, 3 4, 1 3)

Note that the SELECT could have some condition (WHERE clause) so you can filter if that suits your needs.

Source Link
BradHards
  • 12.9k
  • 2
  • 39
  • 72

You could do this with conversion via Well Known Text:

spatialite> SELECT AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"));
AsText(GeomFromText("LINESTRING(1 2, 3 4, 1 3)"))
LINESTRING(1 2, 3 4, 1 3)

However you can use MakeLine() with more than two points.

Apart from the obvious version that you know about already, there are two more options. The first is to use MultiPoint:

spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 0));
LINESTRING(1 3, 3 4, 1 2)
spatialite> SELECT AsText(MakeLine(GeomFromText("MULTIPOINT(1 2,3 4,1 3)"), 1));
LINESTRING(1 2, 3 4, 1 3)

The last argument (0 in the first example, 1 in the second) turns on reversal of order. You usually want this set to 1.

The other option is to use the aggregate function form. Lets say you have a table of point geometry:

spatialite> CREATE TABLE somepoints (label);
spatialite> SELECT AddGeometryColumn('somepoints', 'geom', 0, 'POINT', 'XY');
1
spatialite> INSERT INTO somepoints VALUES('a', MakePoint(1,2));
spatialite> INSERT INTO somepoints VALUES('b', MakePoint(3,4));
spatialite> INSERT INTO somepoints VALUES('c', MakePoint(1,3));

Lets see what that looks like:

spatialite> .headers on
spatialite> SELECT label, AsText(geom) FROM somepoints;
label|AsText(geom)
a|POINT(1 2)
b|POINT(3 4)
c|POINT(1 3)

Now you can select points to turn into a linestring:

spatialite> SELECT AsText(MakeLine(geom)) FROM somepoints;
AsText(MakeLine(geom))
LINESTRING(1 2, 3 4, 1 3)

Note that the SELECT could have some condition (WHERE clause) so you can filter if that suits your needs.