Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. ogr2ogr -f "ESRI Shapefile" shapefilename.shp PG:"host=host user=user
  2. dbname=databasename password=password" -sql "SELECT the_geom FROM tablename"
  3.  
  4. COPY yourNewTableName (lat, long, name, other)
  5. FROM '/path/yourCSVfile.csv' CSV;
  6.  
  7. SELECT addgeometrycolumn('public','yourNewTableName ','the_geom',4326,'POINT');
  8.  
  9. UPDATE yourNewTableName SET the_geom = GeometryFromText('POINT('||lat||' '||long||')',4326);
  10.  
  11. pgsql2shp -s 4326 -W latin5 -f newSHP -h localhost -u username -P password
  12. yourdataBaseName "SELECT * FROM yourNewTableName"
  13.  
  14. "Takes a CSV as input, write a SHP as output"
  15. import arcpy
  16. import os
  17.  
  18. csv_input = r"C:pathtoinput.csv"
  19. shp_output_dir = os.path.dirname(csv_input)
  20. temp_layer = os.path.splitext(os.path.basename(csv_input))[0] # == "input"
  21.  
  22. # OP NOTE - you say "coordinates" and I assumed you meant WGS84 latitude/longitude. If not, this is NOT your projection
  23. WGS84_PROJ = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];IsHighPrecision"
  24. # OP NOTE - if the latitude/longitude fields aren't named as such you'll need to update this
  25. arcpy.MakeXYEventLayer_management(csv_input, "LATITUDE", "LONGITUDE", temp_layer, WGS84_PROJ)
  26. # OP note: this exports a feature to a directory as a shapefile.
  27. # You don't specify the name directly, it's just taken from the existing `temp_layer` name
  28. arcpy.FeatureClassToShapefile_conversion(temp_layer, shp_output_dir)
  29. arcpy.Delete_management(temp_layer) # clean up layer, for completeness
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement