56 |
56 |
*
|
57 |
57 |
* @param the number of lines in the coordinates arrays
|
58 |
58 |
************************************************************************/
|
59 |
|
static void WritePointsArray ( int nSHPType,
|
60 |
|
const char * pszFilename,
|
61 |
|
float min_pntx[40000][100],
|
62 |
|
float max_pntx[40000][100],
|
63 |
|
float min_pnty[40000][100],
|
64 |
|
float max_pnty[40000][100],
|
65 |
|
float pointz[40000][100],
|
66 |
|
vector<string> urlvec,
|
67 |
|
vector<string> docidvec,
|
68 |
|
int number_data_lines ) {
|
|
59 |
static void WritePointsArray(int nSHPType,
|
|
60 |
const char *pszFilename,
|
|
61 |
float min_pntx[40000][100],
|
|
62 |
float max_pntx[40000][100],
|
|
63 |
float min_pnty[40000][100],
|
|
64 |
float max_pnty[40000][100],
|
|
65 |
float pointz[40000][100],
|
|
66 |
vector < string > urlvec,
|
|
67 |
vector < string > docidvec,
|
|
68 |
int number_data_lines)
|
|
69 |
{
|
69 |
70 |
|
70 |
|
SHPHandle hSHPHandle;
|
71 |
|
SHPObject * psShape;
|
72 |
|
double x, y, z, m, j, dx[number_data_lines], dy[number_data_lines], dz[number_data_lines];
|
73 |
|
int ii, iRecord, i;
|
74 |
|
char buf[20];
|
75 |
|
char intString;
|
76 |
|
//for the dbf file
|
77 |
|
DBFHandle hDBF;
|
|
71 |
SHPHandle hSHPHandle;
|
|
72 |
SHPObject *psShape;
|
|
73 |
double x, y, z, m, j, dx[number_data_lines], dy[number_data_lines],
|
|
74 |
dz[number_data_lines];
|
|
75 |
int ii, iRecord, i;
|
|
76 |
char buf[20];
|
|
77 |
char intString;
|
|
78 |
//for the dbf file
|
|
79 |
DBFHandle hDBF;
|
78 |
80 |
|
79 |
|
//create the dbf file
|
80 |
|
hDBF = DBFCreate( pszFilename );
|
81 |
|
if ( hDBF == NULL )
|
82 |
|
{
|
83 |
|
printf( "DBFCreate(%s) failed.\n" );
|
84 |
|
exit( 2 );
|
85 |
|
}
|
|
81 |
//create the dbf file
|
|
82 |
hDBF = DBFCreate(pszFilename);
|
|
83 |
if (hDBF == NULL) {
|
|
84 |
printf("DBFCreate(%s) failed.\n");
|
|
85 |
exit(2);
|
|
86 |
}
|
|
87 |
//add to the dbf file attributes for ID, pval(elevation), url
|
|
88 |
if (DBFAddField(hDBF, "ID", FTInteger, 10, 0) == -1) {
|
|
89 |
printf("DBFAddField(%s,FTInteger,%d,0) failed.\n");
|
|
90 |
}
|
|
91 |
if (DBFAddField(hDBF, "area_coef", FTDouble, 10, 4) == -1) {
|
|
92 |
printf("DBFAddField(%s,FTDouble,%d,0) failed.\n");
|
|
93 |
}
|
|
94 |
if (DBFAddField(hDBF, "url", FTString, 220, 0) == -1) {
|
|
95 |
printf("DBFAddField(%s,FTString,%d,0) failed.\n");
|
|
96 |
}
|
|
97 |
if (DBFAddField(hDBF, "docid", FTString, 220, 0) == -1) {
|
|
98 |
printf("DBFAddField(%s,FTString,%d,0) failed.\n");
|
|
99 |
}
|
86 |
100 |
|
87 |
|
//add to the dbf file attributes for ID, pval(elevation), url
|
88 |
|
if ( DBFAddField( hDBF, "ID", FTInteger, 10, 0 ) == -1 )
|
89 |
|
{
|
90 |
|
printf( "DBFAddField(%s,FTInteger,%d,0) failed.\n" );
|
91 |
|
}
|
92 |
|
if ( DBFAddField( hDBF, "area_coef", FTDouble, 10, 4 ) == -1 )
|
93 |
|
{
|
94 |
|
printf( "DBFAddField(%s,FTDouble,%d,0) failed.\n" );
|
95 |
|
}
|
96 |
|
if ( DBFAddField( hDBF, "url", FTString, 220, 0 ) == -1 )
|
97 |
|
{
|
98 |
|
printf( "DBFAddField(%s,FTString,%d,0) failed.\n" );
|
99 |
|
}
|
100 |
|
if ( DBFAddField( hDBF, "docid", FTString, 220, 0 ) == -1 )
|
101 |
|
{
|
102 |
|
printf( "DBFAddField(%s,FTString,%d,0) failed.\n" );
|
103 |
|
}
|
|
101 |
//cout<<" DBF Record Count --> "<<iRecord<<endl;
|
|
102 |
int id_field = DBFGetFieldIndex(hDBF, "ID");
|
|
103 |
int url_field = DBFGetFieldIndex(hDBF, "url");
|
|
104 |
int docid_field = DBFGetFieldIndex(hDBF, "docid");
|
|
105 |
int area_field = DBFGetFieldIndex(hDBF, "area_coef");
|
104 |
106 |
|
|
107 |
hSHPHandle = SHPCreate(pszFilename, nSHPType);
|
105 |
108 |
|
106 |
|
//cout<<" DBF Record Count --> "<<iRecord<<endl;
|
107 |
|
int id_field = DBFGetFieldIndex( hDBF, "ID" );
|
108 |
|
int url_field = DBFGetFieldIndex( hDBF, "url" );
|
109 |
|
int docid_field = DBFGetFieldIndex( hDBF, "docid" );
|
110 |
|
int area_field = DBFGetFieldIndex( hDBF, "area_coef" );
|
|
109 |
ii = 0;
|
|
110 |
for (ii = 0; ii < number_data_lines; ii++) {
|
|
111 |
double area_coef =
|
|
112 |
sqrt(pow((max_pntx[2][ii] - min_pntx[2][ii]), 2) +
|
|
113 |
pow((max_pnty[2][ii] - min_pnty[2][ii]), 2));
|
|
114 |
double ave_x = ((min_pntx[2][ii] + max_pntx[2][ii]) / 2);
|
|
115 |
double ave_y = ((min_pnty[2][ii] + max_pnty[2][ii]) / 2);
|
|
116 |
double ave_z = (pointz[2][ii]);
|
111 |
117 |
|
112 |
|
hSHPHandle = SHPCreate( pszFilename, nSHPType );
|
|
118 |
if (ave_x < 180 && ave_x > -180 && ave_y < 90 && ave_y > -90) {
|
113 |
119 |
|
114 |
|
ii = 0;
|
115 |
|
for ( ii = 0; ii < number_data_lines; ii++ )
|
116 |
|
{
|
117 |
|
double area_coef = sqrt( pow((max_pntx[2][ii]-min_pntx[2][ii]),2) + pow((max_pnty[2][ii]-min_pnty[2][ii]),2) );
|
118 |
|
double ave_x = ( (min_pntx[2][ii]+max_pntx[2][ii])/2 );
|
119 |
|
double ave_y = ( (min_pnty[2][ii]+max_pnty[2][ii])/2 );
|
120 |
|
double ave_z = ( pointz[2][ii] );
|
|
120 |
psShape =
|
|
121 |
SHPCreateObject(SHPT_POINT, ii, 0, NULL, NULL, 1, &ave_x, &ave_y,
|
|
122 |
&ave_z, NULL);
|
121 |
123 |
|
122 |
|
if (ave_x < 180 && ave_x > -180 && ave_y < 90 && ave_y >-90 ) {
|
|
124 |
SHPWriteObject(hSHPHandle, -1, psShape);
|
|
125 |
SHPDestroyObject(psShape);
|
|
126 |
//do the update to the dbf file too
|
|
127 |
iRecord = DBFGetRecordCount(hDBF);
|
123 |
128 |
|
124 |
|
psShape = SHPCreateObject( SHPT_POINT, ii, 0, NULL, NULL, 1, &ave_x, &ave_y, &ave_z, NULL );
|
125 |
|
|
126 |
|
SHPWriteObject( hSHPHandle, -1, psShape );
|
127 |
|
SHPDestroyObject( psShape );
|
128 |
|
//do the update to the dbf file too
|
129 |
|
iRecord = DBFGetRecordCount( hDBF );
|
130 |
|
|
131 |
|
DBFWriteStringAttribute(hDBF, iRecord, url_field, urlvec[ii].c_str() );
|
132 |
|
DBFWriteStringAttribute(hDBF, iRecord, docid_field, docidvec[ii].c_str() );
|
133 |
|
DBFWriteIntegerAttribute(hDBF, iRecord, id_field, int(ii) );
|
134 |
|
DBFWriteDoubleAttribute(hDBF, iRecord, area_field, area_coef );
|
135 |
|
}
|
136 |
|
}
|
137 |
|
//recompute the extents
|
138 |
|
//SHPComputeExtents( psShape );
|
139 |
|
//cout << "xmin: " << psShape->dfXMin << " xmax: " << psShape->dfXMax << endl;
|
140 |
|
//cout << "ymin: " << psShape->dfYMin << " ymax: " << psShape->dfYMax << endl;
|
141 |
|
DBFClose( hDBF );
|
142 |
|
SHPClose( hSHPHandle );
|
|
129 |
DBFWriteStringAttribute(hDBF, iRecord, url_field,
|
|
130 |
urlvec[ii].c_str());
|
|
131 |
DBFWriteStringAttribute(hDBF, iRecord, docid_field,
|
|
132 |
docidvec[ii].c_str());
|
|
133 |
DBFWriteIntegerAttribute(hDBF, iRecord, id_field, int (ii));
|
|
134 |
DBFWriteDoubleAttribute(hDBF, iRecord, area_field, area_coef);
|
|
135 |
}
|
|
136 |
}
|
|
137 |
//recompute the extents
|
|
138 |
//SHPComputeExtents( psShape );
|
|
139 |
//cout << "xmin: " << psShape->dfXMin << " xmax: " << psShape->dfXMax << endl;
|
|
140 |
//cout << "ymin: " << psShape->dfYMin << " ymax: " << psShape->dfYMax << endl;
|
|
141 |
DBFClose(hDBF);
|
|
142 |
SHPClose(hSHPHandle);
|
143 |
143 |
}
|
144 |
144 |
|
145 |
145 |
|
146 |
146 |
/** getUsage -- function that prints to stdout the usage for this driver */
|
147 |
147 |
static void getUsage()
|
148 |
148 |
{
|
149 |
|
std::cout<<"usage: metacat2shape metacat_export.txt test.shp\n\n";
|
150 |
|
std::cout<<" where:\n\n";
|
151 |
|
std::cout<<" input -- is an input ASCII file, that contains the following cols:\n";
|
152 |
|
std::cout<<" -> docid -- the document id\n";
|
153 |
|
std::cout<<" -> x -- the xlocation\n";
|
154 |
|
std::cout<<" -> y -- the y location\n";
|
155 |
|
std::cout<<" -> url -- the url to the document\n";
|
|
149 |
std::cout << "usage: metacat2shape metacat_export.txt test.shp\n\n";
|
|
150 |
std::cout << " where:\n\n";
|
|
151 |
std::
|
|
152 |
cout <<
|
|
153 |
" input -- is an input ASCII file, that contains the following cols:\n";
|
|
154 |
std::cout << " -> docid -- the document id\n";
|
|
155 |
std::cout << " -> x -- the xlocation\n";
|
|
156 |
std::cout << " -> y -- the y location\n";
|
|
157 |
std::cout << " -> url -- the url to the document\n";
|
156 |
158 |
|
157 |
|
std::cout<<" shapefile -- {output} is a ESRI shapefile\n\n";
|
|
159 |
std::cout << " shapefile -- {output} is a ESRI shapefile\n\n";
|
158 |
160 |
|
159 |
|
std::cout<<" see:\n";
|
160 |
|
std::cout<<" example: metacat2shape metacat_export.txt test.shp\n\n";
|
|
161 |
std::cout << " see:\n";
|
|
162 |
std::cout << " example: metacat2shape metacat_export.txt test.shp\n\n";
|
161 |
163 |
|
162 |
|
std::cout<<" ##><><><><><><><><><><><><><><><><><><><><><><><><>##\n";
|
163 |
|
std::cout<<" ## John Harris ##\n";
|
164 |
|
std::cout<<" ## harris@nceas.ucsb.edu ##\n";
|
165 |
|
std::cout<<" ## Copyright 1999-2003 ##\n";
|
166 |
|
std::cout<<" ##><><><><><><><><><><><><><><><><><><><><><><><><>##\n";
|
|
164 |
std::cout << " ##><><><><><><><><><><><><><><><><><><><><><><><><>##\n";
|
|
165 |
std::cout << " ## John Harris ##\n";
|
|
166 |
std::cout << " ## harris@nceas.ucsb.edu ##\n";
|
|
167 |
std::cout << " ## Copyright 1999-2003 ##\n";
|
|
168 |
std::cout << " ##><><><><><><><><><><><><><><><><><><><><><><><><>##\n";
|
167 |
169 |
|
168 |
170 |
std::cout << std::endl;
|
169 |
171 |
|
... | ... | |
171 |
173 |
|
172 |
174 |
|
173 |
175 |
|
174 |
|
int main( int argc, char * * argv )
|
|
176 |
int main(int argc, char **argv)
|
175 |
177 |
{
|
176 |
178 |
//get the usage info if the inputs are not right
|
177 |
|
if ( argc != 3 )
|
178 |
|
{
|
|
179 |
if (argc != 3) {
|
179 |
180 |
getUsage();
|
180 |
|
exit( 1 );
|
|
181 |
exit(1);
|
181 |
182 |
}
|
182 |
|
|
183 |
183 |
//these arrays are for the input x, y, z data
|
184 |
|
float min_pntx[1000] [100];
|
185 |
|
float min_pnty[1000] [100];
|
186 |
|
float max_pntx[1000] [100];
|
187 |
|
float max_pnty[1000] [100];
|
|
184 |
float min_pntx[1000][100];
|
|
185 |
float min_pnty[1000][100];
|
|
186 |
float max_pntx[1000][100];
|
|
187 |
float max_pnty[1000][100];
|
188 |
188 |
|
189 |
|
float pointz[1000] [100];
|
190 |
|
vector<string> docidvec;
|
191 |
|
vector<string> urlvec;
|
|
189 |
float pointz[1000][100];
|
|
190 |
vector < string > docidvec;
|
|
191 |
vector < string > urlvec;
|
192 |
192 |
|
193 |
|
FILE * infile;
|
|
193 |
FILE *infile;
|
194 |
194 |
char oneline[200];
|
195 |
|
char * value;
|
|
195 |
char *value;
|
196 |
196 |
|
197 |
197 |
int cnt = 0;
|
198 |
198 |
int number_lines = 0;
|
... | ... | |
205 |
205 |
|
206 |
206 |
SHPHandle hSHP;
|
207 |
207 |
int nShapeType, nEntities, i, iPart;
|
208 |
|
const char * pszPlus;
|
|
208 |
const char *pszPlus;
|
209 |
209 |
|
210 |
210 |
//test the reading of the file
|
211 |
|
if ( ( infile = fopen( argv[1], "r" ) ) == ( FILE * ) NULL )
|
212 |
|
{
|
213 |
|
fprintf( stderr, "Can't read the file: %s.\n", argv[1] );
|
214 |
|
exit( 2 );
|
|
211 |
if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
|
|
212 |
fprintf(stderr, "Can't read the file: %s.\n", argv[1]);
|
|
213 |
exit(2);
|
215 |
214 |
}
|
216 |
215 |
|
217 |
216 |
/* read the data into an array -- first the grid nodes
|
... | ... | |
225 |
224 |
* 36.2083333333333
|
226 |
225 |
* http://metacat.nceas.ucsb.edu/knb/servlet/metacat?action=read&docid=nrs.239.1&qformat=knb
|
227 |
226 |
*/
|
228 |
|
infile = fopen( argv[1], "r" );
|
229 |
|
char const * out_shape = argv[2];
|
230 |
|
while ( fgets( oneline, 199, infile ) ) {
|
231 |
|
sscanf( oneline, "%s %s %s %s %s %s %s", buf_docid, buf_xmin, buf_xmax, buf_ymin, buf_ymax, buf_url);
|
|
227 |
infile = fopen(argv[1], "r");
|
|
228 |
char const *out_shape = argv[2];
|
|
229 |
while (fgets(oneline, 199, infile)) {
|
|
230 |
sscanf(oneline, "%s %s %s %s %s %s %s", buf_docid, buf_xmin, buf_xmax,
|
|
231 |
buf_ymin, buf_ymax, buf_url);
|
232 |
232 |
|
233 |
233 |
/**** cout<<" docid -> " << bufa
|
234 |
234 |
<<"\n cnt -> " << cnt
|
... | ... | |
237 |
237 |
<<"\n p -> " << buf2
|
238 |
238 |
<<endl; *******/
|
239 |
239 |
|
240 |
|
min_pntx[2] [cnt] = atof(buf_xmin);
|
241 |
|
max_pntx[2] [cnt] = atof(buf_xmax);
|
242 |
|
min_pnty[2] [cnt] = atof(buf_ymin);
|
243 |
|
max_pnty[2] [cnt] = atof(buf_ymax);
|
|
240 |
min_pntx[2][cnt] = atof(buf_xmin);
|
|
241 |
max_pntx[2][cnt] = atof(buf_xmax);
|
|
242 |
min_pnty[2][cnt] = atof(buf_ymin);
|
|
243 |
max_pnty[2][cnt] = atof(buf_ymax);
|
244 |
244 |
|
245 |
245 |
urlvec.push_back(buf_url);
|
246 |
246 |
docidvec.push_back(buf_docid);
|
... | ... | |
248 |
248 |
cnt++;
|
249 |
249 |
number_lines = cnt;
|
250 |
250 |
}
|
251 |
|
fclose( infile );
|
|
251 |
fclose(infile);
|
252 |
252 |
|
253 |
|
cout<<"creating a new shape file, with "<< number_lines <<" records "<<endl;
|
254 |
|
WritePointsArray( SHPT_POINT,
|
255 |
|
out_shape,
|
256 |
|
min_pntx,
|
257 |
|
max_pntx,
|
258 |
|
min_pnty,
|
259 |
|
max_pnty,
|
260 |
|
pointz,
|
261 |
|
urlvec,
|
262 |
|
docidvec,
|
263 |
|
number_lines );
|
|
253 |
cout << "creating a new shape file, with " << number_lines << " records "
|
|
254 |
<< endl;
|
|
255 |
WritePointsArray(SHPT_POINT, out_shape, min_pntx, max_pntx, min_pnty,
|
|
256 |
max_pnty, pointz, urlvec, docidvec, number_lines);
|
264 |
257 |
|
265 |
258 |
#ifdef USE_DBMALLOC
|
266 |
|
malloc_dump( 2 );
|
|
259 |
malloc_dump(2);
|
267 |
260 |
#endif
|
268 |
|
exit( 0 );
|
|
261 |
exit(0);
|
269 |
262 |
}
|
fixed the index jsp to do the redirection to the given skin's html (the all
seem to have html pages, yet not all have jsp's). Started implementing the
display of eml docs with bounding coordinates as boxes.