def download_file(self):
     tmp = tempfile.mkdtemp()
     wget(self.url, cwd=tmp) or die("Could not download %s" % self.url)
     zip_path = os.path.join(tmp, 'City.zip')
     unzip(zip_path, cwd=tmp) or die("failed to unzip %s" % tmp)
     shapefile = os.path.join(tmp, 'City.shp')
     return shapefile
    def handle(self, *args, **options):
        # First we download a bunch of zipfiles of TIGER data.
        HERE = os.getcwd()
        print "Working directory is", HERE
        OUTDIR = os.path.join(HERE, 'tiger_data')
        BASEURL='ftp://ftp2.census.gov/geo/tiger/TIGER2010'
        # 25 = MA; 25025 = Suffolk County, MA.
        ZIPS = ("PLACE/2010/tl_2010_25_place10.zip",
                "EDGES/tl_2010_25025_edges.zip",
                "FACES/tl_2010_25025_faces.zip",
                "FEATNAMES/tl_2010_25025_featnames.zip"
                )
        makedirs(OUTDIR) or die("couldn't create directory %s" % OUTDIR)
        for fname in ZIPS:
            wget('%s/%s' % (BASEURL, fname), cwd=OUTDIR) or die(
                "Could not download %s/%s" % (BASEURL, fname))

        import glob
        for fname in glob.glob(os.path.join(OUTDIR, '*zip')):
            unzip(fname, cwd=OUTDIR) or die("Could not unzip %s" % fname)
        print "Shapefiles unzipped in %s" % OUTDIR

        # Now we load them into our blocks table.
        from ebpub.streets.blockimport.tiger import import_blocks
        from ebpub.utils.geodjango import get_default_bounds
        print "Importing blocks, this may take several minutes ..."

        # Passing --city means we skip features labeled for other cities.

        importer = import_blocks.TigerImporter(
            '%s/tl_2010_25025_edges.shp' % OUTDIR,
            '%s/tl_2010_25025_featnames.dbf' % OUTDIR,
            '%s/tl_2010_25025_faces.dbf' % OUTDIR,
            '%s/tl_2010_25_place10.shp' % OUTDIR,
            encoding='utf8',
            filter_bounds=get_default_bounds(),
            filter_city='BOSTON',
            reset=options['reset'])
        num_created, num_existing = importer.save()
        print "Created %d blocks (%d existing)" % (num_created, num_existing)

        #########################

        print "Populating streets and fixing addresses, these can take several minutes..."

        #cd $SOURCE_ROOT/ebpub/ebpub/streets/bin || die

        # Note these scripts should be run ONCE, in this order,
        # after you have imported *all* your blocks.

        from ebpub.streets.bin import populate_streets
        populate_streets.main(['-v', '-v', '-v', '-v', 'streets'])
        populate_streets.main(['-v', '-v', '-v', '-v', 'block_intersections'])
        populate_streets.main(['-v', '-v', '-v', '-v', 'intersections'])
        print "Done."
    def handle(self, *args, **options):
        # First we download a bunch of zipfiles of TIGER data.
        HERE = os.getcwd()
        print "Working directory is", HERE
        OUTDIR = os.path.join(HERE, 'tiger_data')
        BASEURL='ftp://ftp2.census.gov/geo/tiger/TIGER2010'
        # 25 = MA; 25025 = Suffolk County, MA.
        ZIPS = ("PLACE/2010/tl_2010_25_place10.zip",
                "EDGES/tl_2010_25025_edges.zip",
                "FACES/tl_2010_25025_faces.zip",
                "FEATNAMES/tl_2010_25025_featnames.zip"
                )
        makedirs(OUTDIR) or die("couldn't create directory %s" % OUTDIR)
        for fname in ZIPS:
            wget('%s/%s' % (BASEURL, fname), cwd=OUTDIR) or die(
                "Could not download %s/%s" % (BASEURL, fname))

        import glob
        for fname in glob.glob(os.path.join(OUTDIR, '*zip')):
            unzip(fname, cwd=OUTDIR) or die("Could not unzip %s" % fname)
        print "Shapefiles unzipped in %s" % OUTDIR

        # Now we load them into our blocks table.
        from ebpub.streets.blockimport.tiger import import_blocks
        from ebpub.utils.geodjango import get_default_bounds
        print "Importing blocks, this may take several minutes ..."

        # Passing --city means we skip features labeled for other cities.

        importer = import_blocks.TigerImporter(
            '%s/tl_2010_25025_edges.shp' % OUTDIR,
            '%s/tl_2010_25025_featnames.dbf' % OUTDIR,
            '%s/tl_2010_25025_faces.dbf' % OUTDIR,
            '%s/tl_2010_25_place10.shp' % OUTDIR,
            encoding='utf8',
            filter_bounds=get_default_bounds(),
            filter_city='BOSTON')
        num_created = importer.save()
        print "Created %d blocks" % num_created

        #########################

        print "Populating streets and fixing addresses, these can take several minutes..."

        #cd $SOURCE_ROOT/ebpub/ebpub/streets/bin || die

        # Note these scripts should be run ONCE, in this order,
        # after you have imported *all* your blocks.

        from ebpub.streets.bin import populate_streets
        populate_streets.main(['-v', '-v', '-v', '-v', 'streets'])
        populate_streets.main(['-v', '-v', '-v', '-v', 'block_intersections'])
        populate_streets.main(['-v', '-v', '-v', '-v', 'intersections'])
        print "Done."
    def handle(self, *args, **options):
        HERE = os.getcwd()
        print "Working directory is", HERE
        ZIP_SERVER="http://developer.openblockproject.org/raw-attachment/ticket/62"
        ZIP_FILE="bozip.zip"
        ZIP_URL="%s/%s" % (ZIP_SERVER, ZIP_FILE)
        ZIP_FOLDER= os.path.join(HERE, 'zip_data')
        makedirs(ZIP_FOLDER) or die("couldn't create %s" % ZIP_FOLDER)

        print "Downloading zip code data..."
        wget(ZIP_URL, cwd=ZIP_FOLDER) or die("Could not download %s" % ZIP_URL)
        zip_path = os.path.join(ZIP_FOLDER, ZIP_FILE)
        unzip(zip_path, cwd=ZIP_FOLDER) or die("failed to unzip %s" % zip_path)

        print "Importing zip codes..."
        from ebpub.db.bin import import_zips
        import_zips.main([ZIP_FOLDER, '-v'])
Example #5
0
    def handle(self, *args, **options):
        HERE = os.getcwd()
        print "Working directory is", HERE
        ZIP_SERVER = "http://developer.openblockproject.org/raw-attachment/ticket/62"
        ZIP_FILE = "bozip.zip"
        ZIP_URL = "%s/%s" % (ZIP_SERVER, ZIP_FILE)
        ZIP_FOLDER = os.path.join(HERE, 'zip_data')
        makedirs(ZIP_FOLDER) or die("couldn't create %s" % ZIP_FOLDER)

        print "Downloading zip code data..."
        wget(ZIP_URL, cwd=ZIP_FOLDER) or die("Could not download %s" % ZIP_URL)
        zip_path = os.path.join(ZIP_FOLDER, ZIP_FILE)
        unzip(zip_path, cwd=ZIP_FOLDER) or die("failed to unzip %s" % zip_path)

        print "Importing zip codes..."
        from ebpub.db.bin import import_zips
        import_zips.main([ZIP_FOLDER, '-v'])
Example #6
0
    def handle(self, *args, **options):
        HERE = os.getcwd()
        print "Working directory is", HERE

        HOOD_SERVER = "http://developer.openblockproject.org/raw-attachment/ticket/62"
        HOOD_FILE = "Planning_districts_revised.zip"
        HOOD_URL = "%s/%s" % (HOOD_SERVER, HOOD_FILE)
        HOOD_FOLDER = os.path.join(HERE, 'neighborhood_data')

        print "Downloading neighborhood data..."
        makedirs(HOOD_FOLDER) or die("couldn't create %s" % HOOD_FOLDER)
        wget(HOOD_URL, cwd=HOOD_FOLDER) or die(
            "Could not download %s" % HOOD_URL)
        hood_path = os.path.join(HOOD_FOLDER, HOOD_FILE)
        unzip(hood_path, cwd=HOOD_FOLDER) or die(
            "Could not unzip %s" % hood_path)

        print "Importing neighborhoods..."
        from ebpub.db.bin import import_hoods
        import_hoods.main(['-v', '-n', 'PD', HOOD_FOLDER])
        print "Done."
 def fetch_files(self, zip_dir):
     orig_cwd = os.getcwd()
     if zip_dir:
         download = not os.path.exists(zip_dir)
         if download:
             os.makedirs(zip_dir)
     else:
         zip_dir = tempfile.mkdtemp()
         download = True
     self.zip_dir = zip_dir
     os.chdir(zip_dir)
     if download:
         print 'Download data files to %s' % zip_dir
         for k, v in self.datafiles.items():
             fetch_name = '%s/%s/%s.zip' % (v['base_url'], v['path'], v['file_name'])
             wget(fetch_name) or die('Could not download %s' % fetch_name)
         for fname in glob.glob('*zip'):
             unzip(fname) or die('Could not unzip %s' % fname)
         print "Shapefiles unzipped in %s" % zip_dir
     os.chdir(orig_cwd)
     return zip_dir
    def handle(self, *args, **options):
        
        TMP = tempfile.mkdtemp()
        print 'Download TIGER data to %s' % TMP
        os.chdir(TMP)
        
        ZIP_SERVER = "http://www2.census.gov/geo/tiger/TIGER2009/37_NORTH_CAROLINA/"
        ZIP_FILE = "tl_2009_37_zcta5.zip"
        ZIP_URL = "%s/%s" % (ZIP_SERVER, ZIP_FILE)
        ZIP_FOLDER = os.path.join(TMP, 'zip_data')
        makedirs(ZIP_FOLDER) or die("couldn't create %s" % ZIP_FOLDER)

        print "Downloading zip code data..."
        wget(ZIP_URL, cwd=ZIP_FOLDER) or die("Could not download %s" % ZIP_URL)
        zip_path = os.path.join(ZIP_FOLDER, ZIP_FILE)
        unzip(zip_path, cwd=ZIP_FOLDER) or die("failed to unzip %s" % zip_path)

        print "Importing zip codes..."
        from ebpub.db.bin import import_zips
        import_zips.main([ZIP_FOLDER, '-v', '-b'])

        print "Removing temp directory %s" % TMP
        os.system('rm -rf %s' % TMP)
    def handle(self, county, **options):
        # First we download a bunch of zipfiles of TIGER data.
        if options['dir']:
            TMP = options['dir']
            download = not os.path.exists(TMP)
            if download:
                os.makedirs(TMP)
        else:
            TMP = tempfile.mkdtemp()
            download = True
        os.chdir(TMP)
        OUTDIR = os.path.join(TMP, 'tiger_data')
        STATE = '37' # NC
        if download:
            print 'Download TIGER data to %s' % TMP
            BASEURL= 'ftp://ftp2.census.gov/geo/tiger/TIGER2010'
            ZIPS = ("PLACE/2010/tl_2010_%s_place10.zip" % STATE,
                    "EDGES/tl_2010_%s_edges.zip" % county,
                    "FACES/tl_2010_%s_faces.zip" % county,
                    "FEATNAMES/tl_2010_%s_featnames.zip" % county,
                    )
            makedirs(OUTDIR) or die("couldn't create directory %s" % OUTDIR)
            for fname in ZIPS:
                wget('%s/%s' % (BASEURL, fname), cwd=OUTDIR) or die(
                    "Could not download %s/%s" % (BASEURL, fname))

            import glob
            for fname in glob.glob(os.path.join(OUTDIR, '*zip')):
                unzip(fname, cwd=OUTDIR) or die("Could not unzip %s" % fname)
            print "Shapefiles unzipped in %s" % OUTDIR

        # Now we load them into our blocks table.
        from ebpub.streets.blockimport.tiger import import_blocks
        from ebpub.utils.geodjango import get_default_bounds
        print "Importing blocks, this may take several minutes ..."

        # Passing --city means we skip features labeled for other cities.

        importer = import_blocks.TigerImporter(
            '%s/tl_2010_%s_edges.shp' % (OUTDIR, county),
            '%s/tl_2010_%s_featnames.dbf' % (OUTDIR, county),
            '%s/tl_2010_%s_faces.dbf' % (OUTDIR, county),
            '%s/tl_2010_%s_place10.shp' % (OUTDIR, STATE),
            encoding='utf8',
            filter_bounds=get_default_bounds())
        num_created = importer.save()
        print "Created %d blocks" % num_created

        #########################

        print "Populating streets and fixing addresses, these can take several minutes..."

        # Note these scripts should be run ONCE, in this order,
        # after you have imported *all* your blocks.

        from ebpub.streets.bin import populate_streets
        populate_streets.main(['streets'])
        populate_streets.main(['block_intersections'])
        populate_streets.main(['intersections'])
        print "Done."

        print "Removing temp directory %s" % TMP
        if not options['dir']:
            os.system('rm -rf %s' % TMP)