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.
Sunday, January 22, 2017
Sunday, January 1, 2017
Voting Districts Day 2: Wrong Python Packages?
I think that I'm going to switch up and use some different packages for reading this spatial data. In order to use the SciPy stuff, I still need more packages and those packages require some unorthodox installation methods. It includes a ton of stuff I'm not sure I need. So, I'm going to do this one package at a time. Well, two in this case.
It looks like Shapely and Fiona can do what I want initially, which is to read shapefiles and plot them.
When I try to use pip for the install ("pip install Fiona"), it doesn't work. It says I need Microsoft Visual C++.
So, after searching the internet, I discovered that I have to install the packages via a wheel. A plethora of these wheels can be found here at this University of California - Irvine website here.
You also use pip to install these wheels; you just have to download them into the same folder first. Also, I have to run the command prompt as an administrator via a right click when starting the application.
Shapely seemed to work like a charm when attempting the old "import shapely" line in Python. Fiona had other ideas.
Looking at Fiona's documentation, she requires a GDAL package, which was also available on the same UC Irvine page that had the other wheels. I installed that one and was finally able to run "import Fiona" successfully.
So, next time, we'll see about reading the shapefiles.
It looks like Shapely and Fiona can do what I want initially, which is to read shapefiles and plot them.
When I try to use pip for the install ("pip install Fiona"), it doesn't work. It says I need Microsoft Visual C++.
So, after searching the internet, I discovered that I have to install the packages via a wheel. A plethora of these wheels can be found here at this University of California - Irvine website here.
You also use pip to install these wheels; you just have to download them into the same folder first. Also, I have to run the command prompt as an administrator via a right click when starting the application.
Shapely seemed to work like a charm when attempting the old "import shapely" line in Python. Fiona had other ideas.
Looking at Fiona's documentation, she requires a GDAL package, which was also available on the same UC Irvine page that had the other wheels. I installed that one and was finally able to run "import Fiona" successfully.
So, next time, we'll see about reading the shapefiles.
Monday, December 19, 2016
New Python Project: Is there a way to build nonpartisan voting districts?
Gerrymandering seems to make the news every couple of years and every couple of years I wander if there's a solution to the problem. It seems that somebody should have figured out how to make fair and equitable congressional districts by now, right?
I'm a little curious if something like that is possible using some geospatial analysis. What are the roadblocks and what's stopping somebody from pulling this off? Who knows? It's an excuse to learn more about Python and its application to mapping and such.
How much experience do I have with Python and geospatial analysis? none! Well, I've done a little, but with esri's arcpy Python module. This should be WAY harder, but a fun challenge.
Poking around the internet, it looks like Python needs some packages to do what I want (or at least get me started). A place called SciPy can hook me up.
They allow installing via pip, which I've done a couple of times in the past. They even tell me exactly what to type. So, to Command Prompt we go and we'll do the install.
Easy peasy. Next time, we'll see what we've installed and how it can help us.
I'm a little curious if something like that is possible using some geospatial analysis. What are the roadblocks and what's stopping somebody from pulling this off? Who knows? It's an excuse to learn more about Python and its application to mapping and such.
How much experience do I have with Python and geospatial analysis? none! Well, I've done a little, but with esri's arcpy Python module. This should be WAY harder, but a fun challenge.
Poking around the internet, it looks like Python needs some packages to do what I want (or at least get me started). A place called SciPy can hook me up.
They allow installing via pip, which I've done a couple of times in the past. They even tell me exactly what to type. So, to Command Prompt we go and we'll do the install.
Easy peasy. Next time, we'll see what we've installed and how it can help us.
Monday, November 21, 2016
PI Critter Cam Day 16: Better Pictures
I set up the critter cam yesterday afternoon after adjusting the setup.py file in the pi-timolo folder to rotate the pictures 180 degrees and take pictures at a 1080 x 1920 resolution. Luckily, a bird came by to test out the new settings.
The picture looks MUCH better! However, we have a couple issue where it's taking and keeping a TON of pictures and it's overwriting all of the previous pictures.
So, within the setup.py file, I'm going to change the threshold setting to 50, which should make the picture taker less sensitive. I'm also going to change motionnumon to False so it'll use a date/time stamp to name the file. I'm also change motionnummax to 0 in case it's using that setting as justification to delete stuff out there.
We'll set it out again tomorrow morning to see how it does. This time, I'll try setting it on the ground.
Sunday, November 20, 2016
PI Critter Cam Day 15: New Enclosures
After realizing that the previous enclosure wasn't going to work, I dug through my scrap wood bin and slapped together a few 2x2s to build a makeshift food holder. I decided to use one of those birdfood suet bricks, which seemed easier to manage.
I also sacrificed one of my sandwich boxes that I take to work to house the Raspberry PI, drilling a small 3/8" hole for the camera. I sandwiched tack between the lunchbox and the PI in a feeble attempt to keep the water out. I used a clamp to attach the box to the birdfood holder.
It's certainly not the most sophisticated design, but should work as a temporary solution. Here's what we have.
I also sacrificed one of my sandwich boxes that I take to work to house the Raspberry PI, drilling a small 3/8" hole for the camera. I sandwiched tack between the lunchbox and the PI in a feeble attempt to keep the water out. I used a clamp to attach the box to the birdfood holder.
It's certainly not the most sophisticated design, but should work as a temporary solution. Here's what we have.
You can see the camera poking out from this angle with the new battery and PI inside.
I let it sit out all afternoon and it actually took some bird pictures, albeit upside down. Yet, it's exciting to see this thing actually work!
NOTE: I took the suet container out, just leaving the food brick. I was worried the birds couldn't get to the food. I should've moved that thread rod too!
Also, the battery held up really well. The PI ran all day as there were some night pictures in the folder. Although, I'm not sure exactly how long as I haven't been including the wifi dongle in the box to conserve battery, which messes up the PI's clock.
So, our next goals: Get the pics right side up and see how much longer the battery lasts with higher quality pics and the wifi left running.
Friday, November 18, 2016
Pi Critter Cam Day 14: A Step Back
Well, things didn't go as planned.
Every time I start the Pi, it'll take a few pictures, but soon stop working. This is according to the TOP application accessible through the terminal that, I think, acts like a Task Manager and shows all the running applications. pi-timolo shows up for about 15 minutes or so, then disappears from the list of active programs. Somethings amiss.
I tried reinstalling pi-timolo, but that didn't help.
I then tried updating the Raspian operating system using the instructions at raspberrypi.org, which essentially has me run two lines in the terminal.
sudo apt-get update
sudo apt-get dist-upgrade
And that's pretty much it. After it finished doing the update and performing a reboot, pi-timolo was able run all night without crashing. Hooray!
sudo apt-get dist-upgrade
And that's pretty much it. After it finished doing the update and performing a reboot, pi-timolo was able run all night without crashing. Hooray!
However, the birdseed holder and Pi container are other issues. I've got another sandwich box that I plan on using with some scrap wood. I think the USB battery I'm using is also shot. So, I bought another one. I'll put everything together tomorrow and see if we can finally get this thing working...
Saturday, October 15, 2016
PI Critter Cam Day 13 (Part 2): Setting the Trap
Now that we've got the camera looking for animals at startup and have all the other physical components, we are ready to get some animal pictures.
First, I need a way to put birdseed next to the camera. I had some extra Y Guides shark tooth sifters laying around, which will make a great plain for holding birdseed. I'll attach my PI enclosure to that with some wood screws. I'm also going to cover them with tack in an attempt to keep water from entering the enclosure through the screw holes.
Now, we'll put the PI in the enclosure and here's the complete picture.
All we need now is some birdseed!
But wait... the sifter was built with chicken wire and birdseed will fall through that. So, I'll put some plexiglassish material from a broken, cheap picture frame between the chicken wire and sifter frame.
I've plugged in the battery, added the birdseed and clamped it to my deck. All we need now is some critters.
I'm not exactly sure how long the freebie battery will power the PI. I'll check the PI at the end of the day to see if it took any pictures and, if I can figure it out, how long it ran before it died.
Subscribe to:
Posts (Atom)








