PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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$"
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
50typedef 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 */
81
82 /* 0=do not keep fieldname case, 1=keep fieldname case */
84
85 /* Number of rows to fetch in a cursor batch */
87
88 /* Name of the column map file if specified */
90
91 /* 0=normal output to stdout, 1=no output to stdout */
92 int quiet;
93
95
96
97/*
98 * Structure to holder the current dumper state
99 */
100
101typedef struct shp_dumper_state
102{
103 /* Configuration for this state */
105
106 /* Database connection being used */
107 PGconn *conn;
108
109 /* Version of PostGIS being used */
111
112 /* OID for geometries */
114
115 /* OID for geographies */
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 */
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 */
153
154 /* Handle of the current SHP file */
156
157 /* Indicate output geometry type: s=2d, z=3dz or 4d, m=3dm */
159
160 /* Shapefile/DBF geometry type */
162
163 /* Number of rows in source database table */
165
166 /* The main query being used for the table scan */
168
169 /* The current row number */
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 */
183
184 /* Last (error) message */
186
187 /* Column map */
189
191
192
193/* Externally accessible functions */
195char *shapetypename(int num);
196
205char *quote_identifier(const char *s);
char * s
Definition cu_in_wkt.c:23
void set_dumper_config_defaults(SHPDUMPERCONFIG *config)
char * quote_identifier(const char *s)
#define SHPDUMPERMSGLEN
int ShpDumperGetRecordCount(SHPDUMPERSTATE *state)
void ShpDumperDestroy(SHPDUMPERSTATE *state)
int ShpDumperConnectDatabase(SHPDUMPERSTATE *state)
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *config)
char * shapetypename(int num)
int ShpLoaderGenerateShapeRow(SHPDUMPERSTATE *state)
SHPDUMPERSTATE * ShpDumperCreate(SHPDUMPERCONFIG *config)
struct shp_dumper_state SHPDUMPERSTATE
int ShpDumperCloseTable(SHPDUMPERSTATE *state)
int ShpDumperOpenTable(SHPDUMPERSTATE *state)
struct shp_dumper_config SHPDUMPERCONFIG
SHPCONNECTIONCONFIG * conn
SHPDUMPERCONFIG * config
char message[SHPDUMPERMSGLEN]