Advertisement
Guest User

Geojson file generation

a guest
Feb 17th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DB_NAME='postgres'
  4. USER='postgres'
  5. BATCH_SIZE=10 # Only fetch 10 records for testing
  6. OUTPUT_DIR='/home/ec2-user/data'
  7. CONTAINER_NAME='postgresql' # Your actual PostgreSQL container name
  8.  
  9. # Ensure the output directory exists
  10. mkdir -p $OUTPUT_DIR
  11.  
  12. # Output file path
  13. HOST_OUTPUT_FILE="${OUTPUT_DIR}/test_geocoded_data.geojson"
  14.  
  15. # Run query for only 10 records
  16. docker exec -i $CONTAINER_NAME psql -U $USER -d $DB_NAME -t -A -c "
  17. SELECT jsonb_pretty(jsonb_build_object(
  18. 'type', 'FeatureCollection',
  19. 'features', COALESCE(
  20. jsonb_agg(
  21. jsonb_build_object(
  22. 'type', 'Feature',
  23. 'geometry', ST_AsGeoJSON(geom)::jsonb,
  24. 'properties', jsonb_build_object(
  25. 'owner_last_name', owner_last_name,
  26. 'owner_first_name', owner_first_name,
  27. 'owner_city', owner_city,
  28. 'owner_state', owner_state,
  29. 'owner_zip', owner_zip,
  30. 'amount', amount,
  31. 'holder_name', holder_name,
  32. 'po_box', po_box
  33. )
  34. )
  35. ), '[]'::jsonb -- Correct placement of closing parentheses
  36. )
  37. ))
  38. FROM (
  39. SELECT geom, owner_last_name, owner_first_name, owner_city, owner_state, owner_zip, amount, holder_name, po_box
  40. FROM unclaimed_property
  41. WHERE geom IS NOT NULL
  42. LIMIT $BATCH_SIZE
  43. ) t" > $HOST_OUTPUT_FILE
  44.  
  45. echo "Exported 10 records to $HOST_OUTPUT_FILE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement