Sunday, January 22, 2017

Voting Districts Day 3: Yet Another Package Change to Pyshp

Still having trouble with Fiona.  So, I'm trying another package for reading shapefiles:  pyshp.

Pyshp installs through pip without issue (as long as I do it as an admin).  Hooray!  

pyshp comes with the shapefile library, which reads a shapefile into a structure of lists and dictionaries.  

What should I read?  The NC Board of Elections has a shapefile that has  all of the voting districts available on their FTP site.

And after downloading, we can read it like so:
import shapefile
vote = shapefile.Reader('ncsbe\\Precincts.shp') #creates an instance that has the lists of data we want.
shapes = vote.shapes() #lists of coordinates making up the shape for each voting district.  

To figure out the center of the shapefile,  I hope this isn't too simple:
What I should do is get the min/max for both the x and y, then average that.  I'll put it all in a list.

coords = list()

for x in range(0,len(shapes)):
xmin = 10000000
xmax = -10000000
ymin = 10000000
ymax = -10000000
for y in range(0,len(shapes[x].points)):
xmin = min(xmin, shapes[x].points[y][0])
xmax = max(xmax, shapes[x].points[y][0])
ymin = min(ymin, shapes[x].points[y][1])
ymax = max(ymax, shapes[x].points[y][1])
coords.append([xmin, xmax,(xmin + xmax)/2, ymin,ymax, (ymin + ymax)/2])

If I want the metadata for each shape through the records method, this is how to do that.  

recs = vote.records()

For now, I just care about the shapes and their distance relative to one another.  

2 comments:

terry james said...

I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..












I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..










I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..

Florence said...


I started on COPD Herbal treatment from Ultimate Life Clinic, the treatment worked incredibly for my lungs condition. I used the herbal treatment for almost 4 months, it reversed my COPD. My severe shortness of breath, dry cough, chest tightness gradually disappeared. Reach Ultimate Life Clinic via their website www.ultimatelifeclinic.com . I can breath much better and It feels comfortable!