PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
shp2pgsql-core.h
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 * Copyright 2001-2003 Refractions Research Inc.
6 * Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
7 * Copyright 2009 Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU General Public Licence. See the COPYING file.
11 *
12 **********************************************************************/
13
14/* Standard headers */
15#include <stdio.h>
16#include <string.h>
17#include <stdlib.h>
18#include <locale.h>
19#include <ctype.h>
20#include <unistd.h>
21#include <errno.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <iconv.h>
25
26#include "shapefil.h"
27#include "shpcommon.h"
28#include "getopt.h"
29
30#include "../liblwgeom/stringbuffer.h"
31
32#define S2P_RCSID "$Id$"
33
34/* Number of digits of precision in WKT produced. */
35#define WKT_PRECISION 15
36
37/* Loader policy constants */
38#define POLICY_NULL_ABORT 0x0
39#define POLICY_NULL_INSERT 0x1
40#define POLICY_NULL_SKIP 0x2
41
42/* Forced dimensionality constants */
43#define FORCE_OUTPUT_DISABLE 0x0
44#define FORCE_OUTPUT_2D 0x1
45#define FORCE_OUTPUT_3DZ 0x2
46#define FORCE_OUTPUT_3DM 0x3
47#define FORCE_OUTPUT_4D 0x4
48
49/* Error message handling */
50#define SHPLOADERMSGLEN 1024
51
52/* Error status codes */
53#define SHPLOADEROK -1
54#define SHPLOADERERR 0
55#define SHPLOADERWARN 1
56
57/* Record status codes */
58#define SHPLOADERRECDELETED 2
59#define SHPLOADERRECISNULL 3
60
61/*
62 * Shapefile (dbf) field name are at most 10chars + 1 NULL.
63 * Postgresql field names are at most 63 bytes + 1 NULL.
64 */
65#define MAXFIELDNAMELEN 64
66#define MAXVALUELEN 1024
67
68/*
69 * Default geometry column name
70 */
71#define GEOMETRY_DEFAULT "geom"
72#define GEOGRAPHY_DEFAULT "geog"
73
74/*
75 * Default character encoding
76 */
77#define ENCODING_DEFAULT "UTF-8"
78
79/*
80 * Structure to hold the loader configuration options
81 */
82typedef struct shp_loader_config
83{
84 /* load mode: c = create, d = delete, a = append, p = prepare */
85 char opt;
86
87 /* table to load into */
88 char *table;
89
90 /* schema to load into */
91 char *schema;
92
93 /* geometry/geography column name specified by the user, may be null. */
94 char *geo_col;
95
96 /* the shape file (without the .shp extension) */
97 char *shp_file;
98
99 /* 0 = SQL inserts, 1 = dump */
101
102 /* 0 = MULTIPOLYGON/MULTILINESTRING, 1 = force to POLYGON/LINESTRING */
104
105 /* 0 = geometry, 1 = geography */
107
108 /* 0 = columnname, 1 = "columnName" */
110
111 /* 0 = allow int8 fields, 1 = no int8 fields */
113
114 /* 0 = no index, 1 = create index after load */
116
117 /* 0 = don't analyze tables , 1 = analyze tables */
119
120 /* 0 = load DBF file only, 1 = load everything */
122
123 /* Override the output geometry type (a FORCE_OUTPUT_* constant) */
125
126 /* iconv encoding name */
127 char *encoding;
128
129 /* tablespace name for the table */
131
132 /* tablespace name for the indexes */
134
135 /* how to handle nulls */
137
138 /* SRID specified */
139 int sr_id;
140
141 /* SRID of the shape file */
143
144 /* 0 = WKB (more precise), 1 = WKT (may have coordinate drift). */
146
147 /* whether to do a single transaction or run each statement on its own */
149
150 /* Name of the column map file if specified */
152
154
155
156/*
157 * Structure to holder the current loader state
158 */
159typedef struct shp_loader_state
160{
161 /* Configuration for this state */
163
164 /* Shapefile handle */
166
167 /* Shapefile type */
169
170 /* Data file handle */
172
173 /* Number of rows in the shapefile */
175
176 /* Number of fields in the shapefile */
178
179 /* Number of rows in the DBF file */
181
182 /* Pointer to an array of field names */
184
185 /* Field type */
187
188 /* Arrays of field widths and precisions */
189 int *widths;
191
192 /* Pointer to an array of PostgreSQL field types */
194
195 /* String containing colume name list in the form "col1, col2, col3 ... , colN" */
197
198 /* String containing the PostGIS geometry type, e.g. POINT, POLYGON etc. */
199 char *pgtype;
200
201 /* Flag for whether the output geometry has Z coordinates or not. */
202 int has_z;
203
204 /* Flag for whether the output geometry has M coordinates or not. */
205 int has_m;
206
207 /* Number of dimensions to output */
209
210 /* Last (error) message */
212
213 /* SRID of the shape file. If not reprojecting, will be the same as to_srid. */
215
216 /* SRID of the table. If not reprojecting, will be the same as from_srid. */
218
219 /* geometry/geography column name to use. Will be set to the default if the config did
220 not specify a column name. */
221 char *geo_col;
222
223 /* Column map */
225
227
228
229/* Externally accessible functions */
230void strtolower(char *s);
232
235int ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader);
236int ShpLoaderGetSQLCopyStatement(SHPLOADERSTATE *state, char **strheader);
238int ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strrecord);
239int ShpLoaderGetSQLFooter(SHPLOADERSTATE *state, char **strfooter);
char * s
Definition cu_in_wkt.c:23
DBFFieldType
Definition shapefil.h:638
int ShpLoaderGetRecordCount(SHPLOADERSTATE *state)
struct shp_loader_config SHPLOADERCONFIG
struct shp_loader_state SHPLOADERSTATE
#define SHPLOADERMSGLEN
void strtolower(char *s)
void ShpLoaderDestroy(SHPLOADERSTATE *state)
SHPLOADERSTATE * ShpLoaderCreate(SHPLOADERCONFIG *config)
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)
int ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
char message[SHPLOADERMSGLEN]
DBFFieldType * types
SHPLOADERCONFIG * config