PostGIS  2.4.9dev-r@@SVN_REVISION@@
pgsql2shp-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 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include <ctype.h>
18 #include <unistd.h>
19 #include <errno.h>
20 #include <math.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <iconv.h>
24 
25 #include "libpq-fe.h"
26 
27 #include "shapefil.h"
28 #include "shpcommon.h"
29 #include "getopt.h"
30 
31 
32 
33 #define P2S_RCSID "$Id: pgsql2shp-core.h 15441 2017-06-23 05:13:22Z robe $"
34 
35 /*
36  * Error message handling
37  */
38 
39 #define SHPDUMPERMSGLEN 1024
40 
41 #define SHPDUMPEROK -1
42 #define SHPDUMPERERR 0
43 #define SHPDUMPERWARN 1
44 
45 
46 /*
47  * Structure to hold the dumper configuration options
48  */
49 
50 typedef struct shp_dumper_config
51 {
52  /* Parameters used to connect to the database */
54 
55  /* table to load into */
56  char *table;
57 
58  /* schema to load into */
59  char *schema;
60 
61  /* user-specified query, if supplied */
62  char *usrquery;
63 
64  /* 0=use normal cursor, 1=use binary cursor */
65  int binary;
66 
67  /* Name of the output shapefile */
68  char *shp_file;
69 
70  /* TODO: rename? 0=switch not provided, 1=switch provided */
72 
73  /* TODO: replace and combine with below 0=do not include gid column in shapefile, 1=include gid column in shapefile */
75 
76  /* TODO: 0=escape column names, 1=do not escape column names */
78 
79  /* Name of geometry/geography database column */
80  char *geo_col_name;
81 
82  /* 0=do not keep fieldname case, 1=keep fieldname case */
84 
85  /* Number of rows to fetch in a cursor batch */
86  int fetchsize;
87 
88  /* Name of the column map file if specified */
90 
92 
93 
94 /*
95  * Structure to holder the current dumper state
96  */
97 
98 typedef struct shp_dumper_state
99 {
100  /* Configuration for this state */
102 
103  /* Database connection being used */
104  PGconn *conn;
105 
106  /* Version of PostGIS being used */
108 
109  /* 0=dumper running on little endian, 1=dumper running on big endian */
111 
112  /* OID for geometries */
113  int geom_oid;
114 
115  /* OID for geographies */
116  int geog_oid;
117 
118  /* Schema of current working table */
119  char *schema;
120 
121  /* Name of current working table */
122  char *table;
123 
124  /* Name of geography/geometry column in current working table */
126 
127  /* DBF fieldnames for all non-spatial fields */
129 
130  /* DBF field types for all non-spatial fields */
132 
133  /* PostgreSQL column names for all non-spatial fields */
134  char **pgfieldnames;
135 
136  /* PostgreSQL column lengths for all non-spatial fields */
138 
139  /* PostgreSQL column typmods for all non-spatial fields */
141 
142  /* Number of non-spatial fields in DBF output file */
144 
145  /* Number of rows in the database table */
147 
148  /* Name of the current shapefile */
149  char *shp_file;
150 
151  /* Handle of the current DBF file */
152  DBFHandle dbf;
153 
154  /* Handle of the current SHP file */
156 
157  /* Indicate output geometry type: s=2d, z=3dz or 4d, m=3dm */
158  char outtype;
159 
160  /* Shapefile/DBF geometry type */
162 
163  /* Number of rows in source database table */
164  int rowcount;
165 
166  /* The main query being used for the table scan */
168 
169  /* The current row number */
170  int currow;
171 
172  /* The result set for the current FETCH batch */
173  PGresult *fetchres;
174 
175  /* The row number within the current FETCH batch */
177 
178  /* The number of rows within the current FETCH batch */
180 
181  /* The query being used to fetch records from the table */
182  char *fetch_query;
183 
184  /* Last (error) message */
185  char message[SHPDUMPERMSGLEN];
186 
187  /* Column map */
189 
191 
192 
193 /* Externally accessible functions */
195 char *shapetypename(int num);
196 
204 void ShpDumperDestroy(SHPDUMPERSTATE *state);
205 char *quote_identifier(const char *s);
char * column_map_filename
int ShpDumperOpenTable(SHPDUMPERSTATE *state)
SHPDUMPERCONFIG * config
int ShpDumperCloseTable(SHPDUMPERSTATE *state)
int ShpLoaderGenerateShapeRow(SHPDUMPERSTATE *state)
void set_dumper_config_defaults(SHPDUMPERCONFIG *config)
SHPDUMPERSTATE * ShpDumperCreate(SHPDUMPERCONFIG *config)
SHPCONNECTIONCONFIG * conn
struct shp_dumper_config SHPDUMPERCONFIG
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *config)
char * s
Definition: cu_in_wkt.c:23
int ShpDumperGetRecordCount(SHPDUMPERSTATE *state)
#define SHPDUMPERMSGLEN
void ShpDumperDestroy(SHPDUMPERSTATE *state)
char * quote_identifier(const char *s)
char * shapetypename(int num)
int ShpDumperConnectDatabase(SHPDUMPERSTATE *state)
struct shp_dumper_state SHPDUMPERSTATE
PGresult * fetchres