Changeset 33217 for main/trunk/greenstone2/perllib/doc.pm
- Timestamp:
- 2019-06-24T16:41:04+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/doc.pm
r33185 r33217 1111 1111 # } 1112 1112 1113 1114 # for every GPS.mapOverlay/sectionID (but sadly not for every doc, let alone every collection),1115 # we use a map to ensure uniqueness of CoordShorts for optimisation purposes1116 # That way we don't end up with the same CoordShort values a large number of times in the index1117 # We only get any savings with GPS.mapOverlay when using this map, not for "Latitude" and "Longitude" metadata1118 my $unique_coordshort_map = {};1119 1120 1121 1113 #If the metadata value is either a latitude or a longitude value then we want to save a shortened version for spacial searching purposes 1122 1114 if ($field =~ m/^(.+\.)?Latitude$/ || $field =~ m/^(.+\.)?Longitude$/) … … 1153 1145 1154 1146 #Only add the metadata if it has not already been added 1155 my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no side-effects.) 1147 my $metaMap = $self->get_metadata_hashmap($section); # metaMap not used and called function has no apparent side-effects, 1148 # but this line appears important for ensuring uniqueness of (Latitude, value) meta 1149 # in the section. Also for LatShort, Longitude, LngShort. 1156 1150 } 1157 1151 … … 1159 1153 # if we are dealing with Longitude meta, we should 1. have Latitude meta too; 2. already have processed Latitude meta 1160 1154 # in that case, add both Lat and Lng of this section as a Coordinate meta 1161 my $latitude = $self->get_metadata_element ($section, "Latitude"); 1162 # TODO: would like all Longitude info together followed by all Coordinate info, but the following will add all coord info meta and end of this function will add Longitude meta 1163 $self->processCoordinate($section, $latitude, $value, $unique_coordshort_map); # value is Longitude 1155 my $latitude = $self->get_metadata_element ($section, "Latitude"); 1156 my $longitude = $value; 1157 # TODO: would like all Longitude meta placed together, followed by all Coordinate meta, 1158 # but the following will add all such coord meta to the doc object and the end of this function will add Longitude meta 1159 $self->processCoordinate($section, $latitude, $longitude); 1164 1160 } 1165 1161 } 1166 1162 1167 1163 elsif($field eq "GPS.mapOverlay") { # then the value is a JSON string 1168 1169 # TODO: How can we prevent GPS.mapOverlay from being processed 4 or so times by buildcol.pl?? 1170 # Once for each pass (dummy, sidx, didx for lucene, info db pass) 1171 1164 1172 1165 if($cmd_line_mode eq "buildcol") { 1173 1166 #my $metaMap = $self->get_metadata_hashmap($section); ## TODO: Check if necessary to avoid duplication of <Coordinate> meta in index\text\<coll>.jdb … … 1177 1170 1178 1171 1179 print STDERR "GPS.mapOverlay before decod e, val:" . $value . "\n";1172 print STDERR "GPS.mapOverlay before decoding, val = " . $value . "\n"; 1180 1173 1181 1174 # TODO html decode? … … 1183 1176 $value =~ s@]@]@g; 1184 1177 $value =~ s@"@"@g; 1185 print STDERR "GPS.mapOverlay after decod e, val:" . $value . "\n";1178 print STDERR "GPS.mapOverlay after decoding, val = " . $value . "\n"; 1186 1179 1187 1180 my $json_array = decode_json $value; … … 1197 1190 #print STDERR "Found a circle:\n" . &printShape($json, $shape); 1198 1191 1199 # Work out bounding box1192 # work out bounding box 1200 1193 # want the inverse of this useful page: 1201 1194 # https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters 1202 # https://www.geodatasource.com/developers/javascript 1203 1204 1205 # for now, just process the circle centre 1206 #my $centre = $shape->{"center"}; 1207 #$self->processLatOrLng($section_ptr, "Latitude", $centre->{"lat"}); 1208 #$self->processLatOrLng($section_ptr, "Longitude", $centre->{"lng"}); 1209 1195 # https://www.geodatasource.com/developers/javascript 1210 1196 1211 1197 # Dr Bainbridge wants us to use: https://gis.stackexchange.com/questions/5821/calculating-latitude-longitude-x-miles-from-point 1212 # But we're using the rule of thumb here, since for N,E,S,W it works out the same:1198 # Since for N,E,S,W the following works out the same as above link, we're using the rule of thumb in the following: 1213 1199 # https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters 1214 1200 # which states … … 1229 1215 1230 1216 # our latitude and longitude values are in degrees. But cos and sin etc in perl and generally all prog languages 1231 # all expect their angle to be in radians. So need to convert from degree to radians before we can take the cos eof it.1217 # all expect their angle to be in radians. So need to convert from degree to radians before we can take the cos of it. 1232 1218 my $centre_lat_radians = $self->degreesToRadians($centre_lat); 1233 1219 my $cos_in_radians = cos($centre_lat_radians); … … 1238 1224 print STDERR "### lng_west $lng_west\n"; 1239 1225 1240 1241 1242 1226 my $cos_lat = cos($centre_lat); 1243 1227 print STDERR "cos $centre_lat is $cos_lat\n"; 1244 1228 1245 $self->processCoordinate($section, $lat_north, $lng_east , $unique_coordshort_map);1246 $self->processCoordinate($section, $lat_south, $lng_east , $unique_coordshort_map);1247 $self->processCoordinate($section, $lat_south, $lng_west , $unique_coordshort_map);1248 $self->processCoordinate($section, $lat_north, $lng_west , $unique_coordshort_map);1229 $self->processCoordinate($section, $lat_north, $lng_east); 1230 $self->processCoordinate($section, $lat_south, $lng_east); 1231 $self->processCoordinate($section, $lat_south, $lng_west); 1232 $self->processCoordinate($section, $lat_north, $lng_west); 1249 1233 1250 1234 } … … 1252 1236 print STDERR "@@ MARKER FOUND WITH LAT: " . $shape->{"position"}->{"lat"} . "\n"; 1253 1237 print STDERR "@@ MARKER FOUND WITH LNG: " . $shape->{"position"}->{"lng"} . "\n"; 1254 $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"} , $unique_coordshort_map);1238 $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"}); 1255 1239 } 1256 1240 elsif ($type eq "polyline" || $type eq "polygon") { 1257 1241 my $path_array = $shape->{"path"}; 1258 1242 foreach my $position (@$path_array) { 1259 $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"} , $unique_coordshort_map);1243 $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"}); 1260 1244 } 1261 1245 } … … 1263 1247 1264 1248 my $bounds = $shape->{"bounds"}; 1265 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"east"} , $unique_coordshort_map);1266 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"east"} , $unique_coordshort_map);1267 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"west"} , $unique_coordshort_map);1268 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"west"} , $unique_coordshort_map);1249 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"east"}); 1250 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"east"}); 1251 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"west"}); 1252 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"west"}); 1269 1253 } 1270 1254 … … 1272 1256 #} 1273 1257 } 1274 1275 # We haven't yet written out any Coordshort meta! Write those out now,1276 # since we've now finally ensured they're all unique CoordShort meta for this GPS.mapOverlay at least.1277 foreach my $coordshort (keys %$unique_coordshort_map) {1278 1279 #print STDERR "@@@@ creating new coordshort: $coordshort\n";1280 push (@{$section_ptr->{'metadata'}}, ["CoordShort", $coordshort ]);1281 }1282 1283 1258 } # end GPS.mapOverlay meta 1284 1259 … … 1311 1286 my $pretty_print_shape = $json->pretty->encode( $shape ); 1312 1287 print STDERR "Shape: $pretty_print_shape\n"; 1313 #&printShape($shape); 1314 } 1315 1316 } 1317 1318 # Beware: this method now ONLY writes out the Coordinate meta, but not the CoordShorts 1319 # At method's end, the CoordShorts are stored in the $unique_coordshort_map (for optimisation), 1320 # ready to be added to the doc section's meta once all Coordinates in a GPS.mapOverlay are done being processed. 1288 } 1289 1290 } 1291 1292 # For the (lat, lng) coordinate given, 1293 # attaches Coordinate and multiple CoordShort (different precision level) metadata to the doc object 1321 1294 sub processCoordinate { 1322 1295 my $self = shift (@_); 1323 my ($section, $latitude, $longitude , $unique_coordshort_map) = @_;1296 my ($section, $latitude, $longitude) = @_; 1324 1297 1325 1298 my $section_ptr = $self->_lookup_section($section); … … 1350 1323 } 1351 1324 1352 # We have to deal with 0 decimal places for either lat or lng, or no dec places for only one of them 1353 # And we have to store all combinations of lats and lngs as CoordShort. 1354 1355 #my $name = "CoordShort"; 1356 #push (@{$section_ptr->{'metadata'}}, [$name, "$latBeforeDec$lat_direction $lngBeforeDec$lng_direction"]); 1357 1358 my @lat_array = ("$latBeforeDec$lat_direction"); 1359 my @lng_array = ("$lngBeforeDec$lng_direction"); 1360 1325 1326 my $name = "CoordShort"; 1327 push (@{$section_ptr->{'metadata'}}, [$name, "$latBeforeDec$lat_direction $lngBeforeDec$lng_direction"]); 1328 1361 1329 for(my $i = 2; $i <= 4; $i++) 1362 1330 { … … 1364 1332 my $lngDecPlaces = (length($lngAfterDec) >= $i) ? substr($lngAfterDec, 0, $i) : ""; 1365 1333 1366 push(@lat_array, $latBeforeDec . $lat_direction. $latDecPlaces) unless $latDecPlaces eq ""; 1367 push(@lng_array, $lngBeforeDec . $lng_direction. $lngDecPlaces) unless $lngDecPlaces eq ""; 1368 1369 #push (@{$section_ptr->{'metadata'}}, [$name, 1370 # $latBeforeDec . $lat_direction. $latDecPlaces . " " . $lngBeforeDec . $lng_direction. $lngDecPlaces]); 1334 push (@{$section_ptr->{'metadata'}}, [$name, 1335 $latBeforeDec . $lat_direction. $latDecPlaces . " " . $lngBeforeDec . $lng_direction. $lngDecPlaces]); 1371 1336 1372 } 1373 1374 for(my $i = 0; $i < scalar(@lat_array); $i++) { 1375 for(my $j = 0; $j < scalar(@lng_array); $j++) { 1376 #push (@{$section_ptr->{'metadata'}}, [$name, $lat_array[$i] . " " . $lng_array[$j] ]); 1377 my $coordshort = $lat_array[$i] . " " . $lng_array[$j]; 1378 $unique_coordshort_map->{$coordshort} = "1"; # just store it 1379 1380 #print STDERR "@@@@ pushed new value: " . $coordshort . " into map\n"; 1381 1382 } 1383 } 1384 1385 1337 } 1386 1338 1387 1339 #Only add the metadata if it has not already been added 1388 #my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no side-effects.)1340 #my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no apparent side-effects.) 1389 1341 } 1390 1342
Note:
See TracChangeset
for help on using the changeset viewer.