savePart.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. include 'db.php';
  3. ini_set('display_errors', 1);
  4. ini_set('error_reporting', E_ALL);
  5. $obj = pg_escape_string($_POST['obj']);
  6. $name = pg_escape_string($_POST['name']);
  7. $note = pg_escape_string($_POST['note']);
  8. $date = pg_escape_string($_POST['date']);
  9. $type = pg_escape_string($_POST['type']);
  10. //zpracovani objektu souradnic jako priprava na vytvoreni linestringu
  11. $coords = explode('{', $obj);
  12. $parts = array();
  13. foreach ($coords as $key => $value) {
  14. if($key==0) {
  15. continue;
  16. } else {
  17. $parts[$key-1] = explode("g", $value);
  18. $pos_start = strpos($parts[$key-1][0], ":");
  19. $pos_end = strpos($parts[$key-1][0], ",");
  20. $parts[$key-1][0] = substr($parts[$key-1][0], $pos_start+1, $pos_end - $pos_start-1);
  21. $pos_start = strpos($parts[$key-1][1], ":");
  22. $pos_end = strpos($parts[$key-1][1], "}");
  23. $parts[$key-1][1] = substr($parts[$key-1][1], $pos_start+1, $pos_end - $pos_start-1);
  24. }
  25. }
  26. //vytvoreni linestringu
  27. $linestring = "LINESTRING";
  28. foreach ($parts as $key=>$part) {
  29. if($key==0){
  30. $linestring .= "(";
  31. } else {
  32. $linestring .= ",";
  33. }
  34. $linestring .= $part[1]." ".$part[0];
  35. }
  36. $linestring .= ")";
  37. $sql = "INSERT INTO hicheck.parts (hi_user_id, note, geom, date, type)
  38. VALUES ('$name', '$note', ST_GeomFromText('$linestring', 4326), '$date', '$type')";
  39. pg_query($db, $sql);
  40. exit(pg_last_error($db));