PostGIS  2.2.7dev-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 #include "shapefil.h"
27 #include "shpcommon.h"
28 #include "getopt.h"
29 
30 #define P2S_RCSID "$Id: pgsql2shp-core.h 14176 2015-10-03 06:12:01Z strk $"
31 
32 /*
33  * Error message handling
34  */
35 
36 #define SHPDUMPERMSGLEN 1024
37 
38 #define SHPDUMPEROK -1
39 #define SHPDUMPERERR 0
40 #define SHPDUMPERWARN 1
41 
42 
43 /*
44  * Structure to hold the dumper configuration options
45  */
46 
47 typedef struct shp_dumper_config
48 {
49  /* Parameters used to connect to the database */
51 
52  /* table to load into */
53  char *table;
54 
55  /* schema to load into */
56  char *schema;
57 
58  /* user-specified query, if supplied */
59  char *usrquery;
60 
61  /* 0=use normal cursor, 1=use binary cursor */
62  int binary;
63 
64  /* Name of the output shapefile */
65  char *shp_file;
66 
67  /* TODO: rename? 0=switch not provided, 1=switch provided */
69 
70  /* TODO: replace and combine with below 0=do not include gid column in shapefile, 1=include gid column in shapefile */
72 
73  /* TODO: 0=escape column names, 1=do not escape column names */
75 
76  /* Name of geometry/geography database column */
77  char *geo_col_name;
78 
79  /* 0=do not keep fieldname case, 1=keep fieldname case */
81 
82  /* Number of rows to fetch in a cursor batch */
83  int fetchsize;
84 
85  /* Name of the column map file if specified */
87 
89 
90 
91 /*
92  * Structure to holder the current dumper state
93  */
94 
95 typedef struct shp_dumper_state
96 {
97  /* Configuration for this state */
99 
100  /* Database connection being used */
101  PGconn *conn;
102 
103  /* Version of PostGIS being used */
105 
106  /* 0=dumper running on little endian, 1=dumper running on big endian */
108 
109  /* OID for geometries */
110  int geom_oid;
111 
112  /* OID for geographies */
113  int geog_oid;
114 
115  /* Schema of current working table */
116  char *schema;
117 
118  /* Name of current working table */
119  char *table;
120 
121  /* Name of geography/geometry column in current working table */
123 
124  /* DBF fieldnames for all non-spatial fields */
126 
127  /* DBF field types for all non-spatial fields */
129 
130  /* PostgreSQL column names for all non-spatial fields */
131  char **pgfieldnames;
132 
133  /* PostgreSQL column lengths for all non-spatial fields */
135 
136  /* PostgreSQL column typmods for all non-spatial fields */
138 
139  /* Number of non-spatial fields in DBF output file */
141 
142  /* Number of rows in the database table */
144 
145  /* Name of the current shapefile */
146  char *shp_file;
147 
148  /* Handle of the current DBF file */
149  DBFHandle dbf;
150 
151  /* Handle of the current SHP file */
153 
154  /* Indicate output geometry type: s=2d, z=3dz or 4d, m=3dm */
155  char outtype;
156 
157  /* Shapefile/DBF geometry type */
159 
160  /* Number of rows in source database table */
161  int rowcount;
162 
163  /* The main query being used for the table scan */
165 
166  /* The current row number */
167  int currow;
168 
169  /* The result set for the current FETCH batch */
170  PGresult *fetchres;
171 
172  /* The row number within the current FETCH batch */
174 
175  /* The number of rows within the current FETCH batch */
177 
178  /* The query being used to fetch records from the table */
179  char *fetch_query;
180 
181  /* Last (error) message */
183 
184  /* Column map */
186 
188 
189 
190 /* Externally accessible functions */
192 char *shapetypename(int num);
193 
201 void ShpDumperDestroy(SHPDUMPERSTATE *state);
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)
int ShpDumperGetRecordCount(SHPDUMPERSTATE *state)
#define SHPDUMPERMSGLEN
void ShpDumperDestroy(SHPDUMPERSTATE *state)
char * shapetypename(int num)
char message[SHPDUMPERMSGLEN]
int ShpDumperConnectDatabase(SHPDUMPERSTATE *state)
struct shp_dumper_state SHPDUMPERSTATE
PGresult * fetchres