]> granicus.if.org Git - postgis/commitdiff
added -p option (prepare mode) that spits out the table schema without
authorMarkus Schaber <markus@schabi.de>
Wed, 6 Apr 2005 14:02:08 +0000 (14:02 +0000)
committerMarkus Schaber <markus@schabi.de>
Wed, 6 Apr 2005 14:02:08 +0000 (14:02 +0000)
inserting any data.

git-svn-id: http://svn.osgeo.org/postgis/trunk@1600 b70326c6-7e19-0410-871a-916f4a2858ee

doc/man/shp2pgsql.1
doc/postgis.xml
loader/README.shp2pgsql
loader/shp2pgsql.c

index e14a7443071032ae7755fb3bfa900987f9f6e35e..6eb233f0abf86be6d3906ea3c36fe0ac79c40caf 100644 (file)
@@ -25,9 +25,15 @@ Appends data from the Shape file into the database table. Note that to use this
 \fB\-c\fR
 Creates a new table and populates it from the Shape file. This is the default mode.
 
+.TP 
+\fB\-p\fR
+Only produces the table creation SQL code, without adding any actual data. This can
+be used if you need to completely separate the table creation and data loading steps.
+
 .TP 
 \fB\-D\fR
-Use the PostgreSQL "dump" format for the output data. This can be combined with -d, -a and -c and is much faster to load than the default "insert" SQL format. Use this for very large data sets.
+Use the PostgreSQL "dump" format for the output data. This can be combined with -a, -c and -d.
+It is much faster to load than the default "insert" SQL format. Use this for very large data sets.
 
 .TP 
 \fB\-s\fR <\fISRID\fR>
@@ -47,6 +53,9 @@ Output WKT format, for use with older (0.x) versions of PostGIS.
 Note that this will introduce coordinate drifts and will drop
 M values from shapefiles.
 
+.LP
+Note that -a, -c, -d and -p are mutually exclusive.
+
 .SH "EXAMPLES"
 .LP 
 An example session using the loader to create an input file and uploading it might look like this:
index 61a8d57dbff934ef580311b6fb551d504f078df4..6d62a41d1c28d251f52f9a759ded9c16076195d1 100644 (file)
@@ -1282,14 +1282,24 @@ COMMIT;</programlisting>
             </listitem>
           </varlistentry>
 
+          <varlistentry>
+            <term>-p</term>
+
+            <listitem>
+              <para>Only produces the table creation SQL code, without adding 
+              any actual data. This can be used if you need to completely
+              separate the table creation and data loading steps.</para>
+            </listitem>
+          </varlistentry>
+
           <varlistentry>
             <term>-D</term>
 
             <listitem>
-              <para>Creates a new table and populates it from the Shape file.
-              This uses the PostgreSQL "dump" format for the output data and
-              is much faster to load than the default "insert" SQL format. Use
-              this for very large data sets.</para>
+              <para>Use the PostgreSQL "dump" format for the output data. This 
+              can be combined with -a, -c and -d. It is much faster to load
+              than the default "insert" SQL format. Use this for very large data
+              sets.</para>
             </listitem>
           </varlistentry>
 
@@ -1334,6 +1344,8 @@ COMMIT;</programlisting>
 
         </variablelist>
 
+        <para>Note that -a, -c, -d and -p are mutually exclusive.</para>
+
         <para>An example session using the loader to create an input file and
         uploading it might look like this:</para>
 
index ef77ece81c06e60b0135cca078b38778c85b5b2d..09337d0226ab35871bf3c71da242cabde1787631 100644 (file)
@@ -38,19 +38,23 @@ the data into.
 
 The options are as follows:
 
-(-a || -c || -d) these options are mutually exclusive.
+(-a || -c || -d || -p) these options are mutually exclusive.
 
   -a    Append mode. Do not delete the target table or try to create
         a new table, simple insert the data into the existing table.
         A table will have to exist for this to work, it is usually
-        used after a create mode as been run once.(mutually exclusive
-       with -c and -d)
+        used after a create mode as been run once or after -p. (mutually
+        exclusive with -c, -d and -p)
   -c    Create mode. This is the default mode is no other is specified.
        Create a new table and upload the data into that table.
-       (mutually exclusive with -a and -d)
+       (mutually eclusive with -a, -d and -p)
   -d    Delete mode. Delete the database table named <tablename>, then
        create a new one with that name before uploading the data into
-       the new empty database table.(mutually exclusive with -a and -c)
+       the new empty database table. (mutually exclusive with -a, -c 
+        and -p)
+  -p    Prepare mode. Read the table schema from the shape file and 
+        create the new table, but do not insert any data. (mutually
+        exclusive with -a, -c and -d)
 
   -D Dump. When inserting the data into the table use 'dump' format.
        Dump format is used by PostgreSQL for large data dumps and 
index a24829ca9adcf651042d721c03eaf852745138d7..0dad9cd3997f3498ac6bd1bb316204692ee2950b 100644 (file)
@@ -396,12 +396,12 @@ main (int ARGC, char **ARGV)
        /*
         * Generate INSERT or COPY lines
         */
-       LoadData();
+       if(opt != 'p') LoadData();
 
        /*
         * If not in 'append' mode update sequence numbering
         */
-       if(opt != 'a') UpdateSerials();
+       if(opt != 'a' && opt != 'p') UpdateSerials();
 
        printf("END;\n"); // End the last transaction
 
@@ -699,13 +699,14 @@ usage(char *me, int exitcode)
        fprintf(stderr, "OPTIONS:\n");
        fprintf(stderr, "  -s <srid>  Set the SRID field. If not specified it defaults to -1.\n");
        fprintf(stderr, "\n");
-       fprintf(stderr, "  (-d|a|c) These are mutually exclusive options:\n");
+       fprintf(stderr, "  (-d|a|c|p) These are mutually exclusive options:\n");
        fprintf(stderr, "      -d  Drops the table , then recreates it and populates\n");
        fprintf(stderr, "          it with current shape file data.\n");
        fprintf(stderr, "      -a  Appends shape file into current table, must be\n");
        fprintf(stderr, "          exactly the same table schema.\n");
        fprintf(stderr, "      -c  Creates a new table and populates it, this is the\n");
        fprintf(stderr, "          default if you do not specify any options.\n");
+       fprintf(stderr, "      -p  Prepare mode, only creates the table\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "  -g <geometry_column> Specify the name of the geometry column\n");
        fprintf(stderr, "     (mostly useful in append mode).\n");
@@ -1186,7 +1187,7 @@ ParseCmdline(int ARGC, char **ARGV)
        extern char *optarg;
        extern int optind;
 
-       while ((c = getopt(ARGC, ARGV, "kcdaDs:g:iW:w")) != EOF){
+       while ((c = getopt(ARGC, ARGV, "kcdapDs:g:iW:w")) != EOF){
                switch (c) {
                case 'c':
                     if (opt == ' ')
@@ -1206,6 +1207,12 @@ ParseCmdline(int ARGC, char **ARGV)
                     else
                          return 0;
                     break;
+              case 'p':
+                    if (opt == ' ')
+                         opt ='p';
+                    else
+                         return 0;
+                    break;
               case 'D':
                    dump_format =1;
                     break;
@@ -1623,6 +1630,10 @@ utf8 (const char *fromcode, char *inputbuf)
 
 /**********************************************************************
  * $Log$
+ * Revision 1.86  2005/04/06 14:02:08  mschaber
+ * added -p option (prepare mode) that spits out the table schema without
+ * inserting any data.
+ *
  * Revision 1.85  2005/04/06 10:46:10  strk
  * Bugfix in -w (hwgeom) handling of ZM shapefiles.
  * Big reorganizzation of code to easy maintainance.