shp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +34 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +28 -0
  6. data/README.md +30 -0
  7. data/Rakefile +23 -0
  8. data/ext/shp/base.hpp +113 -0
  9. data/ext/shp/dbf.cpp +381 -0
  10. data/ext/shp/dbf.hpp +44 -0
  11. data/ext/shp/extconf.rb +13 -0
  12. data/ext/shp/shape_object.cpp +58 -0
  13. data/ext/shp/shape_object.hpp +27 -0
  14. data/ext/shp/shapefile.cpp +299 -0
  15. data/ext/shp/shapefile.hpp +35 -0
  16. data/ext/shp/shapelib/.cvsignore +15 -0
  17. data/ext/shp/shapelib/ChangeLog +450 -0
  18. data/ext/shp/shapelib/HOWTO-RELEASE +16 -0
  19. data/ext/shp/shapelib/LICENSE.LGPL +483 -0
  20. data/ext/shp/shapelib/Makefile +113 -0
  21. data/ext/shp/shapelib/README +41 -0
  22. data/ext/shp/shapelib/README.tree +172 -0
  23. data/ext/shp/shapelib/contrib/.cvsignore +12 -0
  24. data/ext/shp/shapelib/contrib/Makefile +66 -0
  25. data/ext/shp/shapelib/contrib/ShapeFileII.pas +234 -0
  26. data/ext/shp/shapelib/contrib/Shape_PointInPoly.cpp +238 -0
  27. data/ext/shp/shapelib/contrib/Shape_PointInPoly_README.txt +59 -0
  28. data/ext/shp/shapelib/contrib/csv2shp.c +558 -0
  29. data/ext/shp/shapelib/contrib/dbfcat.c +166 -0
  30. data/ext/shp/shapelib/contrib/dbfinfo.c +106 -0
  31. data/ext/shp/shapelib/contrib/makefile.vc +34 -0
  32. data/ext/shp/shapelib/contrib/my_nan.h +46 -0
  33. data/ext/shp/shapelib/contrib/shpcat.c +100 -0
  34. data/ext/shp/shapelib/contrib/shpcentrd.c +159 -0
  35. data/ext/shp/shapelib/contrib/shpdata.c +129 -0
  36. data/ext/shp/shapelib/contrib/shpdxf.c +340 -0
  37. data/ext/shp/shapelib/contrib/shpfix.c +110 -0
  38. data/ext/shp/shapelib/contrib/shpgeo.c +1595 -0
  39. data/ext/shp/shapelib/contrib/shpgeo.h +154 -0
  40. data/ext/shp/shapelib/contrib/shpinfo.c +113 -0
  41. data/ext/shp/shapelib/contrib/shpproj.c +260 -0
  42. data/ext/shp/shapelib/contrib/shpsort.c +605 -0
  43. data/ext/shp/shapelib/contrib/shpsort.txt +44 -0
  44. data/ext/shp/shapelib/contrib/shpwkb.c +123 -0
  45. data/ext/shp/shapelib/contrib/tests/shpproj.sh +38 -0
  46. data/ext/shp/shapelib/dbfopen.c +2221 -0
  47. data/ext/shp/shapelib/makefile.vc +86 -0
  48. data/ext/shp/shapelib/makeshape.sh +21 -0
  49. data/ext/shp/shapelib/mkdist.sh +37 -0
  50. data/ext/shp/shapelib/mkinstalldirs +38 -0
  51. data/ext/shp/shapelib/mkrelease.sh +55 -0
  52. data/ext/shp/shapelib/safileio.c +286 -0
  53. data/ext/shp/shapelib/shapefil.h +647 -0
  54. data/ext/shp/shapelib/shapelib.def +46 -0
  55. data/ext/shp/shapelib/shpopen.c +2388 -0
  56. data/ext/shp/shapelib/shptree.c +1187 -0
  57. data/ext/shp/shapelib/shputils.c +1072 -0
  58. data/ext/shp/shapelib/stream1.out +1465 -0
  59. data/ext/shp/shapelib/stream1.sh +28 -0
  60. data/ext/shp/shapelib/stream2.out +530 -0
  61. data/ext/shp/shapelib/stream2.sh +11 -0
  62. data/ext/shp/shapelib/stream3.out +37 -0
  63. data/ext/shp/shapelib/web/.cvsignore +2 -0
  64. data/ext/shp/shapelib/web/codepage.html +403 -0
  65. data/ext/shp/shapelib/web/dbf_api.html +436 -0
  66. data/ext/shp/shapelib/web/index.html +235 -0
  67. data/ext/shp/shapelib/web/license.html +78 -0
  68. data/ext/shp/shapelib/web/manifest.html +87 -0
  69. data/ext/shp/shapelib/web/release.html +80 -0
  70. data/ext/shp/shapelib/web/shapelib-tools.html +352 -0
  71. data/ext/shp/shapelib/web/shp_api.html +376 -0
  72. data/ext/shp/shp.cpp +19 -0
  73. data/ext/shp/shp.hpp +47 -0
  74. data/lib/shp.rb +35 -0
  75. data/lib/shp/version.rb +3 -0
  76. data/shp.gemspec +23 -0
  77. data/spec/shp_spec.rb +127 -0
  78. metadata +176 -0
@@ -0,0 +1,154 @@
1
+ /******************************************************************************
2
+ * Copyright (c) 1999, Carl Anderson
3
+ *
4
+ * This code is based in part on the earlier work of Frank Warmerdam
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a
7
+ * copy of this software and associated documentation files (the "Software"),
8
+ * to deal in the Software without restriction, including without limitation
9
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
+ * and/or sell copies of the Software, and to permit persons to whom the
11
+ * Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included
14
+ * in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ ******************************************************************************
24
+ * shpgeo.h
25
+ *
26
+ * support for geometric and other additions to shapelib
27
+ *
28
+ *
29
+ * $Log: shpgeo.h,v $
30
+ * Revision 1.3 2002-01-15 14:36:56 warmerda
31
+ * upgrade to use proj_api.h
32
+ *
33
+ * Revision 1.2 1999/05/26 02:56:31 candrsn
34
+ * updates to shpdxf, dbfinfo, port from Shapelib 1.1.5 of dbfcat and shpinfo
35
+ *
36
+ *
37
+ */
38
+
39
+
40
+
41
+ /* I'm using some shorthand throughout this file
42
+ * R+ is a Clockwise Ring and is the positive portion of an object
43
+ * R- is a CounterClockwise Ring and is a hole in a R+
44
+ * A complex object is one having at least one R-
45
+ * A compound object is one having more than one R+
46
+ * A simple object has one and only one element (R+ or R-)
47
+ *
48
+ * The closed ring constraint is for polygons and assumed here
49
+ * Arcs or LineStrings I am calling Rings (generically open or closed)
50
+ * Point types are vertices or lists of vertices but not Rings
51
+ *
52
+ * SHPT_POLYGON, SHPT_POLYGONZ, SHPT_POLYGONM and SHPT_MULTIPATCH
53
+ * can have SHPObjects that are compound as well as complex
54
+ *
55
+ * SHP_POINT and its Z and M derivatives are strictly simple
56
+ * MULTI_POINT, SHPT_ARC and their derivatives may be simple or compound
57
+ *
58
+ */
59
+
60
+
61
+ #ifndef SHPGEO_H
62
+
63
+ #define SHPGEO_H
64
+
65
+
66
+ #ifdef __cplusplus
67
+ extern "C" {
68
+ #endif
69
+
70
+ #include "proj_api.h"
71
+
72
+
73
+ #define SHPD_POINT 1
74
+ #define SHPD_LINE 2
75
+ #define SHPD_AREA 4
76
+ #define SHPD_Z 8
77
+ #define SHPD_MEASURE 16
78
+
79
+
80
+ /* move these into a ogis header file ogis.h */
81
+ #define OGIST_UNKNOWN 0
82
+ #define OGIST_POINT 1
83
+ #define OGIST_LINESTRING 2
84
+ #define OGIST_POLYGON 3
85
+ #define OGIST_MULTIPOINT 4
86
+ #define OGIST_MULTILINE 5
87
+ #define OGIST_MULTIPOLYGON 6
88
+ #define OGIST_GEOMCOLL 7
89
+
90
+ typedef struct { int StreamPos;
91
+ int NeedSwap;
92
+ char *wStream;
93
+ } WKBStreamObj;
94
+
95
+ typedef struct { double x; double y; } PT;
96
+
97
+
98
+ typedef struct { int cParts;
99
+ SHPObject *SHPObj;
100
+ } SHPObjectList;
101
+
102
+
103
+ #define LSB_ORDER (int) 1
104
+
105
+
106
+ extern char * asFileName ( const char *fil, char *ext );
107
+ extern int SHPProject ( SHPObject *psCShape,
108
+ projPJ inproj, projPJ outproj );
109
+ extern projPJ SHPSetProjection ( int param_cnt, char **params );
110
+ extern int SHPFreeProjection ( projPJ p);
111
+
112
+ extern int SHPDimension ( int SHPType );
113
+
114
+ extern double SHPArea_2d ( SHPObject *psCShape );
115
+ extern int SHPRingDir_2d ( SHPObject *psCShape, int Ring );
116
+ extern double SHPLength_2d ( SHPObject *psCShape );
117
+ extern PT SHPCentrd_2d ( SHPObject *psCShape );
118
+ extern PT SHPPointinPoly_2d ( SHPObject *psCShape );
119
+ extern PT* SHPPointsinPoly_2d ( SHPObject *psCShape );
120
+
121
+ extern int RingCentroid_2d ( int nVertices, double *a, double *b, PT *C,
122
+ double *Area );
123
+ extern double RingLength_2d ( int nVertices, double *a, double *b );
124
+ extern int RingDir_2d ( int nVertices, double *a, double *b );
125
+ extern double RingArea_2d ( int nVertices, double *a, double *b );
126
+
127
+ extern SHPObject* SHPClone ( SHPObject *psCShape, int lowPart, int highPart );
128
+ extern SHPObject* SHPUnCompound ( SHPObject *psCShape, int * ringNumber );
129
+ extern SHPObject* SHPIntersect_2d ( SHPObject* a, SHPObject* b );
130
+
131
+ extern int SHPWriteOGisWKB ( WKBStreamObj *stream_obj, SHPObject *psCShape );
132
+ extern SHPObject* SHPReadOGisWKB ( WKBStreamObj *stream_obj );
133
+
134
+ int SHPWriteOGisPolygon ( WKBStreamObj *stream_obj, SHPObject *psCShape );
135
+ int SHPWriteOGisLine ( WKBStreamObj *stream_obj, SHPObject *psCShape );
136
+ int SHPWriteOGisPoint ( WKBStreamObj *stream_obj, SHPObject *psCShape );
137
+
138
+ SHPObject* SHPReadOGisPolygon ( WKBStreamObj *stream_obj );
139
+ SHPObject* SHPReadOGisLine ( WKBStreamObj *stream_obj );
140
+ SHPObject* SHPReadOGisPoint ( WKBStreamObj *stream_obj );
141
+
142
+ extern int SHPClean ( SHPObject *psCShape );
143
+ extern int SHPOGisType ( int GeomType, int toOGis);
144
+
145
+ void swapD (void *so, unsigned char *in, long bytes);
146
+ void swapW (void *so, unsigned char *in, long bytes);
147
+ void SwapG( void *so, void *in, int this_cnt, int this_size );
148
+
149
+
150
+ #ifdef __cplusplus
151
+ }
152
+ #endif
153
+
154
+ #endif /* ndef SHPGEO_H */
@@ -0,0 +1,113 @@
1
+ /******************************************************************************
2
+ * Copyright (c) 1999, Carl Anderson
3
+ *
4
+ * This code is based in part on the earlier work of Frank Warmerdam
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a
7
+ * copy of this software and associated documentation files (the "Software"),
8
+ * to deal in the Software without restriction, including without limitation
9
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
+ * and/or sell copies of the Software, and to permit persons to whom the
11
+ * Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included
14
+ * in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ ******************************************************************************
24
+ *
25
+ * requires shapelib 1.2
26
+ * gcc shpinfoj shpopen.o -o shpinfo
27
+ *
28
+ *
29
+ * $Log: shpinfo.c,v $
30
+ * Revision 1.4 2011-07-24 03:17:46 fwarmerdam
31
+ * include string.h and stdlib.h where needed in contrib (#2146)
32
+ *
33
+ * Revision 1.3 2002-04-15 21:33:03 warmerda
34
+ * Avoid dereference arrays.
35
+ *
36
+ * Revision 1.2 2002/04/15 18:40:31 warmerda
37
+ * Fixed size of adfBnds{Min,Max} as per bug from David Fowler.
38
+ *
39
+ * Revision 1.1 1999/05/26 02:56:31 candrsn
40
+ * updates to shpdxf, dbfinfo, port from Shapelib 1.1.5 of dbfcat and shpinfo
41
+ *
42
+ *
43
+ */
44
+
45
+ #include <stdlib.h>
46
+ #include <string.h>
47
+ #include "shapefil.h"
48
+
49
+ int main( int argc, char ** argv )
50
+
51
+ {
52
+ SHPHandle hSHP, cSHP;
53
+ int nShapeType, nEntities, nVertices, nParts, *panParts, i, iPart;
54
+ double *padVertices, adfBndsMin[4], adfBndsMax[4];
55
+ const char *pszPlus;
56
+ int cShapeType, cEntities, cVertices, cParts, *cpanParts, ci, cPart;
57
+ double *cpadVertices, cadBounds[4];
58
+ const char *cpszPlus;
59
+ char sType [15]= "";
60
+ /* -------------------------------------------------------------------- */
61
+ /* Display a usage message. */
62
+ /* -------------------------------------------------------------------- */
63
+ if( argc != 2 )
64
+ {
65
+ printf( "shpinfo shp_file\n" );
66
+ exit( 1 );
67
+ }
68
+
69
+ /* -------------------------------------------------------------------- */
70
+ /* Open the passed shapefile. */
71
+ /* -------------------------------------------------------------------- */
72
+ hSHP = SHPOpen( argv[1], "rb" );
73
+
74
+ if( hSHP == NULL )
75
+ {
76
+ printf( "Unable to open:%s\n", argv[1] );
77
+ exit( 1 );
78
+ }
79
+
80
+ SHPGetInfo( hSHP, &nEntities, &nShapeType, adfBndsMin, adfBndsMax );
81
+
82
+ switch ( nShapeType ) {
83
+ case SHPT_POINT:
84
+ strcpy(sType,"Point");
85
+ break;
86
+
87
+ case SHPT_ARC:
88
+ strcpy(sType,"Polyline");
89
+ break;
90
+
91
+ case SHPT_POLYGON:
92
+ strcpy(sType,"Polygon");
93
+ break;
94
+
95
+ case SHPT_MULTIPOINT:
96
+ strcpy(sType,"MultiPoint");
97
+ break;
98
+ }
99
+
100
+ /* -------------------------------------------------------------------- */
101
+ printf ("Info for %s\n",argv[1]);
102
+ printf ("%s(%d), %ld Records in file\n",sType,nShapeType,nEntities);
103
+
104
+ /* -------------------------------------------------------------------- */
105
+ /* Print out the file bounds. */
106
+ /* -------------------------------------------------------------------- */
107
+ printf( "File Bounds: (%15.10lg,%15.10lg)\n\t(%15.10lg,%15.10lg)\n",
108
+ adfBndsMin[0], adfBndsMin[1], adfBndsMax[0], adfBndsMax[1] );
109
+
110
+
111
+
112
+ SHPClose( hSHP );
113
+ }
@@ -0,0 +1,260 @@
1
+ /******************************************************************************
2
+ * Copyright (c) 1999, Carl Anderson
3
+ *
4
+ * This code is based in part on the earlier work of Frank Warmerdam
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a
7
+ * copy of this software and associated documentation files (the "Software"),
8
+ * to deal in the Software without restriction, including without limitation
9
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
+ * and/or sell copies of the Software, and to permit persons to whom the
11
+ * Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included
14
+ * in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ * DEALINGS IN THE SOFTWARE.
23
+ ******************************************************************************
24
+ *
25
+ * requires shapelib 1.2
26
+ * gcc shpproj ../shpopen.o ../dbfopen.o shpgeo.o -lm -lproj -o shpproj
27
+ *
28
+ * this requires linking with the PROJ4.3 projection library available from
29
+ *
30
+ * ftp://kai.er.usgs.gov/ftp/PROJ.4
31
+ *
32
+ *
33
+ * SHPGeo must be compiled with -DPROJ4 support
34
+ *
35
+ * $Log: shpproj.c,v $
36
+ * Revision 1.10 2011-07-24 03:17:46 fwarmerdam
37
+ * include string.h and stdlib.h where needed in contrib (#2146)
38
+ *
39
+ * Revision 1.9 2002-01-15 14:37:08 warmerda
40
+ * upgrade to use proj_api.h
41
+ *
42
+ * Revision 1.8 2002/01/11 15:47:26 warmerda
43
+ * several fixes
44
+ *
45
+ * Revision 1.7 2002/01/11 15:23:28 warmerda
46
+ * use text mode reading and writing .prj files
47
+ *
48
+ * Revision 1.6 1999/05/26 02:56:31 candrsn
49
+ * updates to shpdxf, dbfinfo, port from Shapelib 1.1.5 of dbfcat and shpinfo
50
+ *
51
+ * Revision 1.2 1999/05/13 19:30:52 warmerda
52
+ * Removed libgen.h, added url for PROJ.4, and corrected unsafe return of
53
+ * local variable in asFileName().
54
+ *
55
+ */
56
+
57
+
58
+ #include <stdlib.h>
59
+ #include <string.h>
60
+ #include <stdarg.h>
61
+ #include "shapefil.h"
62
+ #include "shpgeo.h"
63
+
64
+ int main( int argc, char ** argv )
65
+ {
66
+ SHPHandle old_SHP, new_SHP;
67
+ DBFHandle old_DBF, new_DBF;
68
+ int nShapeType, nEntities, nVertices, nParts, *panParts, i, iPart, j;
69
+ double *padVertices, adBounds[4];
70
+ const char *pszPlus;
71
+ DBFFieldType idfld_type;
72
+ SHPObject *psCShape;
73
+ FILE *ifp = NULL;
74
+ int idfld, nflds;
75
+ char kv[257] = "";
76
+ char idfldName[120] = "";
77
+ char fldName[120] = "";
78
+ char shpFileName[120] = "";
79
+ char dbfFileName[120] = "";
80
+ char prjFileName[120] = "";
81
+ char parg[80];
82
+ double apeture[4];
83
+ int inarg, outarg;
84
+ char *DBFRow = NULL;
85
+
86
+ /* for testing only
87
+ char *in_args[] = { "init=nad83:1002", "units=us-ft" };
88
+ char *out_args[] = { "proj=utm", "zone=16", "units=m" };
89
+ */
90
+
91
+ char *in_args[16];
92
+ char *out_args[16];
93
+ int in_argc = 0 , out_argc = 0, outf_arg;
94
+ char *arglst;
95
+ projPJ orig_prj, new_prj;
96
+ va_list myargs, moargs;
97
+
98
+ if( argc < 4)
99
+ {
100
+ printf( "shpproj shp_file new_shp ( -i=in_proj_file | -i=\"in_params\" | -i=geographic ) ( -o=out_info_file | -o=\"out_params\" | -o=geographic ) \n" );
101
+ exit( 1 );
102
+ }
103
+
104
+ old_SHP = SHPOpen( argv[1], "rb" );
105
+ old_DBF = DBFOpen( argv[1], "rb" );
106
+ if( old_SHP == NULL || old_DBF == NULL )
107
+ {
108
+ printf( "Unable to open old files:%s\n", argv[1] );
109
+ exit( 1 );
110
+ }
111
+
112
+ outf_arg = 2;
113
+ inarg = 0;
114
+ outarg = 0;
115
+ for ( i = 3; i < argc; i++ ) {
116
+ if ( !strncmp ("-i=", argv[i], 3 )) inarg = i;
117
+ if ( !strncmp ("-o=", argv[i], 3 )) outarg = i;
118
+ }
119
+
120
+
121
+ /* if shapefile has a prj component then use that
122
+ else try for a file then read args as list */
123
+
124
+ if( inarg == 0 )
125
+ {
126
+ strcpy( prjFileName, argv[1] );
127
+ ifp = fopen( asFileName ( prjFileName, "prj" ),"rt");
128
+ }
129
+ else
130
+ {
131
+ ifp = fopen( asFileName ( argv[inarg] + 3, "prj" ),"rt");
132
+ }
133
+
134
+ i = 0;
135
+ if ( ifp ) {
136
+ if( inarg == 0 )
137
+ printf ("using default file proj params from <- %s\n",
138
+ asFileName ( prjFileName, "prj" ) );
139
+ else
140
+ printf ("using file proj params from <- %s\n",
141
+ asFileName ( argv[inarg] + 3, "prj" ) );
142
+
143
+ while( fscanf( ifp, "%s", parg) != EOF ) {
144
+ in_args[i] = malloc ( strlen(parg)+1 );
145
+ strcpy ( in_args[i], parg);
146
+ i++;
147
+ }
148
+
149
+ in_argc = i;
150
+ fclose (ifp);
151
+ }
152
+ else {
153
+ if ( inarg > 0 ) {
154
+ arglst = argv[inarg] + 3;
155
+ j = 0;
156
+ i = 0;
157
+ while ( j < strlen (arglst) ) {
158
+ in_argc += sscanf ( arglst + j, "%s", parg);
159
+
160
+ in_args[i] = malloc( strlen (parg)+1);
161
+ strcpy (in_args[i], parg);
162
+ i++;
163
+ j += strlen (parg) +1;
164
+ if ( arglst[j] + 1 == 0 ) j = strlen (argv[inarg]);
165
+ }
166
+ }
167
+ }
168
+
169
+ i = 0;
170
+ if ( outarg > 0 ) ifp = fopen( asFileName ( argv[outarg] + 3, "prj" ),"rt");
171
+ if ( ifp ) {
172
+ while( fscanf( ifp, "%s", parg) != EOF ) {
173
+ out_args[i] = malloc ( strlen(parg));
174
+ strcpy ( out_args[i], parg);
175
+ i++;
176
+ }
177
+ out_argc = i;
178
+ fclose (ifp);
179
+ }
180
+ else {
181
+ if ( outarg > 0 ) {
182
+ arglst = argv[outarg] + 3;
183
+ j = 0;
184
+ i = 0;
185
+ while ( j < strlen (arglst) ) {
186
+ out_argc += sscanf ( arglst + j, "%s", parg);
187
+
188
+ out_args[i] = malloc( strlen (parg)+1);
189
+ strcpy (out_args[i], parg);
190
+ i++;
191
+ j += strlen (parg) +1;
192
+ if ( arglst[j] + 1 == 0 ) j = strlen (argv[outarg]);
193
+ }
194
+ }
195
+ }
196
+
197
+ if ( !strcmp( argv[inarg], "-i=geographic" )) in_argc = 0;
198
+ if ( !strcmp( argv[outarg], "-o=geographic" )) out_argc = 0;
199
+
200
+ orig_prj = SHPSetProjection ( in_argc, in_args );
201
+ new_prj = SHPSetProjection ( out_argc, out_args );
202
+
203
+ if ( !(( (!in_argc) || orig_prj) && ( (!out_argc) || new_prj) )) {
204
+ fprintf (stderr, "unable to process projection, exiting...\n");
205
+ exit(1);
206
+ }
207
+
208
+
209
+ SHPGetInfo( old_SHP, &nEntities, &nShapeType, NULL, NULL);
210
+ new_SHP = SHPCreate ( argv[outf_arg], nShapeType );
211
+
212
+ new_DBF = DBFCloneEmpty (old_DBF, argv[outf_arg]);
213
+ if( new_SHP == NULL || new_DBF == NULL )
214
+ {
215
+ printf( "Unable to create new files:%s\n", argv[outf_arg] );
216
+ exit( 1 );
217
+ }
218
+
219
+ DBFRow = (char *) malloc ( (old_DBF->nRecordLength) + 15 );
220
+
221
+ for( i = 0; i < nEntities; i++ )
222
+ {
223
+ int j;
224
+
225
+ psCShape = SHPReadObject ( old_SHP, i );
226
+
227
+ SHPProject (psCShape, orig_prj, new_prj );
228
+
229
+ SHPWriteObject ( new_SHP, -1, psCShape );
230
+ SHPDestroyObject ( psCShape );
231
+
232
+ memcpy ( DBFRow, DBFReadTuple ( old_DBF, i ), old_DBF->nRecordLength );
233
+ DBFWriteTuple ( new_DBF, new_DBF->nRecords, DBFRow );
234
+
235
+ }
236
+
237
+ SHPFreeProjection ( orig_prj );
238
+ SHPFreeProjection ( new_prj );
239
+
240
+ /* store projection params into prj file */
241
+ ifp = fopen( asFileName ( argv[outf_arg], "prj" ),"wt");
242
+ if ( ifp ) {
243
+
244
+ if ( out_argc == 0 )
245
+ { fprintf( ifp, "proj=geographic\n" ); }
246
+ else
247
+ { for ( i = 0; i < out_argc; i++ )
248
+ fprintf( ifp, "%s\n", out_args[i]);
249
+ }
250
+ fclose (ifp);
251
+ }
252
+
253
+ SHPClose( old_SHP );
254
+ SHPClose( new_SHP );
255
+ DBFClose( old_DBF );
256
+ DBFClose( new_DBF );
257
+ printf ("\n");
258
+ }
259
+
260
+