Revision 2919
Added by harris almost 19 years ago
src/edu/ucsb/nceas/metacat/spatial/MetacatSpatialDataset.java | ||
---|---|---|
48 | 48 |
this.initialized = true; |
49 | 49 |
docs = new Vector(); |
50 | 50 |
} |
51 |
|
|
51 | 52 |
|
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 |
/** |
|
53 | 82 |
* Returns XML as a String -- the xml describes the dataset |
54 | 83 |
*/ |
55 | 84 |
public String toXML () { |
... | ... | |
127 | 156 |
MetacatSpatialDocument _doc = (MetacatSpatialDocument)docs.elementAt(i); |
128 | 157 |
try { |
129 | 158 |
if ( ! _doc.getIsPoint() ) { |
130 |
_sb.append( _doc.getDocid()+" "+ _doc.getXMin()+ " " + _doc.getYMin() + " http://www.cnn.com \n"); |
|
131 |
_sb.append( _doc.getDocid()+" "+ _doc.getXMax()+ " " + _doc.getYMin() + " http://www.cnn.com \n"); |
|
132 |
_sb.append( _doc.getDocid()+" "+ _doc.getXMax()+ " " + _doc.getYMax() + " http://www.cnn.com \n"); |
|
133 |
_sb.append( _doc.getDocid()+" "+ _doc.getXMin()+ " " + _doc.getYMax() + " http://www.cnn.com \n"); |
|
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"); |
|
134 | 166 |
} |
135 | 167 |
} catch (NullPointerException npe) { |
136 | 168 |
log.fatal("ERROR: null pointer exception on a spatial document"); |
src/edu/ucsb/nceas/metacat/spatial/SpatialQueryProcessor.java | ||
---|---|---|
147 | 147 |
float _docMinX = |
148 | 148 |
queryWestBoundingCoordinate((String) _docs.elementAt(i)); |
149 | 149 |
|
150 |
String _title = getTitle((String) _docs.elementAt(i)); |
|
150 |
//String _title = getTitle((String) _docs.elementAt(i));
|
|
151 | 151 |
|
152 | 152 |
// check if inside the bounding box |
153 | 153 |
if (_docMaxX <= _xmax && _docMinX >= _xmin && _docMaxY <= _ymax && _docMinY >= _ymin ) { |
src/edu/ucsb/nceas/metacat/spatial/MetacatSpatialConstants.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
public static final float FLOAT_NULL = (float)1e20; |
28 | 28 |
|
29 |
/** like: nebulous.msi.ucsb.edu:9999 **/ |
|
30 |
public static String servercontext; |
|
31 |
|
|
32 |
|
|
33 |
//metacat?action=read&docid=knb2003.432.1&qformat=knb |
|
34 |
public static String metacatcontext = "knp"; |
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
public static void setServerContext(String _scontext) { |
|
39 |
servercontext = _scontext; |
|
40 |
} |
|
41 |
|
|
42 |
public static String getServerContext() { return servercontext; } |
|
43 |
|
|
44 |
public static String getMetacatContext() { return metacatcontext;} |
|
45 |
|
|
46 |
|
|
29 | 47 |
} |
src/edu/ucsb/nceas/metacat/spatial/MetacatSpatialDocument.java | ||
---|---|---|
63 | 63 |
this.extents = _extents; |
64 | 64 |
} |
65 | 65 |
|
66 |
|
|
67 |
/** |
|
68 |
* jitters a float value |
|
69 |
*/ |
|
70 |
public float jitter(float _val) { |
|
71 |
float _random = (float)Math.random(); |
|
72 |
return _val+(_random/1000); |
|
73 |
} |
|
74 |
|
|
75 |
public String getMetacatURL() { |
|
76 |
|
|
77 |
return MetacatSpatialConstants.getServerContext() |
|
78 |
+"/"+MetacatSpatialConstants.getMetacatContext()+"/"; |
|
79 |
|
|
80 |
} |
|
81 |
|
|
66 | 82 |
public String getTitle() { return this.title; } |
67 | 83 |
public void setTitle(String _title) {this.title = _title; } |
68 | 84 |
|
src/edu/ucsb/nceas/metacat/DocumentIdQuery.java | ||
---|---|---|
36 | 36 |
public class DocumentIdQuery |
37 | 37 |
{ |
38 | 38 |
|
39 |
|
|
39 | 40 |
/** |
41 |
* Create an squery parameters table using an already-initialized hashtable |
|
42 |
* |
|
43 |
* @param docidList an array of document identifiers to search for |
|
44 |
* @param params the hashtable to add the query parameters to. |
|
45 |
* |
|
46 |
*/ |
|
47 |
public static Hashtable createDocidQueryParams(String[] docidList, Hashtable params) |
|
48 |
{ |
|
49 |
params = getDefaultQueryParams(); |
|
50 |
if (docidList != null) { |
|
51 |
params.put("/eml/@packageId", docidList); |
|
52 |
} |
|
53 |
return params; |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
40 | 58 |
* Create an squery using some preset values for the query parameters, only |
41 | 59 |
* passing in the document ids to be searched. |
42 | 60 |
* |
43 |
* @param docidList an arrany of document identifiers to search for
|
|
61 |
* @param docidList an array of document identifiers to search for |
|
44 | 62 |
*/ |
45 | 63 |
public static String createDocidQuery(String[] docidList) |
46 | 64 |
{ |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
73 | 73 |
import edu.ucsb.nceas.metacat.spatial.MetacatSpatialQuery; |
74 | 74 |
import edu.ucsb.nceas.metacat.spatial.MetacatSpatialDocument; |
75 | 75 |
import edu.ucsb.nceas.metacat.spatial.MetacatSpatialDataset; |
76 |
import edu.ucsb.nceas.metacat.spatial.MetacatSpatialConstants; |
|
76 | 77 |
|
77 | 78 |
/** |
78 | 79 |
* A metadata catalog server implemented as a Java Servlet |
... | ... | |
207 | 208 |
} |
208 | 209 |
|
209 | 210 |
// create a spatial index of the database |
211 |
MetacatSpatialConstants.setServerContext(MetaCatUtil.getOption("server")); |
|
210 | 212 |
MetacatSpatialQuery _spatialQuery = new MetacatSpatialQuery(); |
211 | 213 |
|
212 | 214 |
// issue the query -- using the geographic bounds of the Earth |
... | ... | |
487 | 489 |
PrintWriter out = response.getWriter(); |
488 | 490 |
handleLoginAction(out, params, request, response); |
489 | 491 |
out.close(); |
490 |
} |
|
491 |
|
|
492 |
else if (action.trim().equals("spatial_query") ) { |
|
493 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
494 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
495 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
496 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
497 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
498 |
|
|
499 |
handleSpatialQuery(params, request, response); |
|
500 | 492 |
|
501 | 493 |
// handle logout action |
502 |
} else if (action.equals("logout")) { |
|
494 |
} else if (action.equals("logout")) {
|
|
503 | 495 |
PrintWriter out = response.getWriter(); |
504 | 496 |
handleLogoutAction(out, params, request, response); |
505 | 497 |
out.close(); |
... | ... | |
599 | 591 |
"Illegal action squery without \"query\" parameter"); |
600 | 592 |
out.close(); |
601 | 593 |
} |
594 |
} else if ( action.trim().equals("spatial_query")) { |
|
595 |
|
|
596 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
597 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
598 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
599 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
600 |
logMetacat.fatal("******************* SPATIAL QUERY ********************"); |
|
601 |
|
|
602 |
|
|
603 |
PrintWriter out = response.getWriter(); |
|
604 |
handleSpatialQuery(out, params, response, username, groupnames, sess_id); |
|
605 |
out.close(); |
|
606 |
|
|
602 | 607 |
} else if (action.equals("export")) { |
603 | 608 |
|
604 | 609 |
handleExportAction(params, response, username, |
... | ... | |
768 | 773 |
/** |
769 | 774 |
* handles all spatial queries -- these queries may include any of the |
770 | 775 |
* queries supported by the WFS / WMS standards |
776 |
|
|
777 |
handleSQuery(out, params, response, username, groupnames, |
|
778 |
sess_id); |
|
771 | 779 |
*/ |
772 |
private void handleSpatialQuery(Hashtable params, |
|
773 |
HttpServletRequest request, |
|
774 |
HttpServletResponse response) { |
|
780 |
private void handleSpatialQuery(PrintWriter out, Hashtable params, |
|
781 |
HttpServletResponse response, |
|
782 |
String username, String[] groupnames, |
|
783 |
String sess_id) { |
|
784 |
|
|
775 | 785 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
776 | 786 |
MetacatSpatialQuery _spatialQuery = new MetacatSpatialQuery(); |
777 | 787 |
|
778 |
PrintWriter out; |
|
779 |
try { |
|
780 |
out = response.getWriter(); |
|
781 | 788 |
|
782 | 789 |
// switch -- html/xml print |
783 |
boolean printXML = true;
|
|
790 |
boolean printXML = false;
|
|
784 | 791 |
|
785 | 792 |
// get the spatial parameters |
786 | 793 |
logMetacat.warn("params: " + params); |
... | ... | |
799 | 806 |
MetacatSpatialDataset _data = |
800 | 807 |
_spatialQuery.queryDatasetByCartesianBounds(_xmin, _ymin, _xmax, _ymax); |
801 | 808 |
|
809 |
// create an s-query |
|
810 |
//DocumentIdQuery.createDocidQueryParams(_data.getDocidList(), params); |
|
811 |
//params.put("query", DocumentIdQuery.createDocidQuery(_data.getDocidList()) ); |
|
812 |
String[] queryArray = new String[1]; |
|
813 |
queryArray[0] = DocumentIdQuery.createDocidQuery(_data.getDocidList()); |
|
814 |
params.put("query", queryArray); |
|
815 |
|
|
816 |
String[] qformatArray = new String[1]; |
|
817 |
qformatArray[0] = "knp"; |
|
818 |
params.put("qformat", qformatArray); |
|
819 |
|
|
820 |
// change the action |
|
821 |
String[] actionArray = new String[1]; |
|
822 |
actionArray[0] = "squery"; |
|
823 |
params.put("action", actionArray); |
|
824 |
|
|
802 | 825 |
// return the list of docs and point at the spatial theme |
803 | 826 |
if ( printXML) { |
804 | 827 |
response.setContentType("text/xml"); |
805 | 828 |
out.println(_data.toXML() ); // write the data as xml |
806 | 829 |
out.close(); |
807 | 830 |
} else { |
808 |
response.setContentType("text/html"); |
|
809 |
out.println("<html>\n<body>"); |
|
810 |
//for all data (print url approximations) |
|
811 |
for (int i = 0; i < _data.size(); i++) { |
|
812 |
//format like: metacat?action=read&docid=dpennington.38.6&qformat=knb |
|
813 |
out.println("<a href=\""+request.getRequestURL()+"?action=read&docid="+(_data.getDocument(i)).getDocid()+"\"> "+(_data.getDocument(i)).getDocid()+"</a> <br>"); |
|
814 |
} |
|
815 |
out.println("</html>\n</body>"); |
|
816 |
out.close(); |
|
817 |
|
|
831 |
logMetacat.warn("username: " + username+"\nsession: "+sess_id); |
|
832 |
handleSQuery(out, params, response, username, groupnames, sess_id); |
|
818 | 833 |
} |
819 | 834 |
|
820 |
} catch (IOException ioe) { ioe.printStackTrace(); } |
|
821 |
|
|
822 | 835 |
return; |
823 | 836 |
} |
824 | 837 |
|
Also available in: Unified diff
Modified the way the results page is displayed.