Revision 2913
Added by harris almost 19 years ago
src/edu/ucsb/nceas/metacat/spatial/MetacatSpatialDataset.java | ||
---|---|---|
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
|
53 |
/** |
|
54 |
* returns the document corresponding to the input index from this dataset |
|
55 |
*/ |
|
53 | 56 |
public MetacatSpatialDocument getDocument(int _id) { |
54 | 57 |
return (MetacatSpatialDocument)docs.elementAt(_id); |
55 | 58 |
} |
... | ... | |
81 | 84 |
StringBuffer _sb = new StringBuffer(); |
82 | 85 |
for (int i = 0; i < docs.size(); i++) { |
83 | 86 |
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i); |
87 |
try { |
|
84 | 88 |
if ( ! _doc.getIsPoint() ) { |
85 | 89 |
_sb.append( _doc.getXMin()+ " " + _doc.getYMin() + " 0 " + _doc.getDocid()+"\n"); |
86 | 90 |
_sb.append( _doc.getXMax()+ " " + _doc.getYMin() + " 0 " + _doc.getDocid()+"\n"); |
87 | 91 |
_sb.append( _doc.getXMax()+ " " + _doc.getYMax() + " 0 " + _doc.getDocid()+"\n"); |
88 | 92 |
_sb.append( _doc.getXMin()+ " " + _doc.getYMax() + " 0 " + _doc.getDocid()+"\n"); |
89 | 93 |
} |
94 |
} catch (NullPointerException npe) { |
|
95 |
log.fatal("ERROR: null pointer exception on a spatial document"); |
|
96 |
npe.getMessage(); |
|
97 |
} |
|
90 | 98 |
} |
91 | 99 |
return _sb; |
92 | 100 |
} |
93 | 101 |
|
102 |
/** |
|
103 |
* writes the entire metacat spatial dataset |
|
104 |
*/ |
|
105 |
public void writeMetacatSpatialCache() { |
|
106 |
// write the data stored in this object using the persistent layer |
|
107 |
PersistentMetacatSpatialDataset _writer = new PersistentMetacatSpatialDataset(); |
|
108 |
_writer.writeMetacatSpatialCache(this); |
|
109 |
} |
|
94 | 110 |
|
111 |
|
|
95 | 112 |
/* |
96 | 113 |
* Writes the dataset to the file system |
97 | 114 |
*/ |
98 |
public void writeTextQueryData() { |
|
99 |
|
|
115 |
public void writeTextQueryData() { |
|
100 | 116 |
// write the data stored in this object using the persistent layer |
101 | 117 |
PersistentMetacatSpatialDataset _writer = new PersistentMetacatSpatialDataset(); |
102 | 118 |
_writer.writeTextQueryData(this); |
103 | 119 |
} |
104 | 120 |
|
121 |
|
|
122 |
|
|
105 | 123 |
|
106 | 124 |
|
107 | 125 |
|
src/edu/ucsb/nceas/metacat/spatial/PersistentMetacatSpatialDataset.java | ||
---|---|---|
44 | 44 |
public class PersistentMetacatSpatialDataset { |
45 | 45 |
|
46 | 46 |
private String textQueryAsciiFile = "/tmp/mso_metacat_textquery.ascii"; |
47 |
private String metacatSpatialCacheAsciiFile = "/tmp/mso_metacat_cache.ascii"; |
|
47 | 48 |
|
48 | 49 |
private static Logger log = Logger.getLogger(PersistentMetacatSpatialDataset.class.getName()); |
49 | 50 |
|
51 |
|
|
52 |
/* |
|
53 |
* Writes the dataset to the file system |
|
54 |
*/ |
|
55 |
public void writeMetacatSpatialCache(MetacatSpatialDataset dataset) { |
|
56 |
try { |
|
57 |
PrintStream out = new PrintStream(new FileOutputStream( metacatSpatialCacheAsciiFile)); |
|
58 |
|
|
59 |
out.println("#HEADER x y z segid"); |
|
50 | 60 |
|
61 |
out.println( dataset.getExtentsDataAsAscii()); |
|
62 |
log.fatal("extents data: " + dataset.getExtentsDataAsAscii() +" done" ); |
|
63 |
|
|
64 |
out.close(); |
|
65 |
|
|
66 |
} catch (FileNotFoundException fnfe) { |
|
67 |
log.fatal("ERROR: could not find the file "); |
|
68 |
fnfe.printStackTrace(); |
|
69 |
} |
|
51 | 70 |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
|
|
52 | 76 |
/* |
53 | 77 |
* Writes the dataset to the file system |
54 | 78 |
*/ |
src/edu/ucsb/nceas/metacat/spatial/SpatialQueryProcessor.java | ||
---|---|---|
106 | 106 |
FileReader queryFileReader = new FileReader(QUERYFILE); |
107 | 107 |
String res = runQuery((Reader) queryFileReader); |
108 | 108 |
return res; |
109 |
} protected MetacatSpatialDataset queryDatasetByCartesianBounds(float |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
/** |
|
113 |
* returns the dataset constained by the input cartesian boundaries |
|
114 |
* |
|
115 |
* param _xmin -- the minimum x cartesian boundary |
|
116 |
* param _ymin -- the minimum y cartesian boundary |
|
117 |
* param _xmax -- the maximum x cartesian boundary |
|
118 |
* param _ymax -- the maximum y cartesian boundary |
|
119 |
* |
|
120 |
* returns data -- a Metacat spatial dataset, containing all the documents |
|
121 |
* within the input bounding box |
|
122 |
*/ |
|
123 |
protected MetacatSpatialDataset queryDatasetByCartesianBounds(float |
|
110 | 124 |
_xmin, |
111 | 125 |
float |
112 | 126 |
_ymin, |
... | ... | |
122 | 136 |
|
123 | 137 |
// for each, see if they fall w/in bounds |
124 | 138 |
for (int i = 0; i < _docs.size(); i++) { |
139 |
|
|
140 |
MetacatSpatialExtents _extents = new MetacatSpatialExtents(); |
|
125 | 141 |
float _docMaxY = |
126 | 142 |
queryNorthBoundingCoordinate((String) _docs.elementAt(i)); |
127 | 143 |
float _docMinY = |
... | ... | |
132 | 148 |
queryWestBoundingCoordinate((String) _docs.elementAt(i)); |
133 | 149 |
|
134 | 150 |
// check if inside the bounding box |
135 |
if (_docMaxX <= _xmax && _docMaxX >= _xmin) {
|
|
151 |
if (_docMaxX <= _xmax && _docMinX >= _xmin && _docMaxY <= _ymax && _docMinY >= _ymin ) {
|
|
136 | 152 |
MetacatSpatialDocument _doc = |
137 | 153 |
new MetacatSpatialDocument((String) _docs.elementAt(i)); |
154 |
|
|
155 |
log.warn("----------------------------------------------------------"); |
|
156 |
log.warn("----------------------------------------------------------"); |
|
157 |
log.warn("----------------------------------------------------------"); |
|
158 |
log.warn("----------------------------------------------------------"); |
|
159 |
log.warn(_docMinX+ " "+ _docMinY + " " +_docMaxX+ " " + _docMaxY); |
|
160 |
|
|
161 |
|
|
138 | 162 |
_doc.setDocid((String) _docs.elementAt(i)); |
163 |
_extents.setXMin(_docMinX); |
|
164 |
_extents.setYMin(_docMinY); |
|
165 |
_extents.setXMax(_docMaxX); |
|
166 |
_extents.setYMax(_docMaxY); |
|
167 |
|
|
168 |
|
|
169 |
if ( _xmax==_xmin && _ymax==_ymin ) { |
|
170 |
_extents.setIsPoint(true); |
|
171 |
} else { |
|
172 |
_extents.setIsPoint(false); |
|
173 |
} |
|
174 |
|
|
175 |
|
|
176 |
|
|
139 | 177 |
// set the extents |
178 |
_doc.setExtents(_extents); |
|
140 | 179 |
_data.add(_doc); |
141 | 180 |
} |
142 | 181 |
} |
143 | 182 |
return _data; |
144 | 183 |
} |
145 | 184 |
|
185 |
|
|
186 |
|
|
146 | 187 |
/** |
147 | 188 |
* Returns a Vector of all the docids in the xml_nodes tables |
148 | 189 |
*/ |
src/edu/ucsb/nceas/metacat/spatial/QueryFailedException.java | ||
---|---|---|
39 | 39 |
* @param message The error or warning message. |
40 | 40 |
*/ |
41 | 41 |
public QueryFailedException(String message) { |
42 |
super(message);
|
|
42 |
super(message); |
|
43 | 43 |
} |
44 | 44 |
} |
src/edu/ucsb/nceas/metacat/spatial/MetacatSpatialDocument.java | ||
---|---|---|
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
public float getXMin() { return extents.getXMin(); } |
63 |
public void setXMin(float x) { extents.setXMin(x); } |
|
64 |
|
|
63 | 65 |
public float getYMin() { return extents.getYMin(); } |
66 |
public void setYMin(float y) {extents.setYMin(y); } |
|
67 |
|
|
64 | 68 |
public float getXMax() { return extents.getXMax(); } |
69 |
public void setXMax(float x) {extents.setXMax(x); } |
|
70 |
|
|
65 | 71 |
public float getYMax() { return extents.getYMax(); } |
72 |
public void setYMax(float y) {extents.setYMax(y); } |
|
66 | 73 |
|
67 | 74 |
public String getDocid() { return this.docid; } |
68 | 75 |
|
69 | 76 |
public boolean getIsPoint() { return extents.getIsPoint(); } |
77 |
public void setIsPoint(boolean ispoint) { extents.setIsPoint(ispoint); } |
|
70 | 78 |
|
71 | 79 |
} |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
205 | 205 |
} |
206 | 206 |
MetaCatUtil.skinconfigs.put(skinName, skinOption); |
207 | 207 |
} |
208 |
|
|
209 |
// create a spatial index of the database |
|
210 |
MetacatSpatialQuery _spatialQuery = new MetacatSpatialQuery(); |
|
208 | 211 |
|
212 |
// issue the query -- using the geographic bounds of the Earth |
|
213 |
MetacatSpatialDataset _data = _spatialQuery.queryDatasetByCartesianBounds(-180, -90, 180, 90); |
|
214 |
|
|
215 |
// write the data to the appropriate theme |
|
216 |
_data.writeMetacatSpatialCache(); |
|
217 |
|
|
218 |
|
|
209 | 219 |
MetaCatUtil.printMessage("Metacat (" + Version.getVersion() |
210 | 220 |
+ ") initialized."); |
211 | 221 |
|
Also available in: Unified diff
Continued integration of the spataial stuff with the metacat servlet.