Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <?php
  2.  
  3. $db = pg_connect("host=172.31.4.61 port=5432 dbname=geoserver user=postgres password=ndem$123") or die ("cant");
  4.  
  5. $data_query = "SELECT row_to_json(fc) FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features";
  6. $data_query .= " FROM (SELECT 'Feature' As type";
  7. $data_query .= ", ST_AsGeoJSON(lg.geom)::json As geometry";
  8. $data_query .= ", row_to_json((SELECT l FROM (SELECT taluk) As l";
  9. $data_query .=" )) As properties";
  10. $data_query .= " FROM s50k.aptaluk50soi2001 As lg ) As f ) As fc";
  11.  
  12. $data = pg_query($db,$data_query);
  13.  
  14. while ($row_p = pg_fetch_row($data) )
  15. {
  16. $count = count($row_p);
  17. $y = 0;
  18. while ($y < $count)
  19. {
  20. $c_row = current($row_p);
  21. $lat_lon.= $c_row . ",";
  22. next($row_p);
  23. $y = $y + 1;
  24. }
  25. }
  26.  
  27. echo $lat_lon;
  28. ?>
  29.  
  30. <?php
  31.  
  32. $db = pg_connect("host=172.31.4.61 port=5432 dbname=geoserver user=postgres password=ndem$123") or die ("cant");
  33.  
  34. $mapa = "SELECT geom FROM s50d.aptirupatiff50dsc01042014";
  35.  
  36. $dbquery = pg_query($db,$mapa);
  37. //echo("hello");
  38.  
  39. $geojson = array( 'type' => 'FeatureCollection', 'features' => array());
  40.  
  41. while($row = pg_fetch_array($dbquery)){
  42.  
  43. $marker = array(
  44. 'type' => 'Feature',
  45. 'features' => array(
  46. 'type' => 'Feature',
  47. 'properties' => array(
  48. 'gid' => "serial"
  49.  
  50. )
  51.  
  52.  
  53. )
  54.  
  55. );
  56. array_push($geojson['features'], $marker['features']);
  57. }
  58. ?>
  59.  
  60. <?php
  61.  
  62. $db = pg_connect("host=172.31.4.61 port=5432 dbname=geoserver user=postgres password=ndem$123") or die ("cant");
  63.  
  64. $data_query = "select st_x(st_centroid(geom)) as long,st_y(st_centroid(geom)) as lat,taluk FROM s50k.aptaluk50soi2001";
  65.  
  66.  
  67. //$data_query = "SELECT ";
  68. //$data_query .= " ST_AsGeoJSON(lg.geom)::json As geometry";
  69. //$data_query .= ", row_to_json((SELECT l FROM (SELECT taluk) As l";
  70. //$data_query .=" )) As properties";
  71. //$data_query .= " FROM s50k.aptaluk50soi2001 As lg ";
  72.  
  73. $data = pg_query($db,$data_query);
  74.  
  75. $geojson = array(
  76. 'type' => 'FeatureCollection',
  77. 'features' => array()
  78.  
  79. );
  80. // while ($row_p = pg_fetch_row($data) )
  81.  
  82. while($edge=pg_fetch_assoc($data)) {
  83. $feature = array(
  84. 'type' => 'Feature',
  85. 'geometry' => array('type'=>$edge['lat'],
  86. 'coordinates'=>$edge['long']),
  87.  
  88. 'crs' => array(
  89. 'type' => 'lat',
  90. 'properties' => $edge['taluk']
  91. ),
  92. 'properties' => array(
  93. 'taluk' => $edge['taluk']
  94. )
  95.  
  96. );
  97.  
  98. array_push($geojson['features'], $feature);
  99.  
  100. }
  101. echo json_encode(array( $geojson));
  102. //"{"type":"Feature","geometry":{"type":"Point","coordinates":[83.15783,17.6501960000001]},"properties":{"poi_nme":"Shree Latha Medicals"}}"
  103. ?>
  104.  
  105. <?php
  106.  
  107. $db = pg_connect("host=172.31.4.61 port=5432 dbname=geoserver user=postgres password=ndem$123") or die ("cant");
  108.  
  109. $data_query = "select ST_AsGeoJSON(lg.geom)::json As geometry , row_to_json((SELECT l FROM (SELECT taluk) As l )) As properties FROM s50k.aptaluk50soi2001 As lg ";
  110.  
  111.  
  112. //$data_query = "SELECT ";
  113. //$data_query .= " ST_AsGeoJSON(lg.geom)::json As geometry";
  114. //$data_query .= ", row_to_json((SELECT l FROM (SELECT taluk) As l";
  115. //$data_query .=" )) As properties";
  116. //$data_query .= " FROM s50k.aptaluk50soi2001 As lg ";
  117.  
  118. $data = pg_query($db,$data_query);
  119.  
  120. $geojson = array(
  121. 'type' => 'FeatureCollection',
  122. 'features' => array()
  123.  
  124. );
  125. // while ($row_p = pg_fetch_row($data) )
  126.  
  127. while($edge=pg_fetch_assoc($data)) {
  128. $feature = array(
  129. 'type' => 'Feature',
  130. 'geometry' => array( 'type' => 'MultiPolygon',
  131. 'coordinates'=>$edge['geometry']),
  132.  
  133. 'properties' => array(
  134. 'taluk' => $edge['properties']
  135. )
  136.  
  137. );
  138.  
  139. array_push($geojson['features'], $feature);
  140.  
  141. }
  142. echo json_encode(array( $geojson));
  143. //"{"type":"Feature","geometry":{"type":"Point","coordinates":[83.15783,17.6501960000001]},"properties":{"poi_nme":"Shree Latha Medicals"}}"
  144. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement