Add a new POINT or LINESTRING geometry field.
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
)
A connection object.
A character string specifying a PostgreSQL schema and
table name (e.g., name = c("schema","table")
)
A character string specifying the name of the new geometry column.
The name of the x/longitude field.
The name of the y/latitude field.
A valid SRID for the new geometry.
Logical. Whether to create an index on the new geometry.
Logical. Whether to display the query (defaults to
TRUE
).
Logical. Whether to execute the query (defaults to
TRUE
).
The name of the dx field (i.e. increment in x direction).
The name of the dy field (i.e. increment in y direction).
If exec = TRUE
, returns TRUE
if the geometry
field was successfully created.
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.
## 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;