geo_coder 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +12 -0
- data/Gemfile.lock +32 -0
- data/History.txt +6 -0
- data/Makefile +13 -0
- data/Manifest.txt +18 -0
- data/README.rdoc +197 -0
- data/Rakefile +53 -0
- data/TODO.txt +8 -0
- data/VERSION +1 -0
- data/bin/build_indexes +8 -0
- data/bin/rebuild_cluster +22 -0
- data/bin/rebuild_metaphones +23 -0
- data/bin/tiger_import +59 -0
- data/demos/demo/app/ext/geocodewrap.rb +84 -0
- data/demos/demo/app/views/index.builder +13 -0
- data/demos/demo/app/views/index.erb +71 -0
- data/demos/demo/config.ru +12 -0
- data/demos/demo/config/bootstraps.rb +130 -0
- data/demos/demo/config/geoenvironment.rb +25 -0
- data/demos/demo/geocoder_helper.rb +12 -0
- data/demos/demo/geocom_geocode.rb +10 -0
- data/demos/demo/main.rb +3 -0
- data/demos/demo/rakefile.rb +17 -0
- data/demos/demo/tmp/restart.txt +0 -0
- data/demos/simpledemo/views/index.builder +13 -0
- data/demos/simpledemo/views/index.erb +69 -0
- data/demos/simpledemo/ws.rb +83 -0
- data/doc/Makefile +7 -0
- data/doc/html4css1.css +279 -0
- data/doc/lookup.rst +193 -0
- data/doc/parsing.rst +125 -0
- data/doc/voidspace.css +147 -0
- data/geo_coder.gemspec +172 -0
- data/lib/geocoder/us.rb +21 -0
- data/lib/geocoder/us/address.rb +290 -0
- data/lib/geocoder/us/constants.rb +670 -0
- data/lib/geocoder/us/database.rb +745 -0
- data/lib/geocoder/us/import.rb +181 -0
- data/lib/geocoder/us/import/tiger.rb +13 -0
- data/lib/geocoder/us/numbers.rb +58 -0
- data/navteq/README +4 -0
- data/navteq/convert.sql +37 -0
- data/navteq/navteq_import +39 -0
- data/navteq/prepare.sql +92 -0
- data/sql/cluster.sql +16 -0
- data/sql/convert.sql +80 -0
- data/sql/create.sql +37 -0
- data/sql/index.sql +12 -0
- data/sql/place.csv +104944 -0
- data/sql/place.sql +104948 -0
- data/sql/setup.sql +78 -0
- data/src/Makefile +13 -0
- data/src/README +14 -0
- data/src/liblwgeom/Makefile +75 -0
- data/src/liblwgeom/box2d.c +54 -0
- data/src/liblwgeom/lex.yy.c +4799 -0
- data/src/liblwgeom/liblwgeom.h +1405 -0
- data/src/liblwgeom/lwalgorithm.c +946 -0
- data/src/liblwgeom/lwalgorithm.h +52 -0
- data/src/liblwgeom/lwcircstring.c +759 -0
- data/src/liblwgeom/lwcollection.c +541 -0
- data/src/liblwgeom/lwcompound.c +118 -0
- data/src/liblwgeom/lwcurvepoly.c +86 -0
- data/src/liblwgeom/lwgeom.c +886 -0
- data/src/liblwgeom/lwgeom_api.c +2201 -0
- data/src/liblwgeom/lwgparse.c +1219 -0
- data/src/liblwgeom/lwgunparse.c +1054 -0
- data/src/liblwgeom/lwline.c +525 -0
- data/src/liblwgeom/lwmcurve.c +125 -0
- data/src/liblwgeom/lwmline.c +137 -0
- data/src/liblwgeom/lwmpoint.c +138 -0
- data/src/liblwgeom/lwmpoly.c +141 -0
- data/src/liblwgeom/lwmsurface.c +129 -0
- data/src/liblwgeom/lwpoint.c +439 -0
- data/src/liblwgeom/lwpoly.c +579 -0
- data/src/liblwgeom/lwsegmentize.c +1047 -0
- data/src/liblwgeom/lwutil.c +369 -0
- data/src/liblwgeom/measures.c +861 -0
- data/src/liblwgeom/postgis_config.h +93 -0
- data/src/liblwgeom/ptarray.c +847 -0
- data/src/liblwgeom/vsprintf.c +179 -0
- data/src/liblwgeom/wktparse.h +126 -0
- data/src/liblwgeom/wktparse.lex +74 -0
- data/src/liblwgeom/wktparse.tab.c +2353 -0
- data/src/liblwgeom/wktparse.tab.h +145 -0
- data/src/liblwgeom/wktparse.y +385 -0
- data/src/libsqlite3_geocoder/Makefile +22 -0
- data/src/libsqlite3_geocoder/Makefile.nix +15 -0
- data/src/libsqlite3_geocoder/Makefile.redhat +15 -0
- data/src/libsqlite3_geocoder/extension.c +121 -0
- data/src/libsqlite3_geocoder/extension.h +13 -0
- data/src/libsqlite3_geocoder/levenshtein.c +42 -0
- data/src/libsqlite3_geocoder/metaphon.c +278 -0
- data/src/libsqlite3_geocoder/util.c +37 -0
- data/src/libsqlite3_geocoder/wkb_compress.c +54 -0
- data/src/metaphone/Makefile +7 -0
- data/src/metaphone/README +49 -0
- data/src/metaphone/extension.c +37 -0
- data/src/metaphone/metaphon.c +251 -0
- data/src/shp2sqlite/Makefile +37 -0
- data/src/shp2sqlite/Makefile.nix +36 -0
- data/src/shp2sqlite/Makefile.redhat +35 -0
- data/src/shp2sqlite/dbfopen.c +1595 -0
- data/src/shp2sqlite/getopt.c +695 -0
- data/src/shp2sqlite/getopt.h +127 -0
- data/src/shp2sqlite/shapefil.h +500 -0
- data/src/shp2sqlite/shp2sqlite.c +1974 -0
- data/src/shp2sqlite/shpopen.c +1894 -0
- data/tests/address.rb +236 -0
- data/tests/benchmark.rb +20 -0
- data/tests/constants.rb +57 -0
- data/tests/data/address-sample.csv +52 -0
- data/tests/data/db-test.csv +57 -0
- data/tests/data/locations.csv +4 -0
- data/tests/database.rb +137 -0
- data/tests/generate.rb +34 -0
- data/tests/numbers.rb +46 -0
- data/tests/run.rb +11 -0
- metadata +237 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* Declarations for getopt.
|
|
2
|
+
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software; you can redistribute it and/or modify it
|
|
5
|
+
under the terms of the GNU General Public License as published by the
|
|
6
|
+
Free Software Foundation; either version 2, or (at your option) any
|
|
7
|
+
later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program; if not, write to the Free Software
|
|
16
|
+
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
17
|
+
|
|
18
|
+
#ifndef _GETOPT_H
|
|
19
|
+
#define _GETOPT_H 1
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
/* For communication from `getopt' to the caller.
|
|
26
|
+
When `getopt' finds an option that takes an argument,
|
|
27
|
+
the argument value is returned here.
|
|
28
|
+
Also, when `ordering' is RETURN_IN_ORDER,
|
|
29
|
+
each non-option ARGV-element is returned here. */
|
|
30
|
+
|
|
31
|
+
extern char *optarg;
|
|
32
|
+
|
|
33
|
+
/* Index in ARGV of the next element to be scanned.
|
|
34
|
+
This is used for communication to and from the caller
|
|
35
|
+
and for communication between successive calls to `getopt'.
|
|
36
|
+
|
|
37
|
+
On entry to `getopt', zero means this is the first call; initialize.
|
|
38
|
+
|
|
39
|
+
When `getopt' returns EOF, this is the index of the first of the
|
|
40
|
+
non-option elements that the caller should itself scan.
|
|
41
|
+
|
|
42
|
+
Otherwise, `optind' communicates from one call to the next
|
|
43
|
+
how much of ARGV has been scanned so far. */
|
|
44
|
+
|
|
45
|
+
extern int optind;
|
|
46
|
+
|
|
47
|
+
/* Callers store zero here to inhibit the error message `getopt' prints
|
|
48
|
+
for unrecognized options. */
|
|
49
|
+
|
|
50
|
+
extern int opterr;
|
|
51
|
+
|
|
52
|
+
/* Set to an option character which was unrecognized. */
|
|
53
|
+
|
|
54
|
+
extern int optopt;
|
|
55
|
+
|
|
56
|
+
/* Describe the long-named options requested by the application.
|
|
57
|
+
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
|
58
|
+
of `struct option' terminated by an element containing a name which is
|
|
59
|
+
zero.
|
|
60
|
+
|
|
61
|
+
The field `has_arg' is:
|
|
62
|
+
no_argument (or 0) if the option does not take an argument,
|
|
63
|
+
required_argument (or 1) if the option requires an argument,
|
|
64
|
+
optional_argument (or 2) if the option takes an optional argument.
|
|
65
|
+
|
|
66
|
+
If the field `flag' is not NULL, it points to a variable that is set
|
|
67
|
+
to the value given in the field `val' when the option is found, but
|
|
68
|
+
left unchanged if the option is not found.
|
|
69
|
+
|
|
70
|
+
To have a long-named option do something other than set an `int' to
|
|
71
|
+
a compiled-in constant, such as set a value from `optarg', set the
|
|
72
|
+
option's `flag' field to zero and its `val' field to a nonzero
|
|
73
|
+
value (the equivalent single-letter option character, if there is
|
|
74
|
+
one). For long options that have a zero `flag' field, `getopt'
|
|
75
|
+
returns the contents of the `val' field. */
|
|
76
|
+
|
|
77
|
+
struct option
|
|
78
|
+
{
|
|
79
|
+
#if __STDC__
|
|
80
|
+
const char *name;
|
|
81
|
+
#else
|
|
82
|
+
char *name;
|
|
83
|
+
#endif
|
|
84
|
+
/* has_arg can't be an enum because some compilers complain about
|
|
85
|
+
type mismatches in all the code that assumes it is an int. */
|
|
86
|
+
int has_arg;
|
|
87
|
+
int *flag;
|
|
88
|
+
int val;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/* Names for the values of the `has_arg' field of `struct option'. */
|
|
92
|
+
|
|
93
|
+
#define no_argument 0
|
|
94
|
+
#define required_argument 1
|
|
95
|
+
#define optional_argument 2
|
|
96
|
+
|
|
97
|
+
#if __STDC__ || defined(PROTO)
|
|
98
|
+
#if defined(__GNU_LIBRARY__)
|
|
99
|
+
/* Many other libraries have conflicting prototypes for getopt, with
|
|
100
|
+
differences in the consts, in stdlib.h. To avoid compilation
|
|
101
|
+
errors, only prototype getopt for the GNU C library. */
|
|
102
|
+
extern int pgis_getopt (int argc, char *const *argv, const char *shortopts);
|
|
103
|
+
#endif /* not __GNU_LIBRARY__ */
|
|
104
|
+
extern int pgis_getopt_long (int argc, char *const *argv, const char *shortopts,
|
|
105
|
+
const struct option *longopts, int *longind);
|
|
106
|
+
extern int pgis_getopt_long_only (int argc, char *const *argv,
|
|
107
|
+
const char *shortopts,
|
|
108
|
+
const struct option *longopts, int *longind);
|
|
109
|
+
|
|
110
|
+
/* Internal only. Users should not call this directly. */
|
|
111
|
+
extern int _pgis_getopt_internal (int argc, char *const *argv,
|
|
112
|
+
const char *shortopts,
|
|
113
|
+
const struct option *longopts, int *longind,
|
|
114
|
+
int long_only);
|
|
115
|
+
#else /* not __STDC__ */
|
|
116
|
+
extern int pgis_getopt ();
|
|
117
|
+
extern int pgis_getopt_long ();
|
|
118
|
+
extern int pgis_getopt_long_only ();
|
|
119
|
+
|
|
120
|
+
extern int _pgis_getopt_internal ();
|
|
121
|
+
#endif /* not __STDC__ */
|
|
122
|
+
|
|
123
|
+
#ifdef __cplusplus
|
|
124
|
+
}
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
#endif /* _GETOPT_H */
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
#ifndef _SHAPEFILE_H_INCLUDED
|
|
2
|
+
#define _SHAPEFILE_H_INCLUDED
|
|
3
|
+
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
* $Id: shapefil.h 2785 2008-05-27 15:08:20Z mcayland $
|
|
6
|
+
*
|
|
7
|
+
* Project: Shapelib
|
|
8
|
+
* Purpose: Primary include file for Shapelib.
|
|
9
|
+
* Author: Frank Warmerdam, warmerdam@pobox.com
|
|
10
|
+
*
|
|
11
|
+
******************************************************************************
|
|
12
|
+
* Copyright (c) 1999, Frank Warmerdam
|
|
13
|
+
*
|
|
14
|
+
* This software is available under the following "MIT Style" license,
|
|
15
|
+
* or at the option of the licensee under the LGPL (see LICENSE.LGPL). This
|
|
16
|
+
* option is discussed in more detail in shapelib.html.
|
|
17
|
+
*
|
|
18
|
+
* --
|
|
19
|
+
*
|
|
20
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
21
|
+
* copy of this software and associated documentation files (the "Software"),
|
|
22
|
+
* to deal in the Software without restriction, including without limitation
|
|
23
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
24
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
25
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
26
|
+
*
|
|
27
|
+
* The above copyright notice and this permission notice shall be included
|
|
28
|
+
* in all copies or substantial portions of the Software.
|
|
29
|
+
*
|
|
30
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
31
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
33
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
35
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
36
|
+
* DEALINGS IN THE SOFTWARE.
|
|
37
|
+
******************************************************************************
|
|
38
|
+
*
|
|
39
|
+
* $Log$
|
|
40
|
+
* Revision 1.5 2006/01/16 10:42:58 strk
|
|
41
|
+
* Added support for Bool and Date DBF<=>PGIS mapping
|
|
42
|
+
*
|
|
43
|
+
* Revision 1.4 2003/12/01 20:52:00 strk
|
|
44
|
+
* shapelib put in sync with gdal cvs
|
|
45
|
+
*
|
|
46
|
+
* Revision 1.27 2003/04/21 18:30:37 warmerda
|
|
47
|
+
* added header write/update public methods
|
|
48
|
+
*
|
|
49
|
+
* Revision 1.26 2002/09/29 00:00:08 warmerda
|
|
50
|
+
* added FTLogical and logical attribute read/write calls
|
|
51
|
+
*
|
|
52
|
+
* Revision 1.25 2002/05/07 13:46:30 warmerda
|
|
53
|
+
* added DBFWriteAttributeDirectly().
|
|
54
|
+
*
|
|
55
|
+
* Revision 1.24 2002/04/10 16:59:54 warmerda
|
|
56
|
+
* added SHPRewindObject
|
|
57
|
+
*
|
|
58
|
+
* Revision 1.23 2002/01/15 14:36:07 warmerda
|
|
59
|
+
* updated email address
|
|
60
|
+
*
|
|
61
|
+
* Revision 1.22 2002/01/15 14:32:00 warmerda
|
|
62
|
+
* try to improve SHPAPI_CALL docs
|
|
63
|
+
*
|
|
64
|
+
* Revision 1.21 2001/11/01 16:29:55 warmerda
|
|
65
|
+
* move pabyRec into SHPInfo for thread safety
|
|
66
|
+
*
|
|
67
|
+
* Revision 1.20 2001/07/20 13:06:02 warmerda
|
|
68
|
+
* fixed SHPAPI attribute for SHPTreeFindLikelyShapes
|
|
69
|
+
*
|
|
70
|
+
* Revision 1.19 2001/05/31 19:20:13 warmerda
|
|
71
|
+
* added DBFGetFieldIndex()
|
|
72
|
+
*
|
|
73
|
+
* Revision 1.18 2001/05/31 18:15:40 warmerda
|
|
74
|
+
* Added support for NULL fields in DBF files
|
|
75
|
+
*
|
|
76
|
+
* Revision 1.17 2001/05/23 13:36:52 warmerda
|
|
77
|
+
* added use of SHPAPI_CALL
|
|
78
|
+
*
|
|
79
|
+
* Revision 1.16 2000/09/25 14:15:59 warmerda
|
|
80
|
+
* added DBFGetNativeFieldType()
|
|
81
|
+
*
|
|
82
|
+
* Revision 1.15 2000/02/16 16:03:51 warmerda
|
|
83
|
+
* added null shape support
|
|
84
|
+
*
|
|
85
|
+
* Revision 1.14 1999/11/05 14:12:05 warmerda
|
|
86
|
+
* updated license terms
|
|
87
|
+
*
|
|
88
|
+
* Revision 1.13 1999/06/02 18:24:21 warmerda
|
|
89
|
+
* added trimming code
|
|
90
|
+
*
|
|
91
|
+
* Revision 1.12 1999/06/02 17:56:12 warmerda
|
|
92
|
+
* added quad'' subnode support for trees
|
|
93
|
+
*
|
|
94
|
+
* Revision 1.11 1999/05/18 19:11:11 warmerda
|
|
95
|
+
* Added example searching capability
|
|
96
|
+
*
|
|
97
|
+
* Revision 1.10 1999/05/18 17:49:38 warmerda
|
|
98
|
+
* added initial quadtree support
|
|
99
|
+
*
|
|
100
|
+
* Revision 1.9 1999/05/11 03:19:28 warmerda
|
|
101
|
+
* added new Tuple api, and improved extension handling - add from candrsn
|
|
102
|
+
*
|
|
103
|
+
* Revision 1.8 1999/03/23 17:22:27 warmerda
|
|
104
|
+
* Added extern "C" protection for C++ users of shapefil.h.
|
|
105
|
+
*
|
|
106
|
+
* Revision 1.7 1998/12/31 15:31:07 warmerda
|
|
107
|
+
* Added the TRIM_DBF_WHITESPACE and DISABLE_MULTIPATCH_MEASURE options.
|
|
108
|
+
*
|
|
109
|
+
* Revision 1.6 1998/12/03 15:48:15 warmerda
|
|
110
|
+
* Added SHPCalculateExtents().
|
|
111
|
+
*
|
|
112
|
+
* Revision 1.5 1998/11/09 20:57:16 warmerda
|
|
113
|
+
* Altered SHPGetInfo() call.
|
|
114
|
+
*
|
|
115
|
+
* Revision 1.4 1998/11/09 20:19:33 warmerda
|
|
116
|
+
* Added 3D support, and use of SHPObject.
|
|
117
|
+
*
|
|
118
|
+
* Revision 1.3 1995/08/23 02:24:05 warmerda
|
|
119
|
+
* Added support for reading bounds.
|
|
120
|
+
*
|
|
121
|
+
* Revision 1.2 1995/08/04 03:17:39 warmerda
|
|
122
|
+
* Added header.
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
#include <stdio.h>
|
|
127
|
+
|
|
128
|
+
#ifdef USE_DBMALLOC
|
|
129
|
+
#include <dbmalloc.h>
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
#ifdef __cplusplus
|
|
133
|
+
extern "C" {
|
|
134
|
+
#endif
|
|
135
|
+
|
|
136
|
+
/************************************************************************/
|
|
137
|
+
/* Configuration options. */
|
|
138
|
+
/************************************************************************/
|
|
139
|
+
|
|
140
|
+
/* -------------------------------------------------------------------- */
|
|
141
|
+
/* Should the DBFReadStringAttribute() strip leading and */
|
|
142
|
+
/* trailing white space? */
|
|
143
|
+
/* -------------------------------------------------------------------- */
|
|
144
|
+
#define TRIM_DBF_WHITESPACE
|
|
145
|
+
|
|
146
|
+
/* -------------------------------------------------------------------- */
|
|
147
|
+
/* Should we write measure values to the Multipatch object? */
|
|
148
|
+
/* Reportedly ArcView crashes if we do write it, so for now it */
|
|
149
|
+
/* is disabled. */
|
|
150
|
+
/* -------------------------------------------------------------------- */
|
|
151
|
+
#define DISABLE_MULTIPATCH_MEASURE
|
|
152
|
+
|
|
153
|
+
/* -------------------------------------------------------------------- */
|
|
154
|
+
/* SHPAPI_CALL */
|
|
155
|
+
/* */
|
|
156
|
+
/* The following two macros are present to allow forcing */
|
|
157
|
+
/* various calling conventions on the Shapelib API. */
|
|
158
|
+
/* */
|
|
159
|
+
/* To force __stdcall conventions (needed to call Shapelib */
|
|
160
|
+
/* from Visual Basic and/or Dephi I believe) the makefile could */
|
|
161
|
+
/* be modified to define: */
|
|
162
|
+
/* */
|
|
163
|
+
/* /DSHPAPI_CALL=__stdcall */
|
|
164
|
+
/* */
|
|
165
|
+
/* If it is desired to force export of the Shapelib API without */
|
|
166
|
+
/* using the shapelib.def file, use the following definition. */
|
|
167
|
+
/* */
|
|
168
|
+
/* /DSHAPELIB_DLLEXPORT */
|
|
169
|
+
/* */
|
|
170
|
+
/* To get both at once it will be necessary to hack this */
|
|
171
|
+
/* include file to define: */
|
|
172
|
+
/* */
|
|
173
|
+
/* #define SHPAPI_CALL __declspec(dllexport) __stdcall */
|
|
174
|
+
/* #define SHPAPI_CALL1 __declspec(dllexport) * __stdcall */
|
|
175
|
+
/* */
|
|
176
|
+
/* The complexity of the situtation is partly caused by the */
|
|
177
|
+
/* peculiar requirement of Visual C++ that __stdcall appear */
|
|
178
|
+
/* after any "*"'s in the return value of a function while the */
|
|
179
|
+
/* __declspec(dllexport) must appear before them. */
|
|
180
|
+
/* -------------------------------------------------------------------- */
|
|
181
|
+
|
|
182
|
+
#ifdef SHAPELIB_DLLEXPORT
|
|
183
|
+
# define SHPAPI_CALL __declspec(dllexport)
|
|
184
|
+
# define SHPAPI_CALL1(x) __declspec(dllexport) x
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
#ifndef SHPAPI_CALL
|
|
188
|
+
# define SHPAPI_CALL
|
|
189
|
+
#endif
|
|
190
|
+
|
|
191
|
+
#ifndef SHPAPI_CALL1
|
|
192
|
+
# define SHPAPI_CALL1(x) x SHPAPI_CALL
|
|
193
|
+
#endif
|
|
194
|
+
|
|
195
|
+
/************************************************************************/
|
|
196
|
+
/* SHP Support. */
|
|
197
|
+
/************************************************************************/
|
|
198
|
+
typedef struct
|
|
199
|
+
{
|
|
200
|
+
FILE *fpSHP;
|
|
201
|
+
FILE *fpSHX;
|
|
202
|
+
|
|
203
|
+
int nShapeType; /* SHPT_* */
|
|
204
|
+
|
|
205
|
+
int nFileSize; /* SHP file */
|
|
206
|
+
|
|
207
|
+
int nRecords;
|
|
208
|
+
int nMaxRecords;
|
|
209
|
+
int *panRecOffset;
|
|
210
|
+
int *panRecSize;
|
|
211
|
+
|
|
212
|
+
double adBoundsMin[4];
|
|
213
|
+
double adBoundsMax[4];
|
|
214
|
+
|
|
215
|
+
int bUpdated;
|
|
216
|
+
|
|
217
|
+
unsigned char *pabyRec;
|
|
218
|
+
int nBufSize;
|
|
219
|
+
} SHPInfo;
|
|
220
|
+
|
|
221
|
+
typedef SHPInfo * SHPHandle;
|
|
222
|
+
|
|
223
|
+
/* -------------------------------------------------------------------- */
|
|
224
|
+
/* Shape types (nSHPType) */
|
|
225
|
+
/* -------------------------------------------------------------------- */
|
|
226
|
+
#define SHPT_NULL 0
|
|
227
|
+
#define SHPT_POINT 1
|
|
228
|
+
#define SHPT_ARC 3
|
|
229
|
+
#define SHPT_POLYGON 5
|
|
230
|
+
#define SHPT_MULTIPOINT 8
|
|
231
|
+
#define SHPT_POINTZ 11
|
|
232
|
+
#define SHPT_ARCZ 13
|
|
233
|
+
#define SHPT_POLYGONZ 15
|
|
234
|
+
#define SHPT_MULTIPOINTZ 18
|
|
235
|
+
#define SHPT_POINTM 21
|
|
236
|
+
#define SHPT_ARCM 23
|
|
237
|
+
#define SHPT_POLYGONM 25
|
|
238
|
+
#define SHPT_MULTIPOINTM 28
|
|
239
|
+
#define SHPT_MULTIPATCH 31
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
/* -------------------------------------------------------------------- */
|
|
243
|
+
/* Part types - everything but SHPT_MULTIPATCH just uses */
|
|
244
|
+
/* SHPP_RING. */
|
|
245
|
+
/* -------------------------------------------------------------------- */
|
|
246
|
+
|
|
247
|
+
#define SHPP_TRISTRIP 0
|
|
248
|
+
#define SHPP_TRIFAN 1
|
|
249
|
+
#define SHPP_OUTERRING 2
|
|
250
|
+
#define SHPP_INNERRING 3
|
|
251
|
+
#define SHPP_FIRSTRING 4
|
|
252
|
+
#define SHPP_RING 5
|
|
253
|
+
|
|
254
|
+
/* -------------------------------------------------------------------- */
|
|
255
|
+
/* SHPObject - represents on shape (without attributes) read */
|
|
256
|
+
/* from the .shp file. */
|
|
257
|
+
/* -------------------------------------------------------------------- */
|
|
258
|
+
typedef struct
|
|
259
|
+
{
|
|
260
|
+
int nSHPType;
|
|
261
|
+
|
|
262
|
+
int nShapeId; /* -1 is unknown/unassigned */
|
|
263
|
+
|
|
264
|
+
int nParts;
|
|
265
|
+
int *panPartStart;
|
|
266
|
+
int *panPartType;
|
|
267
|
+
|
|
268
|
+
int nVertices;
|
|
269
|
+
double *padfX;
|
|
270
|
+
double *padfY;
|
|
271
|
+
double *padfZ;
|
|
272
|
+
double *padfM;
|
|
273
|
+
|
|
274
|
+
double dfXMin;
|
|
275
|
+
double dfYMin;
|
|
276
|
+
double dfZMin;
|
|
277
|
+
double dfMMin;
|
|
278
|
+
|
|
279
|
+
double dfXMax;
|
|
280
|
+
double dfYMax;
|
|
281
|
+
double dfZMax;
|
|
282
|
+
double dfMMax;
|
|
283
|
+
} SHPObject;
|
|
284
|
+
|
|
285
|
+
/* -------------------------------------------------------------------- */
|
|
286
|
+
/* SHP API Prototypes */
|
|
287
|
+
/* -------------------------------------------------------------------- */
|
|
288
|
+
SHPHandle SHPAPI_CALL
|
|
289
|
+
SHPOpen( const char * pszShapeFile, const char * pszAccess );
|
|
290
|
+
SHPHandle SHPAPI_CALL
|
|
291
|
+
SHPCreate( const char * pszShapeFile, int nShapeType );
|
|
292
|
+
void SHPAPI_CALL
|
|
293
|
+
SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
|
|
294
|
+
double * padfMinBound, double * padfMaxBound );
|
|
295
|
+
|
|
296
|
+
SHPObject SHPAPI_CALL1(*)
|
|
297
|
+
SHPReadObject( SHPHandle hSHP, int iShape );
|
|
298
|
+
int SHPAPI_CALL
|
|
299
|
+
SHPWriteObject( SHPHandle hSHP, int iShape, SHPObject * psObject );
|
|
300
|
+
|
|
301
|
+
void SHPAPI_CALL
|
|
302
|
+
SHPDestroyObject( SHPObject * psObject );
|
|
303
|
+
void SHPAPI_CALL
|
|
304
|
+
SHPComputeExtents( SHPObject * psObject );
|
|
305
|
+
SHPObject SHPAPI_CALL1(*)
|
|
306
|
+
SHPCreateObject( int nSHPType, int nShapeId,
|
|
307
|
+
int nParts, int * panPartStart, int * panPartType,
|
|
308
|
+
int nVertices, double * padfX, double * padfY,
|
|
309
|
+
double * padfZ, double * padfM );
|
|
310
|
+
SHPObject SHPAPI_CALL1(*)
|
|
311
|
+
SHPCreateSimpleObject( int nSHPType, int nVertices,
|
|
312
|
+
double * padfX, double * padfY, double * padfZ );
|
|
313
|
+
|
|
314
|
+
int SHPAPI_CALL
|
|
315
|
+
SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
|
|
316
|
+
|
|
317
|
+
void SHPAPI_CALL SHPClose( SHPHandle hSHP );
|
|
318
|
+
void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
|
|
319
|
+
|
|
320
|
+
const char SHPAPI_CALL1(*)
|
|
321
|
+
SHPTypeName( int nSHPType );
|
|
322
|
+
const char SHPAPI_CALL1(*)
|
|
323
|
+
SHPPartTypeName( int nPartType );
|
|
324
|
+
|
|
325
|
+
/* -------------------------------------------------------------------- */
|
|
326
|
+
/* Shape quadtree indexing API. */
|
|
327
|
+
/* -------------------------------------------------------------------- */
|
|
328
|
+
|
|
329
|
+
/* this can be two or four for binary or quad tree */
|
|
330
|
+
#define MAX_SUBNODE 4
|
|
331
|
+
|
|
332
|
+
typedef struct shape_tree_node
|
|
333
|
+
{
|
|
334
|
+
/* region covered by this node */
|
|
335
|
+
double adfBoundsMin[4];
|
|
336
|
+
double adfBoundsMax[4];
|
|
337
|
+
|
|
338
|
+
/* list of shapes stored at this node. The papsShapeObj pointers
|
|
339
|
+
or the whole list can be NULL */
|
|
340
|
+
int nShapeCount;
|
|
341
|
+
int *panShapeIds;
|
|
342
|
+
SHPObject **papsShapeObj;
|
|
343
|
+
|
|
344
|
+
int nSubNodes;
|
|
345
|
+
struct shape_tree_node *apsSubNode[MAX_SUBNODE];
|
|
346
|
+
|
|
347
|
+
} SHPTreeNode;
|
|
348
|
+
|
|
349
|
+
typedef struct
|
|
350
|
+
{
|
|
351
|
+
SHPHandle hSHP;
|
|
352
|
+
|
|
353
|
+
int nMaxDepth;
|
|
354
|
+
int nDimension;
|
|
355
|
+
|
|
356
|
+
SHPTreeNode *psRoot;
|
|
357
|
+
} SHPTree;
|
|
358
|
+
|
|
359
|
+
SHPTree SHPAPI_CALL1(*)
|
|
360
|
+
SHPCreateTree( SHPHandle hSHP, int nDimension, int nMaxDepth,
|
|
361
|
+
double *padfBoundsMin, double *padfBoundsMax );
|
|
362
|
+
void SHPAPI_CALL
|
|
363
|
+
SHPDestroyTree( SHPTree * hTree );
|
|
364
|
+
|
|
365
|
+
int SHPAPI_CALL
|
|
366
|
+
SHPWriteTree( SHPTree *hTree, const char * pszFilename );
|
|
367
|
+
SHPTree SHPAPI_CALL
|
|
368
|
+
SHPReadTree( const char * pszFilename );
|
|
369
|
+
|
|
370
|
+
int SHPAPI_CALL
|
|
371
|
+
SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
|
|
372
|
+
int SHPAPI_CALL
|
|
373
|
+
SHPTreeAddShapeId( SHPTree * hTree, SHPObject * psObject );
|
|
374
|
+
int SHPAPI_CALL
|
|
375
|
+
SHPTreeRemoveShapeId( SHPTree * hTree, int nShapeId );
|
|
376
|
+
|
|
377
|
+
void SHPAPI_CALL
|
|
378
|
+
SHPTreeTrimExtraNodes( SHPTree * hTree );
|
|
379
|
+
|
|
380
|
+
int SHPAPI_CALL1(*)
|
|
381
|
+
SHPTreeFindLikelyShapes( SHPTree * hTree,
|
|
382
|
+
double * padfBoundsMin,
|
|
383
|
+
double * padfBoundsMax,
|
|
384
|
+
int * );
|
|
385
|
+
int SHPAPI_CALL
|
|
386
|
+
SHPCheckBoundsOverlap( double *, double *, double *, double *, int );
|
|
387
|
+
|
|
388
|
+
/************************************************************************/
|
|
389
|
+
/* DBF Support. */
|
|
390
|
+
/************************************************************************/
|
|
391
|
+
typedef struct
|
|
392
|
+
{
|
|
393
|
+
FILE *fp;
|
|
394
|
+
|
|
395
|
+
int nRecords;
|
|
396
|
+
|
|
397
|
+
int nRecordLength;
|
|
398
|
+
int nHeaderLength;
|
|
399
|
+
int nFields;
|
|
400
|
+
int *panFieldOffset;
|
|
401
|
+
int *panFieldSize;
|
|
402
|
+
int *panFieldDecimals;
|
|
403
|
+
char *pachFieldType;
|
|
404
|
+
|
|
405
|
+
char *pszHeader;
|
|
406
|
+
|
|
407
|
+
int nCurrentRecord;
|
|
408
|
+
int bCurrentRecordModified;
|
|
409
|
+
char *pszCurrentRecord;
|
|
410
|
+
|
|
411
|
+
int bNoHeader;
|
|
412
|
+
int bUpdated;
|
|
413
|
+
} DBFInfo;
|
|
414
|
+
|
|
415
|
+
typedef DBFInfo * DBFHandle;
|
|
416
|
+
|
|
417
|
+
typedef enum {
|
|
418
|
+
FTString,
|
|
419
|
+
FTInteger,
|
|
420
|
+
FTDouble,
|
|
421
|
+
FTLogical,
|
|
422
|
+
FTInvalid,
|
|
423
|
+
FTDate
|
|
424
|
+
} DBFFieldType;
|
|
425
|
+
|
|
426
|
+
#define XBASE_FLDHDR_SZ 32
|
|
427
|
+
|
|
428
|
+
DBFHandle SHPAPI_CALL
|
|
429
|
+
DBFOpen( const char * pszDBFFile, const char * pszAccess );
|
|
430
|
+
DBFHandle SHPAPI_CALL
|
|
431
|
+
DBFCreate( const char * pszDBFFile );
|
|
432
|
+
|
|
433
|
+
int SHPAPI_CALL
|
|
434
|
+
DBFGetFieldCount( DBFHandle psDBF );
|
|
435
|
+
int SHPAPI_CALL
|
|
436
|
+
DBFGetRecordCount( DBFHandle psDBF );
|
|
437
|
+
int SHPAPI_CALL
|
|
438
|
+
DBFAddField( DBFHandle hDBF, const char * pszFieldName,
|
|
439
|
+
DBFFieldType eType, int nWidth, int nDecimals );
|
|
440
|
+
|
|
441
|
+
DBFFieldType SHPAPI_CALL
|
|
442
|
+
DBFGetFieldInfo( DBFHandle psDBF, int iField,
|
|
443
|
+
char * pszFieldName, int * pnWidth, int * pnDecimals );
|
|
444
|
+
|
|
445
|
+
int SHPAPI_CALL
|
|
446
|
+
DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName);
|
|
447
|
+
|
|
448
|
+
int SHPAPI_CALL
|
|
449
|
+
DBFReadIntegerAttribute( DBFHandle hDBF, int iShape, int iField );
|
|
450
|
+
double SHPAPI_CALL
|
|
451
|
+
DBFReadDoubleAttribute( DBFHandle hDBF, int iShape, int iField );
|
|
452
|
+
const char SHPAPI_CALL1(*)
|
|
453
|
+
DBFReadStringAttribute( DBFHandle hDBF, int iShape, int iField );
|
|
454
|
+
const char SHPAPI_CALL1(*)
|
|
455
|
+
DBFReadLogicalAttribute( DBFHandle hDBF, int iShape, int iField );
|
|
456
|
+
int SHPAPI_CALL
|
|
457
|
+
DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
|
|
458
|
+
|
|
459
|
+
int SHPAPI_CALL DBFReadSetup(DBFHandle psDBF, int hEntity);
|
|
460
|
+
|
|
461
|
+
int SHPAPI_CALL DBFReadDeleted(DBFHandle psDBF, int hEntity);
|
|
462
|
+
|
|
463
|
+
int SHPAPI_CALL
|
|
464
|
+
DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
|
|
465
|
+
int nFieldValue );
|
|
466
|
+
int SHPAPI_CALL
|
|
467
|
+
DBFWriteDoubleAttribute( DBFHandle hDBF, int iShape, int iField,
|
|
468
|
+
double dFieldValue );
|
|
469
|
+
int SHPAPI_CALL
|
|
470
|
+
DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField,
|
|
471
|
+
const char * pszFieldValue );
|
|
472
|
+
int SHPAPI_CALL
|
|
473
|
+
DBFWriteNULLAttribute( DBFHandle hDBF, int iShape, int iField );
|
|
474
|
+
|
|
475
|
+
int SHPAPI_CALL
|
|
476
|
+
DBFWriteLogicalAttribute( DBFHandle hDBF, int iShape, int iField,
|
|
477
|
+
const char lFieldValue);
|
|
478
|
+
int SHPAPI_CALL
|
|
479
|
+
DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
|
|
480
|
+
const void * pValue );
|
|
481
|
+
const char SHPAPI_CALL1(*)
|
|
482
|
+
DBFReadTuple(DBFHandle psDBF, int hEntity );
|
|
483
|
+
int SHPAPI_CALL
|
|
484
|
+
DBFWriteTuple(DBFHandle psDBF, int hEntity, void * pRawTuple );
|
|
485
|
+
|
|
486
|
+
DBFHandle SHPAPI_CALL
|
|
487
|
+
DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
|
|
488
|
+
|
|
489
|
+
void SHPAPI_CALL
|
|
490
|
+
DBFClose( DBFHandle hDBF );
|
|
491
|
+
void SHPAPI_CALL
|
|
492
|
+
DBFUpdateHeader( DBFHandle hDBF );
|
|
493
|
+
char SHPAPI_CALL
|
|
494
|
+
DBFGetNativeFieldType( DBFHandle hDBF, int iField );
|
|
495
|
+
|
|
496
|
+
#ifdef __cplusplus
|
|
497
|
+
}
|
|
498
|
+
#endif
|
|
499
|
+
|
|
500
|
+
#endif /* ndef _SHAPEFILE_H_INCLUDED */
|