Revision 2563
Added by harris over 19 years ago
src/perl/get_eml.pl | ||
---|---|---|
1 |
#!/usr/bin/perl |
|
2 |
|
|
3 |
# check that the correct number or parameters are issued |
|
4 |
if (($#ARGV +1) != 3) {die "Usage: %./get_eml.pl <metacat_url> <login> <passwd>\n\n";} |
|
5 |
|
|
6 |
($url, $username, $password) = @ARGV; #get the input file and output file names |
|
7 |
|
|
8 |
|
|
9 |
use Metacat; |
|
10 |
use XML::DOM; |
|
11 |
|
|
12 |
my $metacat = Metacat->new(); |
|
13 |
#my $username = "uid=knb2003,o=NCEAS,dc=ecoinformatics,dc=org"; |
|
14 |
#my $password = "afr1ca"; |
|
15 |
|
|
16 |
|
|
17 |
#my $url = "http://indus.nceas.ucsb.edu/knb-test/metacat"; |
|
18 |
#my $url = "http://metacat.nceas.ucsb.edu/knb/servlet/metacat"; |
|
19 |
#my $url = "http://dhcp84.nceas.ucsb.edu:8080/knp/servlet/metacat"; |
|
20 |
#my $url = $infile |
|
21 |
|
|
22 |
if ($metacat) { |
|
23 |
$metacat->set_options( metacatUrl => $url ); |
|
24 |
} else { |
|
25 |
#print "Failed during metacat creation."; |
|
26 |
$error = 1; |
|
27 |
exit(); |
|
28 |
} |
|
29 |
|
|
30 |
# Login to metacat |
|
31 |
# //print "Logging in to metacat..........\n"; |
|
32 |
my $response1 = $metacat->login($username, $password); |
|
33 |
if (! $response1) { |
|
34 |
# //print $metacat->getMessage(); |
|
35 |
# //print "Failed during login: metacat.\n"; |
|
36 |
$error = 2; |
|
37 |
} else { |
|
38 |
# //print "Logged in.\n"; |
|
39 |
} |
|
40 |
|
|
41 |
|
|
42 |
my $query = "<?xml version=\"1.0\" ?> <pathquery version=\"1.2\"> <querytitle>Untitled-Search-2</querytitle> <returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype> <returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype> <returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype> <returnfield>dataset/title</returnfield> <returnfield>individualName/surName</returnfield> <returnfield>keyword</returnfield><returnfield>westBoundingCoordinate</returnfield><returnfield>eastBoundingCoordinate</returnfield><returnfield>northBoundingCoordinate</returnfield><returnfield>southBoundingCoordinate</returnfield><returnfield>westbc</returnfield><returnfield>eastbc</returnfield><returnfield>northbc</returnfield><returnfield>southbc</returnfield><querygroup operator=\"INTERSECT\"><querygroup operator=\"UNION\"><querygroup operator=\"UNION\"><queryterm searchmode=\"contains\" casesensitive=\"false\"><value>%25</value></queryterm></querygroup></querygroup></querygroup></pathquery>"; |
|
43 |
|
|
44 |
my $response = $metacat->squery($query); |
|
45 |
|
|
46 |
my $mesg =$metacat->getMessage(); |
|
47 |
|
|
48 |
#print "\n\ngetting the message ... \n"; |
|
49 |
#print $mesg; |
|
50 |
|
|
51 |
if($mesg eq ""){ |
|
52 |
# print ("Too much time is reply back from metacat..."); |
|
53 |
exit(); |
|
54 |
} |
|
55 |
|
|
56 |
my $parser = new XML::DOM::Parser; |
|
57 |
my $node; |
|
58 |
my $name; |
|
59 |
my $doc = $parser->parse($mesg); |
|
60 |
my $nodes = $doc->getElementsByTagName("docid"); |
|
61 |
|
|
62 |
$numberNodes = $nodes->getLength; |
|
63 |
|
|
64 |
|
|
65 |
for (my $loop_index =0; $loop_index < $numberNodes; $loop_index++) |
|
66 |
{ |
|
67 |
$node = $nodes->item($loop_index); |
|
68 |
$name = $node->getFirstChild()->getNodeValue(); |
|
69 |
|
|
70 |
$node = $node->getParentNode(); |
|
71 |
my $tempnodes = $node->getElementsByTagName("param"); |
|
72 |
my $tempnumberNodes = $tempnodes->getLength; |
|
73 |
|
|
74 |
my $title = ""; |
|
75 |
my $keyword = ""; |
|
76 |
my $cName = ""; |
|
77 |
my $eBC = ""; |
|
78 |
my $wBC = ""; |
|
79 |
my $nBC = ""; |
|
80 |
my $sBC = ""; |
|
81 |
|
|
82 |
for (my $loop =0; $loop < $tempnumberNodes; $loop++) |
|
83 |
{ |
|
84 |
my $tempnode = $tempnodes->item($loop); |
|
85 |
my $paramname = $tempnode->getAttributeNode("name")->getValue(); |
|
86 |
if($paramname eq "dataset/title"){ |
|
87 |
$title = $tempnode->getFirstChild()->getNodeValue(); |
|
88 |
} |
|
89 |
if($paramname eq "keyword"){ |
|
90 |
$keyword = $keyword.",".$tempnode->getFirstChild()->getNodeValue(); |
|
91 |
} |
|
92 |
if($paramname eq "individualName/surName"){ |
|
93 |
$cName = $cName.",".$tempnode->getFirstChild()->getNodeValue(); |
|
94 |
} |
|
95 |
if($paramname eq "eastBoundingCoordinate"){ |
|
96 |
$eBC = $tempnode->getFirstChild()->getNodeValue(); |
|
97 |
} |
|
98 |
if($paramname eq "eastbc"){ |
|
99 |
$eBC = $tempnode->getFirstChild()->getNodeValue(); |
|
100 |
} |
|
101 |
if($paramname eq "westBoundingCoordinate"){ |
|
102 |
$wBC = $tempnode->getFirstChild()->getNodeValue(); |
|
103 |
} |
|
104 |
if($paramname eq "westbc"){ |
|
105 |
$wBC = $tempnode->getFirstChild()->getNodeValue(); |
|
106 |
} |
|
107 |
if($paramname eq "northBoundingCoordinate"){ |
|
108 |
$nBC = $tempnode->getFirstChild()->getNodeValue(); |
|
109 |
} |
|
110 |
if($paramname eq "northbc"){ |
|
111 |
$nBC = $tempnode->getFirstChild()->getNodeValue(); |
|
112 |
} |
|
113 |
if($paramname eq "southBoundingCoordinate"){ |
|
114 |
$sBC = $tempnode->getFirstChild()->getNodeValue(); |
|
115 |
} |
|
116 |
if($paramname eq "southbc"){ |
|
117 |
$sBC = $tempnode->getFirstChild()->getNodeValue(); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
if($keyword ne "" ){ |
|
122 |
$keyword = substr ($keyword, 1); |
|
123 |
} |
|
124 |
if($cName ne "" ){ |
|
125 |
$cName = substr ($cName, 1); |
|
126 |
} |
|
127 |
|
|
128 |
# print "$name, $title, ($cName), ($keyword), ($eBC,$wBC,$nBC,$sBC), $url?action=read&docid=$name&qformat=knb, \n"; |
|
129 |
if ($eBC ne "" && $nBC ne "" && $eBC ne "0" && $nBC ne "0") { |
|
130 |
print "$name $eBC $nBC $url?action=read&docid=$name&qformat=knb \n"; |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
#print $numberNodes; |
|
0 | 135 |
bin/metacat_to_shapefile.sh | ||
---|---|---|
1 |
#!/bin/sh -e |
|
2 |
|
|
3 |
|
|
4 |
############################################################################### |
|
5 |
# '$RCSfile$' |
|
6 |
# Authors: Matt Jones, Chad Berkley, Jivka Bojilova |
|
7 |
# Copyright: 2000 Regents of the University of California and the |
|
8 |
# National Center for Ecological Analysis and Synthesis |
|
9 |
# For Details: http://www.nceas.ucsb.edu/ |
|
10 |
# |
|
11 |
# '$Author$' |
|
12 |
# '$Date$' |
|
13 |
# '$Revision$' |
|
14 |
# |
|
15 |
# Build file for the Ant cross-platform build system for metacat |
|
16 |
# See http://jakarta.apache.org for details on Ant |
|
17 |
# |
|
18 |
# usage: ant [compile|jar|install|jdoc] |
|
19 |
# |
|
20 |
# This program is free software; you can redistribute it and/or modify |
|
21 |
# it under the terms of the GNU General Public License as published by |
|
22 |
# the Free Software Foundation; either version 2 of the License, or |
|
23 |
# (at your option) any later version. |
|
24 |
# |
|
25 |
# This program is distributed in the hope that it will be useful, |
|
26 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
# GNU General Public License for more details. |
|
29 |
# |
|
30 |
# You should have received a copy of the GNU General Public License |
|
31 |
# along with this program; if not, write to the Free Software |
|
32 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
33 |
############################################################################### |
|
34 |
|
|
35 |
## script to create a shapefile from metacat, and to be run nightly as a cronjob |
|
36 |
|
|
37 |
|
|
38 |
################### JUDITHS'S SETTINGS ######################################### |
|
39 |
#METACAT_URL=http://metacat.nceas.ucsb.edu/knb/servlet/metacat |
|
40 |
METACAT_URL=http://127.0.0.1:8080/knp/servlet/metacat |
|
41 |
METACAT_LOGIN=yeah |
|
42 |
METACAT_PASSWD=right |
|
43 |
|
|
44 |
TMP_DIR=/tmp |
|
45 |
|
|
46 |
METACAT_SHAPEFILE_RESOURCES=/usr/local/devtools/shapefile/metacat/ |
|
47 |
#METACAT_SHAPEFILE_RESOURCES=/home/harris/development/private/src/cpp/shapefile/metacat/ |
|
48 |
|
|
49 |
PERL_BIN=/usr/bin/perl |
|
50 |
|
|
51 |
POINTS_GEOCOORD=metacat_points_geocoord.txt |
|
52 |
POINTS_UTM=metacat_points_utm.txt |
|
53 |
|
|
54 |
SHAPEFILE_GEOCOORD=metacat_points_geocoord |
|
55 |
SHAPEFILE_UTM=metacat_points_utm |
|
56 |
|
|
57 |
#DIST_DIR=/home/harris/development/private/src/cpp/shapefile/metacat/data |
|
58 |
DIST_DIR=/var/www/html/mapserver/kruger/data/ |
|
59 |
############################################################################# |
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
################### JOHN'S SETTINGS ######################################### |
|
64 |
#METACAT_URL=http://dhcp84.nceas.ucsb.edu:8080/knp/servlet/metacat |
|
65 |
###METACAT_URL=http://metacat.nceas.ucsb.edu/knb/servlet/metacat |
|
66 |
|
|
67 |
#TMP_DIR=/tmp |
|
68 |
|
|
69 |
#METACAT_SHAPEFILE_RESOURCES=/home/harris/development/private/src/cpp/shapefile/metacat/ |
|
70 |
|
|
71 |
#PERL_BIN=/usr/bin/perl |
|
72 |
|
|
73 |
#POINTS_GEOCOORD=metacat_points_geocoord.txt |
|
74 |
#POINTS_UTM=metacat_points_utm.txt |
|
75 |
|
|
76 |
#SHAPEFILE_GEOCOORD=metacat_points_geocoord |
|
77 |
#SHAPEFILE_UTM=metacat_points_utm |
|
78 |
|
|
79 |
#DIST_DIR=/home/harris/development/private/src/cpp/shapefile/metacat/data |
|
80 |
############################################################################# |
|
81 |
|
|
82 |
|
|
83 |
## 1] get the counding coordinates from metacat |
|
84 |
$METACAT_SHAPEFILE_RESOURCES/get_eml.pl $METACAT_URL $METACAT_LOGIN $METACAT_PASSWD > $TMP_DIR/$POINTS_GEOCOORD |
|
85 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
86 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
87 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
88 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
89 |
cat $TMP_DIR/$POINTS_GEOCOORD |
|
90 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
91 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
92 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
93 |
echo "THE DATA RETRIEVED FROM METACAT START ON THE FOLLOWING LINE" |
|
94 |
|
|
95 |
|
|
96 |
## 2] create the shapefile [this will be in geocoordinates] |
|
97 |
$METACAT_SHAPEFILE_RESOURCES/metacat_shapefile $TMP_DIR/$POINTS_GEOCOORD $TMP_DIR/$SHAPEFILE_GEOCOORD |
|
98 |
|
|
99 |
## 3] convert the data to utm |
|
100 |
|
|
101 |
# delete the file if it exists |
|
102 |
if test -f $TMP_DIR/$POINTS_UTM; then |
|
103 |
rm $TMP_DIR/$POINTS_UTM |
|
104 |
fi |
|
105 |
|
|
106 |
cat $TMP_DIR/$POINTS_GEOCOORD | while read line |
|
107 |
do |
|
108 |
ID=`echo $line | awk '{print $1}'` |
|
109 |
LAT=`echo $line | awk '{print $3}'` |
|
110 |
LONG=`echo $line | awk '{print $2}'` |
|
111 |
URL=`echo $line | awk '{print $4}'` |
|
112 |
|
|
113 |
|
|
114 |
## the utm x,y's are switched here |
|
115 |
UTM=`$METACAT_SHAPEFILE_RESOURCES/coords/ll2utm $LAT $LONG | awk '{print $1, $2}'` |
|
116 |
Y=`echo $UTM | awk '{print $1}'` |
|
117 |
X=`echo $UTM | awk '{print $2}'` |
|
118 |
|
|
119 |
if test ! -d $X; then |
|
120 |
echo $ID $X $Y $URL >> $TMP_DIR/$POINTS_UTM |
|
121 |
fi |
|
122 |
done |
|
123 |
|
|
124 |
## 4] make a second shapefile -- this time in utm |
|
125 |
$METACAT_SHAPEFILE_RESOURCES/metacat_shapefile $TMP_DIR/$POINTS_UTM $TMP_DIR/$SHAPEFILE_UTM |
|
126 |
|
|
127 |
|
|
128 |
## 5] distribute the shapefiles |
|
129 |
cp $TMP_DIR/$SHAPEFILE_GEOCOORD* $DIST_DIR |
|
130 |
cp $TMP_DIR/$SHAPEFILE_UTM* $DIST_DIR |
|
131 |
|
|
132 |
|
|
133 |
## clean up |
|
134 |
rm core* |
|
135 |
|
|
136 |
|
|
0 | 137 |
Also available in: Unified diff
Filed used my the Metacat Spatial Option. Generally these files represent
the portion of the spatial option that harvests spatial elements from a
Metacat, and stores the elements as a shapefile on the file system. This
option, at this point, is pretty much independent of the metacat application.
This system requires Mapserver, and is run as a cron job.
metacat_to_shapefile.sh -- script that is called by the cron job and uses the
following code to create a shapefile with the spatial elements in the respective
metacat:
get_eml.pl -- connects to metacat and gets the spatial location data as points.
metacat_shapefile -- linux binary to write the shapefile