Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. {'geojson': "[{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'ge
  2. ometry': {'type': 'Point', 'coordinates': [74.886779, 33.571307]}, 'properties':
  3. {'rastvalues': 9, 'id': 1, 'species': 'Poa pratensis L.'}}, {'type': 'Feature',
  4. 'geometry': {'type': 'Point', 'coordinates': [75.015556, 33.588333]}, 'properti
  5. es': {'rastvalues': 9, 'id': 2, 'species': 'Poa pratensis L.'}}, {'type': 'Featu
  6. re', 'geometry': {'type': 'Point', 'coordinates': [75.06231, 33.592838]}, 'prope
  7. rties': {'rastvalues': 9, 'id': 3, 'species': 'Phleum alpinium L.'}}, {'type': '
  8. Feature', 'geometry': {'type': 'Point', 'coordinates': [75.196944, 33.550556]},
  9. 'properties': {'rastvalues': 12, 'id': 4, 'species': 'Pinus roxburghii Sargent'}
  10. }, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [75.224722,
  11. 33.540278]}, 'properties': {'rastvalues': 12, 'id': 5, 'species': 'Pinus roxburg
  12. hii Sargent'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates':
  13. [75.103889, 34.485833]}, 'properties': {'rastvalues': 3, 'id': 6, 'species': 'P
  14. inus roxburghii Sargent'}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'c
  15. oordinates': [75.143611, 34.536667]}, 'properties': {'rastvalues': 3, 'id': 7, '
  16. species': 'Phleum alpinium L.'}}, {'type': 'Feature', 'geometry': {'type': 'Poin
  17. t', 'coordinates': [74.329145, 33.818276]}, 'properties': {'rastvalues': 9, 'id'
  18. : 8, 'species': 'Pinus roxburghii Sargent'}}]}]"}
  19.  
  20. function main_map_init (map, options) {
  21. var promise = $.getJSON('{% url "datapot" %}');
  22. // Download GeoJSON via Ajax
  23. promise.then(function(data) {
  24. var allbusinesses = L.geoJson(data);
  25. var cafes = L.geoJson(data, {
  26. filter: function(feature, layer) {
  27. return feature.properties.rastvalues == "3";
  28. },
  29. pointToLayer: function(feature, latlng) {
  30. return L.marker(latlng, {
  31.  
  32. }).on('mouseover', function() {
  33. this.bindPopup(feature.properties.species).openPopup();
  34. });
  35. }
  36. });
  37.  
  38. var others = L.geoJson(data, {
  39. filter: function(feature, layer) {
  40. return feature.properties.rastvalues != "3";
  41. },
  42. pointToLayer: function(feature, latlng) {
  43. return L.marker(latlng, {
  44. }).on('mouseover', function() {
  45. this.bindPopup(feature.properties.species).openPopup();
  46. });
  47. }
  48. });
  49. map.fitBounds(allbusinesses.getBounds(), {
  50. padding: [50, 50]
  51. });
  52. cafes.addTo(map)
  53. others.addTo(map)
  54.  
  55. });
  56. }
  57. </script>
  58.  
  59. feature = Object {type: "Feature", id: 1,properties: Object, geometry: Object}, layer = undefined
  60.  
  61. def extract_raster_points(request):
  62. conn = psycopg2.connect(dbname="geodjango",host='localhost',user='postgres', password='postgres', port=5433)
  63. cur=conn.cursor()
  64. dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  65. res=dict_cur.execute("""SELECT row_to_json(fc) FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features FROM (SELECT 'Feature' As type, ST_AsGeoJSON(lg.geom)::json As geometry ,row_to_json((SELECT l FROM (SELECT id, species,rastvalues) As l )) As properties FROM pft_account As lg ) As f ) As fc;""")
  66.  
  67. points=dict_cur.fetchone()
  68. #datapot = json.loads(str(points))
  69. datapot = json.loads(json.dumps(points))
  70. datapotg=datapot[0]
  71. print(datapotg)
  72. return JsonResponse(datapotg,safe=False)
  73.  
  74. {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [74.886779, 33.571307]}, "properties": {"rastvalues": 9, "id": 1, "species": "Poa pratensis L."}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.015556, 33.588333]}, "properties": {"rastvalues": 9, "id": 2, "species": "Poa pratensis L."}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.06231, 33.592838]}, "properties": {"rastvalues": 9, "id": 3, "species": "Phleum alpinium L."}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.196944, 33.550556]},"properties": {"rastvalues": 12, "id": 4, "species": "Pinus roxburghii Sargent"}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.224722,33.540278]}, "properties": {"rastvalues": 12, "id": 5, "species": "Pinus roxburghii Sargent"}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.103889, 34.485833]}, "properties": {"rastvalues": 3, "id": 6, "species": "Pinus roxburghii Sargent"}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [75.143611, 34.536667]}, "properties": {"rastvalues": 3, "id": 7, "species": "Phleum alpinium L."}}, {"type": "Feature", "geometry": {"type": "Point", "coordinates": [74.329145, 33.818276]}, "properties": {"rastvalues": 9, "id": 8, "species": "Pinus roxburghii Sargent"}}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement