Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/******************************************************************************
* $Id: shputils.c,v 1.11 2016-12-05 12:44:06 erouault Exp $
*
* Project: Shapelib
* Purpose:
* Altered "shpdump" and "dbfdump" to allow two files to be appended.
* Other Functions:
* Selecting from the DBF before the write occurs.
* Change the UNITS between Feet and Meters and Shift X,Y.
* Clip and Erase boundary. The program only passes thru the
* data once.
*
* Bill Miller North Carolina - Department of Transporation
* Feb. 1997 -- bmiller@dot.state.nc.us
* There was not a lot of time to debug hidden problems;
* And the code is not very well organized or documented.
* The clip/erase function was not well tested.
* Oct. 2000 -- bmiller@dot.state.nc.us
* Fixed the problem when select is using numbers
* larger than short integer. It now reads long integer.
* NOTE: DBF files created using windows NT will read as a string with
* a length of 381 characters. This is a bug in "dbfopen".
*
*
* Author: Bill Miller (bmiller@dot.state.nc.us)
*
******************************************************************************
* Copyright (c) 1999, Frank Warmerdam
*
* This software is available under the following "MIT Style" license,
* or at the option of the licensee under the LGPL (see COPYING). This
* option is discussed in more detail in shapelib.html.
*
* --
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* $Log: shputils.c,v $
* Revision 1.11 2016-12-05 12:44:06 erouault
* * Major overhaul of Makefile build system to use autoconf/automake.
*
* * Warning fixes in contrib/
*
* Revision 1.10 2007-12-13 19:59:23 fwarmerdam
* reindent code, avoid some warnings.
*
* Revision 1.9 2004/01/14 14:56:00 fwarmerdam
* Some cleanlyness improvements.
*
* Revision 1.8 2004/01/14 14:40:22 fwarmerdam
* Fixed exit() call to include code.
*
* Revision 1.7 2003/02/25 17:20:22 warmerda
* Set psCShape to NULL after SHPDestroyObject() to avoid multi-frees of
* the same memory ... as submitted by Fred Fox.
*
* Revision 1.6 2001/08/28 13:57:14 warmerda
* fixed DBFAddField return value check
*
* Revision 1.5 2000/11/02 13:52:48 warmerda
* major upgrade from Bill Miller
*
* Revision 1.4 1999/11/05 14:12:05 warmerda
* updated license terms
*
* Revision 1.3 1998/12/03 15:47:39 warmerda
* Did a bunch of rewriting to make it work with the V1.2 API.
*
* Revision 1.2 1998/06/18 01:19:49 warmerda
* Made C++ compilable.
*
* Revision 1.1 1997/05/27 20:40:27 warmerda
* Initial revision
*/
#include "shapefil.h"
#include "string.h"
#include <stdlib.h>
SHP_CVSID("$Id: shputils.c,v 1.11 2016-12-05 12:44:06 erouault Exp $")
#ifndef FALSE
# define FALSE 0
# define TRUE 1
#endif
char infile[80], outfile[80], temp[400];
/* Variables for shape files */
SHPHandle hSHP;
SHPHandle hSHPappend;
int nShapeType, nEntities, iPart;
int nShapeTypeAppend, nEntitiesAppend;
SHPObject *psCShape;
double adfBoundsMin[4], adfBoundsMax[4];
/* Variables for DBF files */
DBFHandle hDBF;
DBFHandle hDBFappend;
DBFFieldType iType;
DBFFieldType jType;
char iszTitle[12];
char jszTitle[12];
int *pt;
char iszFormat[32], iszField[1024];
char jszFormat[32], jszField[1024];
int i, ti, iWidth, iDecimals, iRecord;
int j, tj, jWidth, jDecimals, jRecord;
int clip_boundary();
double findunit(char *unit);
void openfiles(void);
void setext(char *pt, char *ext);
int strncasecmp2(char *s1, char *s2, int n);
void mergefields(void);
void findselect(void);
void showitems(void);
int selectrec();
void check_theme_bnd();
int clip_boundary();
void error();
/* -------------------------------------------------------------------- */
/* Variables for the DESCRIBE function */
/* -------------------------------------------------------------------- */
int ilist = FALSE, iall = FALSE;
/* -------------------------------------------------------------------- */
/* Variables for the SELECT function */
/* -------------------------------------------------------------------- */
int found = FALSE, newdbf = FALSE;
char selectitem[40], *cpt;
long int selectvalues[150], selcount=0;
int iselect = FALSE, iselectitem = -1;
int iunselect = FALSE;
/* -------------------------------------------------------------------- */
/* Variables for the CLIP and ERASE functions */
/* -------------------------------------------------------------------- */
double cxmin, cymin, cxmax, cymax;
int iclip = FALSE, ierase = FALSE;
int itouch = FALSE, iinside = FALSE, icut = FALSE;
int ibound = FALSE, ipoly = FALSE;
char clipfile[80];
/* -------------------------------------------------------------------- */
/* Variables for the FACTOR function */
/* -------------------------------------------------------------------- */
double infactor,outfactor,factor = 0; /* NO FACTOR */
int iunit = FALSE;
int ifactor = FALSE;
/* -------------------------------------------------------------------- */
/* Variables for the SHIFT function */
/* -------------------------------------------------------------------- */
double xshift = 0, yshift = 0; /* NO SHIFT */
int main( int argc, char ** argv )
{
/* -------------------------------------------------------------------- */
/* Check command line usage. */
/* -------------------------------------------------------------------- */
if( argc < 2 ) error();
strcpy(infile, argv[1]);
if (argc > 2) {
strcpy(outfile,argv[2]);
if (strncasecmp2(outfile, "LIST",0) == 0) { ilist = TRUE; }
if (strncasecmp2(outfile, "ALL",0) == 0) { iall = TRUE; }
}
if (ilist || iall || argc == 2 ) {
setext(infile, "shp");
printf("DESCRIBE: %s\n",infile);
strcpy(outfile,"");
}
/* -------------------------------------------------------------------- */
/* Look for other functions on the command line. (SELECT, UNIT) */
Loading
Loading full blame...