15 #include "../postgis_config.h"
18 #include "../liblwgeom/liblwgeom.h"
20 #define xstr(s) str(s)
26 printf(
_(
"RELEASE: %s (%s)\n" ),
28 printf(
_(
"USAGE: shp2pgsql [<options>] <shapefile> [[<schema>.]<table>]\n"
30 printf(
_(
" -s [<from>:]<srid> Set the SRID field. Defaults to %d.\n"
31 " Optionally reprojects from given SRID.\n"),
33 printf(
_(
" (-d|a|c|p) These are mutually exclusive options:\n"
34 " -d Drops the table, then recreates it and populates\n"
35 " it with current shape file data.\n"
36 " -a Appends shape file into current table, must be\n"
37 " exactly the same table schema.\n"
38 " -c Creates a new table and populates it, this is the\n"
39 " default if you do not specify any options.\n"
40 " -p Prepare mode, only creates the table.\n" ));
41 printf(
_(
" -g <geocolumn> Specify the name of the geometry/geography column\n"
42 " (mostly useful in append mode).\n" ));
43 printf(
_(
" -D Use postgresql dump format (defaults to SQL insert statements).\n" ));
44 printf(
_(
" -e Execute each statement individually, do not use a transaction.\n"
45 " Not compatible with -D.\n" ));
46 printf(
_(
" -G Use geography type (requires lon/lat data or -s to reproject).\n" ));
47 printf(
_(
" -k Keep postgresql identifiers case.\n" ));
48 printf(
_(
" -i Use int4 type for all integer dbf fields.\n" ));
49 printf(
_(
" -I Create a spatial index on the geocolumn.\n" ));
50 printf(
_(
" -m <filename> Specify a file containing a set of mappings of (long) column\n"
51 " names to 10 character DBF column names. The content of the file is one or\n"
52 " more lines of two names separated by white space and no trailing or\n"
53 " leading space. For example:\n"
54 " COLUMNNAME DBFFIELD1\n"
55 " AVERYLONGCOLUMNNAME DBFFIELD2\n" ));
56 printf(
_(
" -S Generate simple geometries instead of MULTI geometries.\n" ));
57 printf(
_(
" -t <dimensionality> Force geometry to be one of '2D', '3DZ', '3DM', or '4D'\n" ));
59 printf(
_(
" -w Output WKT instead of WKB. Note that this can result in\n"
60 " coordinate drift.\n" ));
61 printf(
_(
" -W <encoding> Specify the character encoding of Shape's\n"
62 " attribute column. (default: \"UTF-8\")\n" ));
63 printf(
_(
" -N <policy> NULL geometries handling policy (insert*,skip,abort).\n" ));
64 printf(
_(
" -n Only import DBF file.\n" ));
65 printf(
_(
" -T <tablespace> Specify the tablespace for the new table.\n"
66 " Note that indexes will still use the default tablespace unless the\n"
67 " -X flag is also used.\n"));
68 printf(
_(
" -X <tablespace> Specify the tablespace for the table's indexes.\n"
69 " This applies to the primary key, and the spatial index if\n"
70 " the -I flag is used.\n" ));
71 printf(
_(
" -Z Prevent tables from being analyzed.\n" ));
72 printf(
_(
" -? Display this help screen.\n" ));
74 printf(
_(
" An argument of `--' disables further option processing.\n" ));
75 printf(
_(
" (useful for unusual file names starting with '-')\n" ));
80 main (
int argc,
char **argv)
84 char *header, *footer, *record;
89 #ifdef PGSQL_LOCALEDIR
90 setlocale (LC_ALL,
"");
91 bindtextdomain (PACKAGE, PGSQL_LOCALEDIR);
108 while ((c =
pgis_getopt(argc, argv,
"-acdeg:ikm:nps:t:wDGIN:ST:W:X:Z")) != EOF)
147 sscanf(ptr,
"%d", &config->
sr_id);
158 fprintf(stderr,
"The -s parameter must be specified in the form [FROM_SRID:]TO_SRID\n");
206 fprintf(stderr,
"Unsupported NULL geometry handling policy.\nValid policies: insert, skip, abort\n");
230 fprintf(stderr,
"Unsupported output type: %s\nValid output types are 2D, 3DZ, 3DM and 4D\n",
pgis_optarg);
260 fprintf(stderr,
"Invalid argument combination - cannot use both -D and -e\n");
280 char *chrptr = strchr(strptr,
'.');
285 if ( chrptr == strptr )
294 config->
schema = strdup(strptr);
295 config->
table = strdup(chrptr+1);
299 config->
table = strdup(strptr);
307 char *shp_file = strdup(config->
shp_file);
311 for ( ptr = shp_file + strlen(shp_file); ptr > shp_file; ptr-- )
321 for ( ptr = shp_file + strlen(shp_file); ptr > shp_file; ptr-- )
323 if ( *ptr ==
'/' || *ptr ==
'\\' )
329 config->
table = strdup(ptr);
350 fprintf(stderr,
"%s\n", state->
message);
360 fprintf(stderr,
"Postgis type: %s[%d]\n", state->
pgtype, state->
pgdims);
367 fprintf(stderr,
"%s\n", state->
message);
373 printf(
"%s", header);
386 fprintf(stderr,
"%s\n", state->
message);
392 printf(
"%s", header);
405 printf(
"%s\n", record);
411 fprintf(stderr,
"%s\n", state->
message);
417 fprintf(stderr,
"%s\n", state->
message);
418 printf(
"%s\n", record);
442 fprintf(stderr,
"%s\n", state->
message);
448 printf(
"%s", footer);
int pgis_getopt(int argc, char **argv, char *opts)
int main(int argc, char *argv[])
#define SRID_UNKNOWN
Unknown SRID value.
const char SHPAPI_CALL1 * SHPTypeName(int nSHPType);const char SHPAPI_CALL1(*) SHPPartTypeName(int nPartType
int ShpLoaderGetRecordCount(SHPLOADERSTATE *state)
void ShpLoaderDestroy(SHPLOADERSTATE *state)
int ShpLoaderGetSQLCopyStatement(SHPLOADERSTATE *state, char **strheader)
int ShpLoaderOpenShape(SHPLOADERSTATE *state)
int ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strrecord)
void set_loader_config_defaults(SHPLOADERCONFIG *config)
int ShpLoaderGetSQLFooter(SHPLOADERSTATE *state, char **strfooter)
SHPLOADERSTATE * ShpLoaderCreate(SHPLOADERCONFIG *config)
int ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
#define POLICY_NULL_ABORT
#define SHPLOADERRECISNULL
#define POLICY_NULL_INSERT
#define SHPLOADERRECDELETED
#define POSTGIS_LIB_VERSION
char * column_map_filename
char message[SHPLOADERMSGLEN]