export_refpoints.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /* Converts a set of refpoints to a JSON file suitable for Django import. */
  3. /* Pass one or several refpoint PHP files as arguments. */
  4. function convert_refpoints($refpoint_file) {
  5. $ref_points = array();
  6. include($refpoint_file);
  7. $result = array();
  8. foreach ($ref_points as $name => $attributes) {
  9. $item = array("model" => "panorama.referencepoint");
  10. $item["fields"] = array("name" => $name,
  11. "latitude" => $attributes[0],
  12. "longitude" => $attributes[1],
  13. "altitude" => $attributes[2]);
  14. $result[] = $item;
  15. }
  16. return $result;
  17. }
  18. function convert_all_refpoints($argv) {
  19. $all_refpoints = array();
  20. foreach (array_slice($argv, 1) as $refpoint_file) {
  21. $all_refpoints = array_merge($all_refpoints, convert_refpoints($refpoint_file));
  22. }
  23. print(json_encode($all_refpoints, JSON_PRETTY_PRINT));
  24. }
  25. if (isset($argv[1])) {
  26. convert_all_refpoints($argv);
  27. } else {
  28. printf("Usage: %s <ref_points_1.php> [ref_points_2.php [...]]\n", $argv[0]);
  29. }
  30. ?>