|
@@ -28,6 +28,7 @@ int main(int argc, char *argv[])
|
|
|
struct flags flags;
|
|
|
|
|
|
int ret, field;
|
|
|
+ char *schema, *olayer;
|
|
|
struct Map_info In, Out;
|
|
|
|
|
|
G_gisinit(argv[0]);
|
|
@@ -47,8 +48,30 @@ int main(int argc, char *argv[])
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
/* if olayer not given, use input as the name */
|
|
|
- if (!params.olayer->answer)
|
|
|
- params.olayer->answer = G_store(params.input->answer);
|
|
|
+ schema = NULL;
|
|
|
+ if (!params.olayer->answer) {
|
|
|
+ olayer = G_store(params.input->answer);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ /* check for schema */
|
|
|
+ char **tokens;
|
|
|
+
|
|
|
+ tokens = G_tokenize(params.olayer->answer, ".");
|
|
|
+ if (G_number_of_tokens(tokens) == 2) {
|
|
|
+ schema = G_store(tokens[0]);
|
|
|
+ olayer = G_store(tokens[1]);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ olayer = G_store(params.olayer->answer);
|
|
|
+ }
|
|
|
+
|
|
|
+ G_free_tokens(tokens);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* if schema not defined, use 'public' */
|
|
|
+ if (!schema)
|
|
|
+ schema = "public";
|
|
|
+ G_debug(1, "Database schema: %s", schema);
|
|
|
|
|
|
/* open input for reading */
|
|
|
ret = Vect_open_old2(&In, params.input->answer, "", params.layer->answer);
|
|
@@ -60,11 +83,11 @@ int main(int argc, char *argv[])
|
|
|
params.input->answer);
|
|
|
|
|
|
/* create output for writing */
|
|
|
- create_pgfile(params.dsn->answer, params.schema->answer, flags.topo->answer ? TRUE : FALSE);
|
|
|
+ create_pgfile(params.dsn->answer, schema, flags.topo->answer ? TRUE : FALSE);
|
|
|
|
|
|
- if (-1 == Vect_open_new(&Out, params.olayer->answer, Vect_is_3d(&In)))
|
|
|
+ if (-1 == Vect_open_new(&Out, olayer, Vect_is_3d(&In)))
|
|
|
G_fatal_error(_("Unable to create PostGIS layer <%s>"),
|
|
|
- params.olayer->answer);
|
|
|
+ olayer);
|
|
|
|
|
|
/* define attributes */
|
|
|
field = Vect_get_field_number(&In, params.layer->answer);
|
|
@@ -73,15 +96,24 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/* create PostGIS layer */
|
|
|
create_table(&In, &Out);
|
|
|
-
|
|
|
+
|
|
|
+ if (flags.topo->answer)
|
|
|
+ Vect_build_partial(&Out, GV_BUILD_NONE); /* upgrade level to 2 */
|
|
|
+
|
|
|
/* copy vector features */
|
|
|
if (Vect_copy_map_lines_field(&In, field, &Out) != 0)
|
|
|
G_fatal_error(_("Copying features failed"));
|
|
|
|
|
|
- Vect_build(&Out);
|
|
|
-
|
|
|
Vect_close(&In);
|
|
|
- Vect_close(&Out);
|
|
|
|
|
|
+ if (Vect_build(&Out) != 1)
|
|
|
+ G_fatal_error(_("Building %s topology failed"),
|
|
|
+ flags.topo->answer ? "PostGIS" : "pseudo");
|
|
|
+
|
|
|
+ G_done_msg(_("Feature table <%s> created in database <%s>."),
|
|
|
+ Vect_get_finfo_layer_name(&Out), Vect_get_finfo_dsn_name(&Out));
|
|
|
+
|
|
|
+ Vect_close(&Out);
|
|
|
+
|
|
|
exit(EXIT_SUCCESS);
|
|
|
}
|