1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2000 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* Author: John Harris
|
7
|
* '$Date: 2006-02-24 16:55:55 -0800 (Fri, 24 Feb 2006) $'
|
8
|
* '$Revision: 2919 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
|
25
|
package edu.ucsb.nceas.metacat.spatial;
|
26
|
|
27
|
import java.util.Vector;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
|
31
|
/**
|
32
|
* Class that reflects a dataset of Metacat Documents in a spatially represented
|
33
|
* sense. This dataset class is comprised of multiple MetacatSpatialDocument
|
34
|
* and uses the PersistentMetacatSpatialDataset class for IO with databases
|
35
|
* and the file system
|
36
|
*/
|
37
|
public class MetacatSpatialDataset {
|
38
|
|
39
|
private boolean initialized = false;
|
40
|
|
41
|
private static Logger log = Logger.getLogger(MetacatSpatialDataset.class.getName());
|
42
|
|
43
|
private Vector docs; // vector of MetacatSpatialDocument's
|
44
|
|
45
|
|
46
|
/** empty constructor **/
|
47
|
public MetacatSpatialDataset() {
|
48
|
this.initialized = true;
|
49
|
docs = new Vector();
|
50
|
}
|
51
|
|
52
|
|
53
|
/**
|
54
|
* returns a string array of the docids
|
55
|
*/
|
56
|
public String[] getDocidList() {
|
57
|
String[] s = new String[docs.size()];
|
58
|
for (int i = 0; i < docs.size(); i++) {
|
59
|
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i);
|
60
|
s[i] = _doc.getDocid();
|
61
|
}
|
62
|
return s;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Returns docid's in a csv-formatted text string
|
67
|
*/
|
68
|
public String toTXT () {
|
69
|
StringBuffer _sb = new StringBuffer();
|
70
|
for (int i = 0; i < docs.size(); i++) {
|
71
|
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i);
|
72
|
if ( i==0 ) {
|
73
|
_sb.append(_doc.getDocid());
|
74
|
} else {
|
75
|
_sb.append(","+_doc.getDocid());
|
76
|
}
|
77
|
}
|
78
|
return _sb.toString();
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Returns XML as a String -- the xml describes the dataset
|
83
|
*/
|
84
|
public String toXML () {
|
85
|
StringBuffer _sb = new StringBuffer();
|
86
|
|
87
|
_sb.append("<metacatspatialdataset>");
|
88
|
for (int i = 0; i < docs.size(); i++) {
|
89
|
|
90
|
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i);
|
91
|
|
92
|
_sb.append("<metacatspatialdocument>\n");
|
93
|
|
94
|
_sb.append("<creator>");
|
95
|
_sb.append(" <individualName>");
|
96
|
_sb.append(" <givenName></givenName>");
|
97
|
_sb.append(" <surName></surName>");
|
98
|
_sb.append(" </individualName>");
|
99
|
_sb.append(" <organizationName></organizationName>");
|
100
|
_sb.append(" </creator>");
|
101
|
|
102
|
_sb.append("<title>"+_doc.getTitle()+"</title>");
|
103
|
_sb.append("<docid>"+_doc.getDocid()+"</docid>");
|
104
|
_sb.append(" <extents>");
|
105
|
_sb.append(" <ispoint>"+_doc.getIsPoint()+"</ispoint>");
|
106
|
_sb.append(" <xmin>"+_doc.getXMin()+"</xmin>");
|
107
|
_sb.append(" <ymin>"+_doc.getYMin()+"</ymin>");
|
108
|
_sb.append(" <xmax>"+_doc.getXMax()+"</xmax>");
|
109
|
_sb.append(" <ymax>"+_doc.getYMax()+"</ymax>");
|
110
|
_sb.append(" </extents>\n");
|
111
|
|
112
|
|
113
|
_sb.append("</metacatspatialdocument>");
|
114
|
|
115
|
}
|
116
|
_sb.append("</metacatspatialdataset>");
|
117
|
|
118
|
return _sb.toString();
|
119
|
}
|
120
|
|
121
|
|
122
|
/**
|
123
|
* returns the document corresponding to the input index from this dataset
|
124
|
*/
|
125
|
public MetacatSpatialDocument getDocument(int _id) {
|
126
|
return (MetacatSpatialDocument)docs.elementAt(_id);
|
127
|
}
|
128
|
|
129
|
/*
|
130
|
* Adds a new MetacatSpatialDocument to this dataset
|
131
|
*/
|
132
|
public void add(MetacatSpatialDocument msdoc) {
|
133
|
docs.add(msdoc);
|
134
|
}
|
135
|
|
136
|
|
137
|
/**
|
138
|
* Returns the size (or number of documents) of the dataset
|
139
|
*/
|
140
|
public int size() {
|
141
|
return docs.size();
|
142
|
}
|
143
|
|
144
|
|
145
|
/**
|
146
|
* returns the data set as a flat-ascii table like:
|
147
|
*
|
148
|
* x y z segid
|
149
|
*
|
150
|
* the data are delimited by spaces and each line is terminated bt '\n'
|
151
|
* out.println("#HEADER docid x y url");
|
152
|
*/
|
153
|
public StringBuffer getExtentsDataAsAscii() {
|
154
|
StringBuffer _sb = new StringBuffer();
|
155
|
for (int i = 0; i < docs.size(); i++) {
|
156
|
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i);
|
157
|
try {
|
158
|
if ( ! _doc.getIsPoint() ) {
|
159
|
//_sb.append( _doc.getDocid()+" "+ _doc.getXMin()+ " " + _doc.getYMin() + " http://www.cnn.com \n");
|
160
|
//_sb.append( _doc.getDocid()+" "+ _doc.getXMax()+ " " + _doc.getYMin() + " http://www.cnn.com \n");
|
161
|
_sb.append( _doc.getDocid()+" "+ _doc.jitter(_doc.getXMax())+ " "
|
162
|
+ _doc.jitter(_doc.getYMax()) + " "
|
163
|
+ "http://"+_doc.getMetacatURL() + "metacat?action=read&docid="+_doc.getDocid()+"&qformat=knp"
|
164
|
+ " \n");
|
165
|
//_sb.append( _doc.getDocid()+" "+ _doc.getXMin()+ " " + _doc.getYMax() + " http://www.cnn.com \n");
|
166
|
}
|
167
|
} catch (NullPointerException npe) {
|
168
|
log.fatal("ERROR: null pointer exception on a spatial document");
|
169
|
npe.getMessage();
|
170
|
}
|
171
|
}
|
172
|
return _sb;
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* writes the entire metacat spatial dataset
|
177
|
*/
|
178
|
public void writeMetacatSpatialCache() {
|
179
|
// write the data stored in this object using the persistent layer
|
180
|
PersistentMetacatSpatialDataset _writer = new PersistentMetacatSpatialDataset();
|
181
|
_writer.writeMetacatSpatialCache(this);
|
182
|
}
|
183
|
|
184
|
|
185
|
/*
|
186
|
* Writes the dataset to the file system
|
187
|
*/
|
188
|
public void writeTextQueryData() {
|
189
|
// write the data stored in this object using the persistent layer
|
190
|
PersistentMetacatSpatialDataset _writer = new PersistentMetacatSpatialDataset();
|
191
|
_writer.writeTextQueryData(this);
|
192
|
}
|
193
|
|
194
|
|
195
|
|
196
|
|
197
|
|
198
|
|
199
|
}
|