Created
October 12, 2011 22:12
-
-
Save eightysteele/1282803 to your computer and use it in GitHub Desktop.
hackery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rename .dbf file temporarily | |
| dbf_filename = '%s.dbf' % sf | |
| dbf_filename_temp = '%s~' % dbf_filename_temp | |
| os.rename(dbf_filename, dbf_filename_temp) | |
| # Create the .dbf blank (it has no fields) | |
| w = shapefile.Writer(shapefile.POLYGONM) | |
| w.poly(parts=[[[1,5],[5,5],[5,1],[3,3],[1,1]]]) | |
| w.save(dbf_filename) | |
| # Get the projection SRID (default 3857) | |
| proj = open('%s.prj' % sf, 'r').read() | |
| srs = osr.SpatialReference() | |
| srs.ImportFromESRI([proj]) | |
| srs.AutoIdentifyEPSG() | |
| srid = srs.GetAuthorityCode(None) | |
| if srid == None: | |
| srid = 3857 | |
| # Create SQL file that contains the_geom | |
| sql_file = open('%s.sql' % f, 'wr+') | |
| command = 'shp2pgsql -I -D -d -s %s %s polygons > %s.sql' % (srid, sf, sf) | |
| args = shlex.split(command) | |
| subprocess.call(args, stdout=sql_file) | |
| # Parse SQL file for a list of the_geom data | |
| sql_file.seek(0) | |
| the_geom = sql_file.read().split('\n')[8:-4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment