Read shapefile with Tkinter produce error
I'm trying to load and read shapefile via Tkinter and tkFileDialog.
Following code shows what done .
Firstly I try to read shapefile directly and print its content - no error , then reading the same shapefile with Tkinter dialog produce error.
import shapefile
import Tkinter, tkFileDialog
# Read the Arena shapefile using the Reader class of the pyshp module
arenafile = r"dataArenas_NBAArenas_NBA.shp"
arena_shapefile = shapefile.Reader(arenafile)
arena_shapes = arena_shapefile.shapes()
arena_records = arena_shapefile.records()
print arena_records
root = Tkinter.Tk()
root.withdraw()
arenafile_tk = tkFileDialog.askopenfile(parent=root,
mode='rb',
initialdir="dataArenas_NBA",
title="Select Arena Shapefile",
filetypes=(("shapefiles", "*.shp"), ("all files", "*.*")))
if arenafile_tk != None:
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
arena_shapes_tk = arena_shapefile_tk.shapes()
arena_records_tk = arena_shapefile_tk.records()
arenafile_tk.close()
print arena_records_tk
This code produce following output:
[[u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'American Airlines Arena', u'', u'', u'601 Biscayne Boulevard', u'', u'', u'', u'Miami', u'FL', u'33132', u'', u'Dade', u'Miami-Fort Lauderdale', 4.0, 25.78117, -80.18758, u'High', u'NGA', u'', u'Eastern', u'Southeast', 19600.0, u'Miami Heat'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'ARCO Arena', u'', u'', u'1 Sports Parkway', u'', u'', u'', u'Sacramento', u'CA', u'95834', u'', u'Sacramento', u'Sacramento', 9.0, 38.64932, -121.51869, u'High', u'NGA', u'', u'Western', u'Pacific', 17317.0, u'Sacramento Kings'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'EnergySolutions Arena', u'', u'', u'301 West South Temple', u'', u'', u'', u'Salt Lake City', u'UT', u'84101', u'', u'Salt Lake', u'Salt Lake City-Ogden', 8.0, 40.76629, -111.90093, u'High', u'NGA', u'Shares arean with Thunder (AF1).', u'Western', u'Northwest', 19911.0, u'Utah Jazz'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040226', u'20100215', u'', u'Fed Ex Forum', u'', u'', u'191 Beale Street', u'', u'', u'', u'Memphis', u'TN', u'38103', u'', u'Shelby', u'Memphis', 4.0, 35.1381, -90.0513, u'High', u'NGA', u'Shares arena with Memphis Tigers (NCAA).', u'Western', u'Southwest', 18119.0, u'Memphis Gizzlies'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Quicken Loans Arena', u'', u'', u'1 Center Court', u'', u'', u'', u'Cleveland', u'OH', u'44115', u'44115-4001', u'Cuyahoga', u'Cleveland-Akron', 5.0, 41.49648, -81.6887, u'High', u'NGA', u'Shares areana with Monsters (AHL) and Gladiators (AF1)', u'Eastern', u'Central', 20562.0, u'Cleveland Cavaliers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Oracle Arena', u'', u'', u'7000 Coliseum Way', u'', u'', u'', u'Oakland', u'CA', u'94621', u'94621-1917', u'Alameda', u'San Francisco-Oakland', 9.0, 37.75131, -122.20217, u'High', u'NGA', u'', u'Western', u'Pacific', 19596.0, u'Golden State Warriors'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'New Orleans Arena', u'', u'', u'1601 Girod Street', u'', u'', u'', u'New Orleans', u'LA', u'70113', u'70113-3124', u'Orleans', u'New Orleans', 6.0, 29.94889, -90.08203, u'High', u'NGA', u'', u'Western', u'Southwest', 18500.0, u'New Orleans Hornets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Rose Garden', u'', u'', u'1 Center Court', u'', u'', u'', u'Portland', u'OR', u'97227', u'', u'Multnomah', u'Portland', 10.0, 45.53165, -122.66692, u'High', u'NGA', u'Shares areana with Winterhawks (WHL).', u'Western', u'Northwest', 20630.0, u'Portland Trailblazers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Amway Arena', u'', u'', u'600 West Amelia Street', u'', u'', u'', u'Orlando', u'FL', u'32801', u'', u'Orange', u'Orlando', 4.0, 28.54883, -81.38636, u'High', u'NGA', u'Shares arena with Titans (NLL) and Predators (AF1)', u'Eastern', u'Southeast', 17519.0, u'Orlando Magic'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Bradley Center', u'', u'', u'1001 North 4th Street', u'', u'', u'', u'Milwaukee', u'WI', u'53203', u'53203-1314', u'Milwaukee', u'Milwaukee', 5.0, 43.04346, -87.91736, u'High', u'NGA', u'Shares arena with Marquette Golden Eagles (NCAA)', u'Eastern', u'Central', 18717.0, u'Milwaukee Bucks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'American Airlines Center', u'', u'', u'2500 Victory Avenue', u'', u'', u'', u'Dallas', u'TX', u'75219', u'75219-7601', u'Dallas', u'Dallas-Fort Worth', 6.0, 32.79062, -96.81043, u'High', u'NGA', u'Shares arena with Stars (NHL)..', u'Western', u'Southwest', 20337.0, u'Dallas Mavericks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'TD Garden Center', u'', u'', u'100 Legends Way', u'', u'', u'', u'Boston', u'MA', u'02114', u'02114-4714', u'Suffolk', u'Boston', 1.0, 42.36653, -71.06206, u'High', u'NGA', u'Shares arena with Bruins (NHL) and Blazers (NLL).', u'Eastern', u'Atlantic', 18624.0, u'Boston Celtics'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Pepsi Center', u'', u'', u'1000 Chopper Circle', u'', u'', u'', u'Denver', u'CO', u'80204', u'', u'Denver', u'Denver', 8.0, 39.74916, -105.00677, u'High', u'NGA', u'Shares arena with Avalanche (NHL) and Mammoth (NLL).', u'Western', u'Northwest', 19155.0, u'Denver Nuggets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Philips Arena', u'', u'', u'1 Philips Drive NW', u'', u'', u'', u'Atlanta', u'GA', u'30303', u'', u'Fulton', u'Atlanta', 4.0, 33.7573, -84.39631, u'High', u'NGA', u'Shares arena with Thashers (NHL) and Dream (WNBA).', u'Eastern', u'Southeast', 19445.0, u'Atlanta Hawks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'United Center', u'', u'', u'1902 West Madison Street', u'', u'', u'', u'Chicago', u'IL', u'60612', u'60612-2459', u'Cook', u'Chicago', 5.0, 41.88059, -87.67418, u'High', u'NGA', u'Shares arena with Blackhawks (NHL).', u'Eastern', u'Central', 20917.0, u'Chicago Bulls'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Wachovia Center', u'', u'', u'3601 South Broad Street', u'', u'', u'', u'Philadelphia', u'PA', u'19148', u'', u'Philadelphia', u'Philadelphia', 3.0, 39.90097, -75.17218, u'High', u'NGA', u'Shares arena with Flyers (NHL) and Wings (NLL).', u'Eastern', u'Atlantic', 21600.0, u'Philadelphia 76ers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'IZOD Center', u'', u'', u'50 Route 120', u'', u'', u'', u'East Rutherfor', u'NJ', u'07073', u'', u'Bergen', u'New York-Newark', 2.0, 40.81163, -74.06767, u'High', u'NGA', u'', u'Eastern', u'Atlantic', 20049.0, u'New Jersey Nets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Madison Square Garden', u'', u'', u'4 Pennsylvania Plaza', u'', u'', u'', u'New York', u'NY', u'10001', u'', u'New York', u'New York-Newark', 2.0, 40.7506, -73.99378, u'High', u'NGA', u'Shares arena with Rangers (NHL), Saint John Red Storm (NCAA), and Liberty (WNBA).', u'Eastern', u'Atlantic', 19763.0, u'New York Knicks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Verizon Center', u'', u'', u'601 F Street NW', u'', u'', u'', u'Washington', u'DC', u'20004', u'', u'District of Columbi', u'Washington', 3.0, 38.89838, -77.02098, u'High', u'NGA', u'Shares arena with Capitals (NHL), Mystics (WNBA) and Georgetown Hoyas (NCAA)', u'Eastern', u'Southeast', 20173.0, u'Washington Wizards'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Staples Center', u'', u'', u'1111 South Figueroa Street', u'', u'', u'', u'Los Angeles', u'CA', u'90015', u'', u'Los Angeles', u'Los Angeles', 9.0, 34.04321, -118.26716, u'High', u'NGA', u'Shares arena with Kings (NHL), Sparks (WNBA), and D-Fenders(D-League).', u'Western', u'Pacific', 18997.0, u'Los Angeles Lakers, Clipppers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Target Center', u'', u'', u'600 First Avenue North', u'', u'', u'', u'Minneapolis', u'MN', u'55403', u'', u'Hennepin', u'Minneapolis-Saint Paul', 5.0, 44.97944, -93.27609, u'High', u'NGA', u'Shares arena with Lynx (WNBA).', u'Western', u'Northwest', 20500.0, u'Minnesota Timberwolves'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'US Airways Center', u'', u'', u'201 East Jefferson', u'', u'', u'', u'Phoenix', u'AZ', u'85004', u'85004-2412', u'Maricopa', u'Phoenix', 8.0, 33.446, -112.07125, u'High', u'NGA', u'Shares arena with Mercury (WNBA), Rattlers (AF1)', u'Western', u'Pacific', 18422.0, u'Phoenix Suns'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Time Warner Cable Arena', u'', u'', u'333 East Trade Street', u'', u'', u'', u'Charlotte', u'NC', u'28202', u'', u'Mecklenburg', u'Charlotte', 4.0, 35.22373, -80.83999, u'High', u'NGA', u'Shares arena with Checkers (AHL),', u'Eastern', u'Southeast', 19026.0, u'Charlotte Bobcats'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Conseco Fieldhouse', u'', u'', u'125 South Pennsylvania Street', u'', u'', u'', u'Indianapolis', u'IN', u'46204', u'', u'Marion', u'Indianapolis', 5.0, 39.76401, -86.15557, u'High', u'NGA', u'Shares arena with Fever (WNBA).', u'Eastern', u'Central', 18345.0, u'Indiana Pacers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Toyota Center (Houston)', u'', u'', u'1510 Polk Street', u'', u'', u'', u'Houston', u'TX', u'77002', u'77002-7130', u'Harris', u'Houston', 6.0, 29.75078, -95.36218, u'High', u'NGA', u'Shares arena with Comets (WNBA).', u'Western', u'Southwest', 18300.0, u'Houston Rockets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Palace of Auburn Hills', u'', u'', u'2 Championship Drive', u'', u'', u'', u'Auburn Hills', u'MI', u'48326', u'', u'Oakland', u'Detroit', 5.0, 42.69721, -83.24467, u'High', u'NGA', u'Shares arena with Shocks (WNBA).', u'Eastern', u'Central', 22076.0, u'Detroit Pistons'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'AT&T Center', u'', u'', u'1 AT&T Center Parkway', u'', u'', u'', u'San Antonio', u'TX', u'78219', u'', u'Bexar', u'San Antonio', 6.0, 29.42703, -98.43766, u'High', u'NGA', u'Shares arena with Silver Stars (WNBA), Rampage (AHL).', u'Western', u'Southwest', 18581.0, u'San Antonio Spurs'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Ford Center', u'', u'', u'100 West Reno Avenue', u'', u'', u'', u'Oklahoma City', u'OK', u'73102', u'73102-2473', u'Oklahoma', u'Oklahoma City', 6.0, 35.46347, -97.51483, u'High', u'NGA', u'', u'Western', u'Southwest', 18203.0, u'Oklahoma City Thunder'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20100215', u'', u'', u'Air Canada Centre', u'', u'', u'40 Bay Street', u'', u'', u'', u'Toronto', u'ON', u'M5J', u'2X2', u'', u'', 0.0, 43.64333, -79.37916, u'High', u'NGA', u'Shares arena with Maple Leafs (NHL) and Rock (NLL).', u'Eastern', u'Atlantic', 19800.0, u'Toronto Raptors']]
Traceback (most recent call last):
File "C:/Users/test.py", line 22, in <module>
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
File "C:Python27libsite-packagesshapefile.py", line 546, in __init__
raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
shapefile.ShapefileException: Shapefile Reader requires a shapefile or file-like object.
Process finished with exit code 1
Link to Arena shapefile
python python-2.7 tkinter shapefile
add a comment |
I'm trying to load and read shapefile via Tkinter and tkFileDialog.
Following code shows what done .
Firstly I try to read shapefile directly and print its content - no error , then reading the same shapefile with Tkinter dialog produce error.
import shapefile
import Tkinter, tkFileDialog
# Read the Arena shapefile using the Reader class of the pyshp module
arenafile = r"dataArenas_NBAArenas_NBA.shp"
arena_shapefile = shapefile.Reader(arenafile)
arena_shapes = arena_shapefile.shapes()
arena_records = arena_shapefile.records()
print arena_records
root = Tkinter.Tk()
root.withdraw()
arenafile_tk = tkFileDialog.askopenfile(parent=root,
mode='rb',
initialdir="dataArenas_NBA",
title="Select Arena Shapefile",
filetypes=(("shapefiles", "*.shp"), ("all files", "*.*")))
if arenafile_tk != None:
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
arena_shapes_tk = arena_shapefile_tk.shapes()
arena_records_tk = arena_shapefile_tk.records()
arenafile_tk.close()
print arena_records_tk
This code produce following output:
[[u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'American Airlines Arena', u'', u'', u'601 Biscayne Boulevard', u'', u'', u'', u'Miami', u'FL', u'33132', u'', u'Dade', u'Miami-Fort Lauderdale', 4.0, 25.78117, -80.18758, u'High', u'NGA', u'', u'Eastern', u'Southeast', 19600.0, u'Miami Heat'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'ARCO Arena', u'', u'', u'1 Sports Parkway', u'', u'', u'', u'Sacramento', u'CA', u'95834', u'', u'Sacramento', u'Sacramento', 9.0, 38.64932, -121.51869, u'High', u'NGA', u'', u'Western', u'Pacific', 17317.0, u'Sacramento Kings'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'EnergySolutions Arena', u'', u'', u'301 West South Temple', u'', u'', u'', u'Salt Lake City', u'UT', u'84101', u'', u'Salt Lake', u'Salt Lake City-Ogden', 8.0, 40.76629, -111.90093, u'High', u'NGA', u'Shares arean with Thunder (AF1).', u'Western', u'Northwest', 19911.0, u'Utah Jazz'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040226', u'20100215', u'', u'Fed Ex Forum', u'', u'', u'191 Beale Street', u'', u'', u'', u'Memphis', u'TN', u'38103', u'', u'Shelby', u'Memphis', 4.0, 35.1381, -90.0513, u'High', u'NGA', u'Shares arena with Memphis Tigers (NCAA).', u'Western', u'Southwest', 18119.0, u'Memphis Gizzlies'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Quicken Loans Arena', u'', u'', u'1 Center Court', u'', u'', u'', u'Cleveland', u'OH', u'44115', u'44115-4001', u'Cuyahoga', u'Cleveland-Akron', 5.0, 41.49648, -81.6887, u'High', u'NGA', u'Shares areana with Monsters (AHL) and Gladiators (AF1)', u'Eastern', u'Central', 20562.0, u'Cleveland Cavaliers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Oracle Arena', u'', u'', u'7000 Coliseum Way', u'', u'', u'', u'Oakland', u'CA', u'94621', u'94621-1917', u'Alameda', u'San Francisco-Oakland', 9.0, 37.75131, -122.20217, u'High', u'NGA', u'', u'Western', u'Pacific', 19596.0, u'Golden State Warriors'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'New Orleans Arena', u'', u'', u'1601 Girod Street', u'', u'', u'', u'New Orleans', u'LA', u'70113', u'70113-3124', u'Orleans', u'New Orleans', 6.0, 29.94889, -90.08203, u'High', u'NGA', u'', u'Western', u'Southwest', 18500.0, u'New Orleans Hornets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Rose Garden', u'', u'', u'1 Center Court', u'', u'', u'', u'Portland', u'OR', u'97227', u'', u'Multnomah', u'Portland', 10.0, 45.53165, -122.66692, u'High', u'NGA', u'Shares areana with Winterhawks (WHL).', u'Western', u'Northwest', 20630.0, u'Portland Trailblazers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Amway Arena', u'', u'', u'600 West Amelia Street', u'', u'', u'', u'Orlando', u'FL', u'32801', u'', u'Orange', u'Orlando', 4.0, 28.54883, -81.38636, u'High', u'NGA', u'Shares arena with Titans (NLL) and Predators (AF1)', u'Eastern', u'Southeast', 17519.0, u'Orlando Magic'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Bradley Center', u'', u'', u'1001 North 4th Street', u'', u'', u'', u'Milwaukee', u'WI', u'53203', u'53203-1314', u'Milwaukee', u'Milwaukee', 5.0, 43.04346, -87.91736, u'High', u'NGA', u'Shares arena with Marquette Golden Eagles (NCAA)', u'Eastern', u'Central', 18717.0, u'Milwaukee Bucks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'American Airlines Center', u'', u'', u'2500 Victory Avenue', u'', u'', u'', u'Dallas', u'TX', u'75219', u'75219-7601', u'Dallas', u'Dallas-Fort Worth', 6.0, 32.79062, -96.81043, u'High', u'NGA', u'Shares arena with Stars (NHL)..', u'Western', u'Southwest', 20337.0, u'Dallas Mavericks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'TD Garden Center', u'', u'', u'100 Legends Way', u'', u'', u'', u'Boston', u'MA', u'02114', u'02114-4714', u'Suffolk', u'Boston', 1.0, 42.36653, -71.06206, u'High', u'NGA', u'Shares arena with Bruins (NHL) and Blazers (NLL).', u'Eastern', u'Atlantic', 18624.0, u'Boston Celtics'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Pepsi Center', u'', u'', u'1000 Chopper Circle', u'', u'', u'', u'Denver', u'CO', u'80204', u'', u'Denver', u'Denver', 8.0, 39.74916, -105.00677, u'High', u'NGA', u'Shares arena with Avalanche (NHL) and Mammoth (NLL).', u'Western', u'Northwest', 19155.0, u'Denver Nuggets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Philips Arena', u'', u'', u'1 Philips Drive NW', u'', u'', u'', u'Atlanta', u'GA', u'30303', u'', u'Fulton', u'Atlanta', 4.0, 33.7573, -84.39631, u'High', u'NGA', u'Shares arena with Thashers (NHL) and Dream (WNBA).', u'Eastern', u'Southeast', 19445.0, u'Atlanta Hawks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'United Center', u'', u'', u'1902 West Madison Street', u'', u'', u'', u'Chicago', u'IL', u'60612', u'60612-2459', u'Cook', u'Chicago', 5.0, 41.88059, -87.67418, u'High', u'NGA', u'Shares arena with Blackhawks (NHL).', u'Eastern', u'Central', 20917.0, u'Chicago Bulls'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Wachovia Center', u'', u'', u'3601 South Broad Street', u'', u'', u'', u'Philadelphia', u'PA', u'19148', u'', u'Philadelphia', u'Philadelphia', 3.0, 39.90097, -75.17218, u'High', u'NGA', u'Shares arena with Flyers (NHL) and Wings (NLL).', u'Eastern', u'Atlantic', 21600.0, u'Philadelphia 76ers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'IZOD Center', u'', u'', u'50 Route 120', u'', u'', u'', u'East Rutherfor', u'NJ', u'07073', u'', u'Bergen', u'New York-Newark', 2.0, 40.81163, -74.06767, u'High', u'NGA', u'', u'Eastern', u'Atlantic', 20049.0, u'New Jersey Nets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Madison Square Garden', u'', u'', u'4 Pennsylvania Plaza', u'', u'', u'', u'New York', u'NY', u'10001', u'', u'New York', u'New York-Newark', 2.0, 40.7506, -73.99378, u'High', u'NGA', u'Shares arena with Rangers (NHL), Saint John Red Storm (NCAA), and Liberty (WNBA).', u'Eastern', u'Atlantic', 19763.0, u'New York Knicks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Verizon Center', u'', u'', u'601 F Street NW', u'', u'', u'', u'Washington', u'DC', u'20004', u'', u'District of Columbi', u'Washington', 3.0, 38.89838, -77.02098, u'High', u'NGA', u'Shares arena with Capitals (NHL), Mystics (WNBA) and Georgetown Hoyas (NCAA)', u'Eastern', u'Southeast', 20173.0, u'Washington Wizards'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Staples Center', u'', u'', u'1111 South Figueroa Street', u'', u'', u'', u'Los Angeles', u'CA', u'90015', u'', u'Los Angeles', u'Los Angeles', 9.0, 34.04321, -118.26716, u'High', u'NGA', u'Shares arena with Kings (NHL), Sparks (WNBA), and D-Fenders(D-League).', u'Western', u'Pacific', 18997.0, u'Los Angeles Lakers, Clipppers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Target Center', u'', u'', u'600 First Avenue North', u'', u'', u'', u'Minneapolis', u'MN', u'55403', u'', u'Hennepin', u'Minneapolis-Saint Paul', 5.0, 44.97944, -93.27609, u'High', u'NGA', u'Shares arena with Lynx (WNBA).', u'Western', u'Northwest', 20500.0, u'Minnesota Timberwolves'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'US Airways Center', u'', u'', u'201 East Jefferson', u'', u'', u'', u'Phoenix', u'AZ', u'85004', u'85004-2412', u'Maricopa', u'Phoenix', 8.0, 33.446, -112.07125, u'High', u'NGA', u'Shares arena with Mercury (WNBA), Rattlers (AF1)', u'Western', u'Pacific', 18422.0, u'Phoenix Suns'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Time Warner Cable Arena', u'', u'', u'333 East Trade Street', u'', u'', u'', u'Charlotte', u'NC', u'28202', u'', u'Mecklenburg', u'Charlotte', 4.0, 35.22373, -80.83999, u'High', u'NGA', u'Shares arena with Checkers (AHL),', u'Eastern', u'Southeast', 19026.0, u'Charlotte Bobcats'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Conseco Fieldhouse', u'', u'', u'125 South Pennsylvania Street', u'', u'', u'', u'Indianapolis', u'IN', u'46204', u'', u'Marion', u'Indianapolis', 5.0, 39.76401, -86.15557, u'High', u'NGA', u'Shares arena with Fever (WNBA).', u'Eastern', u'Central', 18345.0, u'Indiana Pacers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Toyota Center (Houston)', u'', u'', u'1510 Polk Street', u'', u'', u'', u'Houston', u'TX', u'77002', u'77002-7130', u'Harris', u'Houston', 6.0, 29.75078, -95.36218, u'High', u'NGA', u'Shares arena with Comets (WNBA).', u'Western', u'Southwest', 18300.0, u'Houston Rockets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Palace of Auburn Hills', u'', u'', u'2 Championship Drive', u'', u'', u'', u'Auburn Hills', u'MI', u'48326', u'', u'Oakland', u'Detroit', 5.0, 42.69721, -83.24467, u'High', u'NGA', u'Shares arena with Shocks (WNBA).', u'Eastern', u'Central', 22076.0, u'Detroit Pistons'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'AT&T Center', u'', u'', u'1 AT&T Center Parkway', u'', u'', u'', u'San Antonio', u'TX', u'78219', u'', u'Bexar', u'San Antonio', 6.0, 29.42703, -98.43766, u'High', u'NGA', u'Shares arena with Silver Stars (WNBA), Rampage (AHL).', u'Western', u'Southwest', 18581.0, u'San Antonio Spurs'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Ford Center', u'', u'', u'100 West Reno Avenue', u'', u'', u'', u'Oklahoma City', u'OK', u'73102', u'73102-2473', u'Oklahoma', u'Oklahoma City', 6.0, 35.46347, -97.51483, u'High', u'NGA', u'', u'Western', u'Southwest', 18203.0, u'Oklahoma City Thunder'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20100215', u'', u'', u'Air Canada Centre', u'', u'', u'40 Bay Street', u'', u'', u'', u'Toronto', u'ON', u'M5J', u'2X2', u'', u'', 0.0, 43.64333, -79.37916, u'High', u'NGA', u'Shares arena with Maple Leafs (NHL) and Rock (NLL).', u'Eastern', u'Atlantic', 19800.0, u'Toronto Raptors']]
Traceback (most recent call last):
File "C:/Users/test.py", line 22, in <module>
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
File "C:Python27libsite-packagesshapefile.py", line 546, in __init__
raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
shapefile.ShapefileException: Shapefile Reader requires a shapefile or file-like object.
Process finished with exit code 1
Link to Arena shapefile
python python-2.7 tkinter shapefile
add a comment |
I'm trying to load and read shapefile via Tkinter and tkFileDialog.
Following code shows what done .
Firstly I try to read shapefile directly and print its content - no error , then reading the same shapefile with Tkinter dialog produce error.
import shapefile
import Tkinter, tkFileDialog
# Read the Arena shapefile using the Reader class of the pyshp module
arenafile = r"dataArenas_NBAArenas_NBA.shp"
arena_shapefile = shapefile.Reader(arenafile)
arena_shapes = arena_shapefile.shapes()
arena_records = arena_shapefile.records()
print arena_records
root = Tkinter.Tk()
root.withdraw()
arenafile_tk = tkFileDialog.askopenfile(parent=root,
mode='rb',
initialdir="dataArenas_NBA",
title="Select Arena Shapefile",
filetypes=(("shapefiles", "*.shp"), ("all files", "*.*")))
if arenafile_tk != None:
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
arena_shapes_tk = arena_shapefile_tk.shapes()
arena_records_tk = arena_shapefile_tk.records()
arenafile_tk.close()
print arena_records_tk
This code produce following output:
[[u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'American Airlines Arena', u'', u'', u'601 Biscayne Boulevard', u'', u'', u'', u'Miami', u'FL', u'33132', u'', u'Dade', u'Miami-Fort Lauderdale', 4.0, 25.78117, -80.18758, u'High', u'NGA', u'', u'Eastern', u'Southeast', 19600.0, u'Miami Heat'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'ARCO Arena', u'', u'', u'1 Sports Parkway', u'', u'', u'', u'Sacramento', u'CA', u'95834', u'', u'Sacramento', u'Sacramento', 9.0, 38.64932, -121.51869, u'High', u'NGA', u'', u'Western', u'Pacific', 17317.0, u'Sacramento Kings'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'EnergySolutions Arena', u'', u'', u'301 West South Temple', u'', u'', u'', u'Salt Lake City', u'UT', u'84101', u'', u'Salt Lake', u'Salt Lake City-Ogden', 8.0, 40.76629, -111.90093, u'High', u'NGA', u'Shares arean with Thunder (AF1).', u'Western', u'Northwest', 19911.0, u'Utah Jazz'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040226', u'20100215', u'', u'Fed Ex Forum', u'', u'', u'191 Beale Street', u'', u'', u'', u'Memphis', u'TN', u'38103', u'', u'Shelby', u'Memphis', 4.0, 35.1381, -90.0513, u'High', u'NGA', u'Shares arena with Memphis Tigers (NCAA).', u'Western', u'Southwest', 18119.0, u'Memphis Gizzlies'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Quicken Loans Arena', u'', u'', u'1 Center Court', u'', u'', u'', u'Cleveland', u'OH', u'44115', u'44115-4001', u'Cuyahoga', u'Cleveland-Akron', 5.0, 41.49648, -81.6887, u'High', u'NGA', u'Shares areana with Monsters (AHL) and Gladiators (AF1)', u'Eastern', u'Central', 20562.0, u'Cleveland Cavaliers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Oracle Arena', u'', u'', u'7000 Coliseum Way', u'', u'', u'', u'Oakland', u'CA', u'94621', u'94621-1917', u'Alameda', u'San Francisco-Oakland', 9.0, 37.75131, -122.20217, u'High', u'NGA', u'', u'Western', u'Pacific', 19596.0, u'Golden State Warriors'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'New Orleans Arena', u'', u'', u'1601 Girod Street', u'', u'', u'', u'New Orleans', u'LA', u'70113', u'70113-3124', u'Orleans', u'New Orleans', 6.0, 29.94889, -90.08203, u'High', u'NGA', u'', u'Western', u'Southwest', 18500.0, u'New Orleans Hornets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Rose Garden', u'', u'', u'1 Center Court', u'', u'', u'', u'Portland', u'OR', u'97227', u'', u'Multnomah', u'Portland', 10.0, 45.53165, -122.66692, u'High', u'NGA', u'Shares areana with Winterhawks (WHL).', u'Western', u'Northwest', 20630.0, u'Portland Trailblazers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Amway Arena', u'', u'', u'600 West Amelia Street', u'', u'', u'', u'Orlando', u'FL', u'32801', u'', u'Orange', u'Orlando', 4.0, 28.54883, -81.38636, u'High', u'NGA', u'Shares arena with Titans (NLL) and Predators (AF1)', u'Eastern', u'Southeast', 17519.0, u'Orlando Magic'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Bradley Center', u'', u'', u'1001 North 4th Street', u'', u'', u'', u'Milwaukee', u'WI', u'53203', u'53203-1314', u'Milwaukee', u'Milwaukee', 5.0, 43.04346, -87.91736, u'High', u'NGA', u'Shares arena with Marquette Golden Eagles (NCAA)', u'Eastern', u'Central', 18717.0, u'Milwaukee Bucks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'American Airlines Center', u'', u'', u'2500 Victory Avenue', u'', u'', u'', u'Dallas', u'TX', u'75219', u'75219-7601', u'Dallas', u'Dallas-Fort Worth', 6.0, 32.79062, -96.81043, u'High', u'NGA', u'Shares arena with Stars (NHL)..', u'Western', u'Southwest', 20337.0, u'Dallas Mavericks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'TD Garden Center', u'', u'', u'100 Legends Way', u'', u'', u'', u'Boston', u'MA', u'02114', u'02114-4714', u'Suffolk', u'Boston', 1.0, 42.36653, -71.06206, u'High', u'NGA', u'Shares arena with Bruins (NHL) and Blazers (NLL).', u'Eastern', u'Atlantic', 18624.0, u'Boston Celtics'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Pepsi Center', u'', u'', u'1000 Chopper Circle', u'', u'', u'', u'Denver', u'CO', u'80204', u'', u'Denver', u'Denver', 8.0, 39.74916, -105.00677, u'High', u'NGA', u'Shares arena with Avalanche (NHL) and Mammoth (NLL).', u'Western', u'Northwest', 19155.0, u'Denver Nuggets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Philips Arena', u'', u'', u'1 Philips Drive NW', u'', u'', u'', u'Atlanta', u'GA', u'30303', u'', u'Fulton', u'Atlanta', 4.0, 33.7573, -84.39631, u'High', u'NGA', u'Shares arena with Thashers (NHL) and Dream (WNBA).', u'Eastern', u'Southeast', 19445.0, u'Atlanta Hawks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'United Center', u'', u'', u'1902 West Madison Street', u'', u'', u'', u'Chicago', u'IL', u'60612', u'60612-2459', u'Cook', u'Chicago', 5.0, 41.88059, -87.67418, u'High', u'NGA', u'Shares arena with Blackhawks (NHL).', u'Eastern', u'Central', 20917.0, u'Chicago Bulls'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Wachovia Center', u'', u'', u'3601 South Broad Street', u'', u'', u'', u'Philadelphia', u'PA', u'19148', u'', u'Philadelphia', u'Philadelphia', 3.0, 39.90097, -75.17218, u'High', u'NGA', u'Shares arena with Flyers (NHL) and Wings (NLL).', u'Eastern', u'Atlantic', 21600.0, u'Philadelphia 76ers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'IZOD Center', u'', u'', u'50 Route 120', u'', u'', u'', u'East Rutherfor', u'NJ', u'07073', u'', u'Bergen', u'New York-Newark', 2.0, 40.81163, -74.06767, u'High', u'NGA', u'', u'Eastern', u'Atlantic', 20049.0, u'New Jersey Nets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Madison Square Garden', u'', u'', u'4 Pennsylvania Plaza', u'', u'', u'', u'New York', u'NY', u'10001', u'', u'New York', u'New York-Newark', 2.0, 40.7506, -73.99378, u'High', u'NGA', u'Shares arena with Rangers (NHL), Saint John Red Storm (NCAA), and Liberty (WNBA).', u'Eastern', u'Atlantic', 19763.0, u'New York Knicks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Verizon Center', u'', u'', u'601 F Street NW', u'', u'', u'', u'Washington', u'DC', u'20004', u'', u'District of Columbi', u'Washington', 3.0, 38.89838, -77.02098, u'High', u'NGA', u'Shares arena with Capitals (NHL), Mystics (WNBA) and Georgetown Hoyas (NCAA)', u'Eastern', u'Southeast', 20173.0, u'Washington Wizards'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Staples Center', u'', u'', u'1111 South Figueroa Street', u'', u'', u'', u'Los Angeles', u'CA', u'90015', u'', u'Los Angeles', u'Los Angeles', 9.0, 34.04321, -118.26716, u'High', u'NGA', u'Shares arena with Kings (NHL), Sparks (WNBA), and D-Fenders(D-League).', u'Western', u'Pacific', 18997.0, u'Los Angeles Lakers, Clipppers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Target Center', u'', u'', u'600 First Avenue North', u'', u'', u'', u'Minneapolis', u'MN', u'55403', u'', u'Hennepin', u'Minneapolis-Saint Paul', 5.0, 44.97944, -93.27609, u'High', u'NGA', u'Shares arena with Lynx (WNBA).', u'Western', u'Northwest', 20500.0, u'Minnesota Timberwolves'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'US Airways Center', u'', u'', u'201 East Jefferson', u'', u'', u'', u'Phoenix', u'AZ', u'85004', u'85004-2412', u'Maricopa', u'Phoenix', 8.0, 33.446, -112.07125, u'High', u'NGA', u'Shares arena with Mercury (WNBA), Rattlers (AF1)', u'Western', u'Pacific', 18422.0, u'Phoenix Suns'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Time Warner Cable Arena', u'', u'', u'333 East Trade Street', u'', u'', u'', u'Charlotte', u'NC', u'28202', u'', u'Mecklenburg', u'Charlotte', 4.0, 35.22373, -80.83999, u'High', u'NGA', u'Shares arena with Checkers (AHL),', u'Eastern', u'Southeast', 19026.0, u'Charlotte Bobcats'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Conseco Fieldhouse', u'', u'', u'125 South Pennsylvania Street', u'', u'', u'', u'Indianapolis', u'IN', u'46204', u'', u'Marion', u'Indianapolis', 5.0, 39.76401, -86.15557, u'High', u'NGA', u'Shares arena with Fever (WNBA).', u'Eastern', u'Central', 18345.0, u'Indiana Pacers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Toyota Center (Houston)', u'', u'', u'1510 Polk Street', u'', u'', u'', u'Houston', u'TX', u'77002', u'77002-7130', u'Harris', u'Houston', 6.0, 29.75078, -95.36218, u'High', u'NGA', u'Shares arena with Comets (WNBA).', u'Western', u'Southwest', 18300.0, u'Houston Rockets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Palace of Auburn Hills', u'', u'', u'2 Championship Drive', u'', u'', u'', u'Auburn Hills', u'MI', u'48326', u'', u'Oakland', u'Detroit', 5.0, 42.69721, -83.24467, u'High', u'NGA', u'Shares arena with Shocks (WNBA).', u'Eastern', u'Central', 22076.0, u'Detroit Pistons'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'AT&T Center', u'', u'', u'1 AT&T Center Parkway', u'', u'', u'', u'San Antonio', u'TX', u'78219', u'', u'Bexar', u'San Antonio', 6.0, 29.42703, -98.43766, u'High', u'NGA', u'Shares arena with Silver Stars (WNBA), Rampage (AHL).', u'Western', u'Southwest', 18581.0, u'San Antonio Spurs'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Ford Center', u'', u'', u'100 West Reno Avenue', u'', u'', u'', u'Oklahoma City', u'OK', u'73102', u'73102-2473', u'Oklahoma', u'Oklahoma City', 6.0, 35.46347, -97.51483, u'High', u'NGA', u'', u'Western', u'Southwest', 18203.0, u'Oklahoma City Thunder'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20100215', u'', u'', u'Air Canada Centre', u'', u'', u'40 Bay Street', u'', u'', u'', u'Toronto', u'ON', u'M5J', u'2X2', u'', u'', 0.0, 43.64333, -79.37916, u'High', u'NGA', u'Shares arena with Maple Leafs (NHL) and Rock (NLL).', u'Eastern', u'Atlantic', 19800.0, u'Toronto Raptors']]
Traceback (most recent call last):
File "C:/Users/test.py", line 22, in <module>
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
File "C:Python27libsite-packagesshapefile.py", line 546, in __init__
raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
shapefile.ShapefileException: Shapefile Reader requires a shapefile or file-like object.
Process finished with exit code 1
Link to Arena shapefile
python python-2.7 tkinter shapefile
I'm trying to load and read shapefile via Tkinter and tkFileDialog.
Following code shows what done .
Firstly I try to read shapefile directly and print its content - no error , then reading the same shapefile with Tkinter dialog produce error.
import shapefile
import Tkinter, tkFileDialog
# Read the Arena shapefile using the Reader class of the pyshp module
arenafile = r"dataArenas_NBAArenas_NBA.shp"
arena_shapefile = shapefile.Reader(arenafile)
arena_shapes = arena_shapefile.shapes()
arena_records = arena_shapefile.records()
print arena_records
root = Tkinter.Tk()
root.withdraw()
arenafile_tk = tkFileDialog.askopenfile(parent=root,
mode='rb',
initialdir="dataArenas_NBA",
title="Select Arena Shapefile",
filetypes=(("shapefiles", "*.shp"), ("all files", "*.*")))
if arenafile_tk != None:
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
arena_shapes_tk = arena_shapefile_tk.shapes()
arena_records_tk = arena_shapefile_tk.records()
arenafile_tk.close()
print arena_records_tk
This code produce following output:
[[u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'American Airlines Arena', u'', u'', u'601 Biscayne Boulevard', u'', u'', u'', u'Miami', u'FL', u'33132', u'', u'Dade', u'Miami-Fort Lauderdale', 4.0, 25.78117, -80.18758, u'High', u'NGA', u'', u'Eastern', u'Southeast', 19600.0, u'Miami Heat'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'ARCO Arena', u'', u'', u'1 Sports Parkway', u'', u'', u'', u'Sacramento', u'CA', u'95834', u'', u'Sacramento', u'Sacramento', 9.0, 38.64932, -121.51869, u'High', u'NGA', u'', u'Western', u'Pacific', 17317.0, u'Sacramento Kings'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040211', u'20100215', u'', u'EnergySolutions Arena', u'', u'', u'301 West South Temple', u'', u'', u'', u'Salt Lake City', u'UT', u'84101', u'', u'Salt Lake', u'Salt Lake City-Ogden', 8.0, 40.76629, -111.90093, u'High', u'NGA', u'Shares arean with Thunder (AF1).', u'Western', u'Northwest', 19911.0, u'Utah Jazz'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20040226', u'20100215', u'', u'Fed Ex Forum', u'', u'', u'191 Beale Street', u'', u'', u'', u'Memphis', u'TN', u'38103', u'', u'Shelby', u'Memphis', 4.0, 35.1381, -90.0513, u'High', u'NGA', u'Shares arena with Memphis Tigers (NCAA).', u'Western', u'Southwest', 18119.0, u'Memphis Gizzlies'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Quicken Loans Arena', u'', u'', u'1 Center Court', u'', u'', u'', u'Cleveland', u'OH', u'44115', u'44115-4001', u'Cuyahoga', u'Cleveland-Akron', 5.0, 41.49648, -81.6887, u'High', u'NGA', u'Shares areana with Monsters (AHL) and Gladiators (AF1)', u'Eastern', u'Central', 20562.0, u'Cleveland Cavaliers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Oracle Arena', u'', u'', u'7000 Coliseum Way', u'', u'', u'', u'Oakland', u'CA', u'94621', u'94621-1917', u'Alameda', u'San Francisco-Oakland', 9.0, 37.75131, -122.20217, u'High', u'NGA', u'', u'Western', u'Pacific', 19596.0, u'Golden State Warriors'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'New Orleans Arena', u'', u'', u'1601 Girod Street', u'', u'', u'', u'New Orleans', u'LA', u'70113', u'70113-3124', u'Orleans', u'New Orleans', 6.0, 29.94889, -90.08203, u'High', u'NGA', u'', u'Western', u'Southwest', 18500.0, u'New Orleans Hornets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Rose Garden', u'', u'', u'1 Center Court', u'', u'', u'', u'Portland', u'OR', u'97227', u'', u'Multnomah', u'Portland', 10.0, 45.53165, -122.66692, u'High', u'NGA', u'Shares areana with Winterhawks (WHL).', u'Western', u'Northwest', 20630.0, u'Portland Trailblazers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Amway Arena', u'', u'', u'600 West Amelia Street', u'', u'', u'', u'Orlando', u'FL', u'32801', u'', u'Orange', u'Orlando', 4.0, 28.54883, -81.38636, u'High', u'NGA', u'Shares arena with Titans (NLL) and Predators (AF1)', u'Eastern', u'Southeast', 17519.0, u'Orlando Magic'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Bradley Center', u'', u'', u'1001 North 4th Street', u'', u'', u'', u'Milwaukee', u'WI', u'53203', u'53203-1314', u'Milwaukee', u'Milwaukee', 5.0, 43.04346, -87.91736, u'High', u'NGA', u'Shares arena with Marquette Golden Eagles (NCAA)', u'Eastern', u'Central', 18717.0, u'Milwaukee Bucks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'American Airlines Center', u'', u'', u'2500 Victory Avenue', u'', u'', u'', u'Dallas', u'TX', u'75219', u'75219-7601', u'Dallas', u'Dallas-Fort Worth', 6.0, 32.79062, -96.81043, u'High', u'NGA', u'Shares arena with Stars (NHL)..', u'Western', u'Southwest', 20337.0, u'Dallas Mavericks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'TD Garden Center', u'', u'', u'100 Legends Way', u'', u'', u'', u'Boston', u'MA', u'02114', u'02114-4714', u'Suffolk', u'Boston', 1.0, 42.36653, -71.06206, u'High', u'NGA', u'Shares arena with Bruins (NHL) and Blazers (NLL).', u'Eastern', u'Atlantic', 18624.0, u'Boston Celtics'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Pepsi Center', u'', u'', u'1000 Chopper Circle', u'', u'', u'', u'Denver', u'CO', u'80204', u'', u'Denver', u'Denver', 8.0, 39.74916, -105.00677, u'High', u'NGA', u'Shares arena with Avalanche (NHL) and Mammoth (NLL).', u'Western', u'Northwest', 19155.0, u'Denver Nuggets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Philips Arena', u'', u'', u'1 Philips Drive NW', u'', u'', u'', u'Atlanta', u'GA', u'30303', u'', u'Fulton', u'Atlanta', 4.0, 33.7573, -84.39631, u'High', u'NGA', u'Shares arena with Thashers (NHL) and Dream (WNBA).', u'Eastern', u'Southeast', 19445.0, u'Atlanta Hawks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'United Center', u'', u'', u'1902 West Madison Street', u'', u'', u'', u'Chicago', u'IL', u'60612', u'60612-2459', u'Cook', u'Chicago', 5.0, 41.88059, -87.67418, u'High', u'NGA', u'Shares arena with Blackhawks (NHL).', u'Eastern', u'Central', 20917.0, u'Chicago Bulls'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Wachovia Center', u'', u'', u'3601 South Broad Street', u'', u'', u'', u'Philadelphia', u'PA', u'19148', u'', u'Philadelphia', u'Philadelphia', 3.0, 39.90097, -75.17218, u'High', u'NGA', u'Shares arena with Flyers (NHL) and Wings (NLL).', u'Eastern', u'Atlantic', 21600.0, u'Philadelphia 76ers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'IZOD Center', u'', u'', u'50 Route 120', u'', u'', u'', u'East Rutherfor', u'NJ', u'07073', u'', u'Bergen', u'New York-Newark', 2.0, 40.81163, -74.06767, u'High', u'NGA', u'', u'Eastern', u'Atlantic', 20049.0, u'New Jersey Nets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Madison Square Garden', u'', u'', u'4 Pennsylvania Plaza', u'', u'', u'', u'New York', u'NY', u'10001', u'', u'New York', u'New York-Newark', 2.0, 40.7506, -73.99378, u'High', u'NGA', u'Shares arena with Rangers (NHL), Saint John Red Storm (NCAA), and Liberty (WNBA).', u'Eastern', u'Atlantic', 19763.0, u'New York Knicks'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Verizon Center', u'', u'', u'601 F Street NW', u'', u'', u'', u'Washington', u'DC', u'20004', u'', u'District of Columbi', u'Washington', 3.0, 38.89838, -77.02098, u'High', u'NGA', u'Shares arena with Capitals (NHL), Mystics (WNBA) and Georgetown Hoyas (NCAA)', u'Eastern', u'Southeast', 20173.0, u'Washington Wizards'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Staples Center', u'', u'', u'1111 South Figueroa Street', u'', u'', u'', u'Los Angeles', u'CA', u'90015', u'', u'Los Angeles', u'Los Angeles', 9.0, 34.04321, -118.26716, u'High', u'NGA', u'Shares arena with Kings (NHL), Sparks (WNBA), and D-Fenders(D-League).', u'Western', u'Pacific', 18997.0, u'Los Angeles Lakers, Clipppers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Target Center', u'', u'', u'600 First Avenue North', u'', u'', u'', u'Minneapolis', u'MN', u'55403', u'', u'Hennepin', u'Minneapolis-Saint Paul', 5.0, 44.97944, -93.27609, u'High', u'NGA', u'Shares arena with Lynx (WNBA).', u'Western', u'Northwest', 20500.0, u'Minnesota Timberwolves'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'US Airways Center', u'', u'', u'201 East Jefferson', u'', u'', u'', u'Phoenix', u'AZ', u'85004', u'85004-2412', u'Maricopa', u'Phoenix', 8.0, 33.446, -112.07125, u'High', u'NGA', u'Shares arena with Mercury (WNBA), Rattlers (AF1)', u'Western', u'Pacific', 18422.0, u'Phoenix Suns'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Time Warner Cable Arena', u'', u'', u'333 East Trade Street', u'', u'', u'', u'Charlotte', u'NC', u'28202', u'', u'Mecklenburg', u'Charlotte', 4.0, 35.22373, -80.83999, u'High', u'NGA', u'Shares arena with Checkers (AHL),', u'Eastern', u'Southeast', 19026.0, u'Charlotte Bobcats'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Conseco Fieldhouse', u'', u'', u'125 South Pennsylvania Street', u'', u'', u'', u'Indianapolis', u'IN', u'46204', u'', u'Marion', u'Indianapolis', 5.0, 39.76401, -86.15557, u'High', u'NGA', u'Shares arena with Fever (WNBA).', u'Eastern', u'Central', 18345.0, u'Indiana Pacers'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Toyota Center (Houston)', u'', u'', u'1510 Polk Street', u'', u'', u'', u'Houston', u'TX', u'77002', u'77002-7130', u'Harris', u'Houston', 6.0, 29.75078, -95.36218, u'High', u'NGA', u'Shares arena with Comets (WNBA).', u'Western', u'Southwest', 18300.0, u'Houston Rockets'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Palace of Auburn Hills', u'', u'', u'2 Championship Drive', u'', u'', u'', u'Auburn Hills', u'MI', u'48326', u'', u'Oakland', u'Detroit', 5.0, 42.69721, -83.24467, u'High', u'NGA', u'Shares arena with Shocks (WNBA).', u'Eastern', u'Central', 22076.0, u'Detroit Pistons'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'AT&T Center', u'', u'', u'1 AT&T Center Parkway', u'', u'', u'', u'San Antonio', u'TX', u'78219', u'', u'Bexar', u'San Antonio', 6.0, 29.42703, -98.43766, u'High', u'NGA', u'Shares arena with Silver Stars (WNBA), Rampage (AHL).', u'Western', u'Southwest', 18581.0, u'San Antonio Spurs'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20060411', u'20100215', u'', u'Ford Center', u'', u'', u'100 West Reno Avenue', u'', u'', u'', u'Oklahoma City', u'OK', u'73102', u'73102-2473', u'Oklahoma', u'Oklahoma City', 6.0, 35.46347, -97.51483, u'High', u'NGA', u'', u'Western', u'Southwest', 18203.0, u'Oklahoma City Thunder'], [u'High Value/Symbolic', u'Sports Arena', u'NBA', u'20100215', u'', u'', u'Air Canada Centre', u'', u'', u'40 Bay Street', u'', u'', u'', u'Toronto', u'ON', u'M5J', u'2X2', u'', u'', 0.0, 43.64333, -79.37916, u'High', u'NGA', u'Shares arena with Maple Leafs (NHL) and Rock (NLL).', u'Eastern', u'Atlantic', 19800.0, u'Toronto Raptors']]
Traceback (most recent call last):
File "C:/Users/test.py", line 22, in <module>
arena_shapefile_tk = shapefile.Reader(arenafile_tk)
File "C:Python27libsite-packagesshapefile.py", line 546, in __init__
raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
shapefile.ShapefileException: Shapefile Reader requires a shapefile or file-like object.
Process finished with exit code 1
Link to Arena shapefile
python python-2.7 tkinter shapefile
python python-2.7 tkinter shapefile
asked Nov 25 '18 at 19:15
TorenToren
2,21572946
2,21572946
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Short answer: try:
arenafile_tk = tkFileDialog.askopenfilename()
instead of:
arenafile_tk = tkFileDialog.askopenfile()
and adjust the arguments accordingly.
Long answer: A shapefile consists of multiple files, when you open the ".shp" file name, it seeks out the others:
arena_shapefile = shapefile.Reader(r"dataArenas_NBAArenas_NBA.shp")
If you try to pass an open file handle, as returned by askopenfile()
, it expects you to provide information about those other files:
arena_shp_file = open(r"dataArenas_NBAArenas_NBA.shp", "rb")
arena_dbf_file = open(r"dataArenas_NBAArenas_NBA.dbf", "rb")
arena_shapefile = shapefile.Reader(shp=arena_shp_file, dbf=arena_dbf_file)
Or some such.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470987%2fread-shapefile-with-tkinter-produce-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Short answer: try:
arenafile_tk = tkFileDialog.askopenfilename()
instead of:
arenafile_tk = tkFileDialog.askopenfile()
and adjust the arguments accordingly.
Long answer: A shapefile consists of multiple files, when you open the ".shp" file name, it seeks out the others:
arena_shapefile = shapefile.Reader(r"dataArenas_NBAArenas_NBA.shp")
If you try to pass an open file handle, as returned by askopenfile()
, it expects you to provide information about those other files:
arena_shp_file = open(r"dataArenas_NBAArenas_NBA.shp", "rb")
arena_dbf_file = open(r"dataArenas_NBAArenas_NBA.dbf", "rb")
arena_shapefile = shapefile.Reader(shp=arena_shp_file, dbf=arena_dbf_file)
Or some such.
add a comment |
Short answer: try:
arenafile_tk = tkFileDialog.askopenfilename()
instead of:
arenafile_tk = tkFileDialog.askopenfile()
and adjust the arguments accordingly.
Long answer: A shapefile consists of multiple files, when you open the ".shp" file name, it seeks out the others:
arena_shapefile = shapefile.Reader(r"dataArenas_NBAArenas_NBA.shp")
If you try to pass an open file handle, as returned by askopenfile()
, it expects you to provide information about those other files:
arena_shp_file = open(r"dataArenas_NBAArenas_NBA.shp", "rb")
arena_dbf_file = open(r"dataArenas_NBAArenas_NBA.dbf", "rb")
arena_shapefile = shapefile.Reader(shp=arena_shp_file, dbf=arena_dbf_file)
Or some such.
add a comment |
Short answer: try:
arenafile_tk = tkFileDialog.askopenfilename()
instead of:
arenafile_tk = tkFileDialog.askopenfile()
and adjust the arguments accordingly.
Long answer: A shapefile consists of multiple files, when you open the ".shp" file name, it seeks out the others:
arena_shapefile = shapefile.Reader(r"dataArenas_NBAArenas_NBA.shp")
If you try to pass an open file handle, as returned by askopenfile()
, it expects you to provide information about those other files:
arena_shp_file = open(r"dataArenas_NBAArenas_NBA.shp", "rb")
arena_dbf_file = open(r"dataArenas_NBAArenas_NBA.dbf", "rb")
arena_shapefile = shapefile.Reader(shp=arena_shp_file, dbf=arena_dbf_file)
Or some such.
Short answer: try:
arenafile_tk = tkFileDialog.askopenfilename()
instead of:
arenafile_tk = tkFileDialog.askopenfile()
and adjust the arguments accordingly.
Long answer: A shapefile consists of multiple files, when you open the ".shp" file name, it seeks out the others:
arena_shapefile = shapefile.Reader(r"dataArenas_NBAArenas_NBA.shp")
If you try to pass an open file handle, as returned by askopenfile()
, it expects you to provide information about those other files:
arena_shp_file = open(r"dataArenas_NBAArenas_NBA.shp", "rb")
arena_dbf_file = open(r"dataArenas_NBAArenas_NBA.dbf", "rb")
arena_shapefile = shapefile.Reader(shp=arena_shp_file, dbf=arena_dbf_file)
Or some such.
answered Nov 25 '18 at 20:01
cdlanecdlane
19.3k21145
19.3k21145
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53470987%2fread-shapefile-with-tkinter-produce-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown