This page was generated from notebooks/io.ipynb. Interactive online version: Binder badge

[1]:
import sys
import os

sys.path.append(os.path.abspath('..'))
import libpysal
[2]:
w = libpysal.weights.lat2W(5,5)
[3]:
w.n
[3]:
25
[4]:
w.pct_nonzero
[4]:
12.8
[5]:
w.neighbors[0]
[5]:
[5, 1]
[6]:
w.neighbors[5]
[6]:
[0, 10, 6]
[7]:
libpysal.examples.available()
[7]:
['georgia',
 '__pycache__',
 'tests',
 'newHaven',
 'Polygon_Holes',
 'nat',
 'Polygon',
 '10740',
 'berlin',
 'rio_grande_do_sul',
 'sids2',
 'sacramento2',
 'burkitt',
 'arcgis',
 'calemp',
 'stl',
 'virginia',
 'geodanet',
 'desmith',
 'book',
 'nyc_bikes',
 'Line',
 'south',
 'snow_maps',
 'Point',
 'street_net_pts',
 'guerry',
 '__pycache__',
 'baltim',
 'networks',
 'us_income',
 'taz',
 'columbus',
 'tokyo',
 'mexico',
 '__pycache__',
 'chicago',
 'wmat',
 'juvenile',
 'clearwater']
[8]:
libpysal.examples.explain('baltim')
[8]:
{'name': 'baltim',
 'description': 'Baltimore house sales prices and hedonics 1978',
 'explanation': ['* baltim.dbf: attribute data. (k=17)',
  '* baltim.shp: Point shapefile. (n=211)',
  '* baltim.shx: spatial index.',
  '* baltim.tri.k12.kwt: kernel weights using a triangular kernel with 12 nearest neighbors in KWT format.',
  '* baltim_k4.gwt: nearest neighbor weights (4nn) in GWT format.',
  '* baltim_q.gal: queen contiguity weights in GAL format.',
  '* baltimore.geojson: spatial weights in geojson format.']}
[9]:
pth = libpysal.examples.get_path('baltim.shp')
[10]:
pth
[10]:
'/home/serge/Dropbox/p/pysal/src/subpackages/libpysal/libpysal/examples/baltim/baltim.shp'
[11]:
shp_file = libpysal.io.open(pth)
[12]:
shapes = [shp for shp in shp_file]
[13]:
shapes[0]
[13]:
(907.0, 534.0)
[14]:
w = libpysal.io.open(libpysal.examples.get_path('baltim_q.gal')).read()
[15]:
w.n
[15]:
211