Add a new POINT or LINESTRING geometry field.
Usage
pgMakePts(
conn,
name,
colname = "geom",
x = "x",
y = "y",
srid,
index = TRUE,
display = TRUE,
exec = TRUE
)
pgMakeStp(
conn,
name,
colname = "geom",
x = "x",
y = "y",
dx = "dx",
dy = "dy",
srid,
index = TRUE,
display = TRUE,
exec = TRUE
)
Arguments
- conn
A connection object.
- name
A character string specifying a PostgreSQL schema and table name (e.g.,
name = c("schema","table")
)- colname
A character string specifying the name of the new geometry column.
- x
The name of the x/longitude field.
- y
The name of the y/latitude field.
- srid
A valid SRID for the new geometry.
- index
Logical. Whether to create an index on the new geometry.
- display
Logical. Whether to display the query (defaults to
TRUE
).- exec
Logical. Whether to execute the query (defaults to
TRUE
).- dx
The name of the dx field (i.e. increment in x direction).
- dy
The name of the dy field (i.e. increment in y direction).
See also
The PostGIS documentation for ST_MakePoint
:
http://postgis.net/docs/ST_MakePoint.html, and for
ST_MakeLine
:
http://postgis.net/docs/ST_MakeLine.html, which are the
main functions of the call.
Author
Mathieu Basille mathieu@basille.org
Examples
## Examples use a dummy connection from DBI package
conn <- DBI::ANSI()
## Create a new POINT field called 'pts_geom'
pgMakePts(conn, name = c("schema", "table"), colname = "pts_geom",
x = "longitude", y = "latitude", srid = 4326, exec = FALSE)
#> Query not executed:
#> ALTER TABLE "schema"."table" ADD COLUMN "pts_geom" geometry(POINT, 4326);
#> Query not executed:
#> CREATE INDEX "table_pts_geom_idx" ON "schema"."table" USING GIST ("pts_geom");
#> --
#> Query not executed:
#> UPDATE "schema"."table"
#> SET "pts_geom" = ST_SetSRID(ST_MakePoint("longitude", "latitude"), 4326)
#> WHERE "longitude" IS NOT NULL AND "latitude" IS NOT NULL;
## Create a new LINESTRING field called 'stp_geom'
pgMakeStp(conn, name = c("schema", "table"), colname = "stp_geom",
x = "longitude", y = "latitude", dx = "xdiff", dy = "ydiff",
srid = 4326, exec = FALSE)
#> Query not executed:
#> ALTER TABLE "schema"."table" ADD COLUMN "stp_geom" geometry(LINESTRING, 4326);
#> Query not executed:
#> CREATE INDEX "table_stp_geom_idx" ON "schema"."table" USING GIST ("stp_geom");
#> --
#> Query not executed:
#> UPDATE "schema"."table"
#> SET "stp_geom" = ST_SetSRID(ST_MakeLine(
#> ARRAY[ST_MakePoint("longitude", "latitude"),
#> ST_MakePoint("longitude" + "xdiff", "latitude" + "ydiff")]
#> ), 4326)
#> WHERE "xdiff" IS NOT NULL AND "ydiff" IS NOT NULL;