GEEK BOY'S BLOG

Peter Clark on life, coding, parenthood, Java, Scala, Ruby, grad school, and demographic data

Playing with PostGIS

I’m working on some stuff for work that involves integrating spatial data (both vector and raster), census microdata, and census tables. Neat stuff. PostgresSQL and PostGIS look like they’ll be extremely useful but I’ve just gotten started learning. I also had the opportunity to contribute a minor bugfix to PostGIS 2.0. Hopefully it won’t be the last one.

For someone coming from a traditional SQL background, the geometry functions take some getting used to. I’ve spent more time in MySQL than anything else, but I tend to think in the Transact-SQL dialect used by Sybase and MS SQL Server, particularly for join syntax. It’s pleasant that PostgreSQL supports a similar join syntax!

I wrote up some simple queries, to play with the spatial functions and to see if they behave the way I expect. I offer them here with no guarantee of usefulness, just a hope that they might prove to be a good starting point for the next adventurer.

This is using PostGIS 2.0-SVN as checked out from the svn repository on Jan 5th, 2012, but none of these functions should be PostGIS 2.0 specific. Once I start playing with the raster stuff, that may no longer be true.

# PostGIS notes:
create table my_geom (id serial NOT NULL PRIMARY KEY, name varchar(20));

select AddGeometryColumn('public', 'my_geom', 'my_polygons', -1, 'POLYGON', 2);

insert into my_geom(name, my_polygons) values ('square1',
    ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'));

insert into my_geom(name, my_polygons) values ('square2',
        ST_GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));

# approximate an approximation of a circle of radius 1, centered at 1,1
insert into my_geom(name, my_polygons) values ('circle1', ST_Buffer(ST_GeomFromText('POINT(1 1)'), 1));

# what did we just insert?
select id, name, ST_AsText(my_polygons) from my_geom g1;

# and are they valid?
select name, ST_IsValid(my_polygons) from my_geom;

# how big are they?
select name, ST_Area(my_polygons), ST_Perimeter(my_polygons) from my_geom;

# do square1 and square2 intersect?
select ST_Intersects(g1.my_polygons, g2.my_polygons)
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name = 'square2';

# What's the intersection between the two squares? (should be the same as square1)
select ST_AsText(ST_Intersection(g1.my_polygons, g2.my_polygons))
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name = 'square2';

# Is it really the same as square1?
select ST_Equals(g1.my_polygons, ST_Intersection(g1.my_polygons, g2.my_polygons))
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name = 'square2';

# What's the symmetric difference?
select ST_AsText(ST_SymDifference(g1.my_polygons, g2.my_polygons))
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name = 'square2';

# What is the area of the difference (should be 3)
select ST_Area(ST_SymDifference(g1.my_polygons, g2.my_polygons))
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name = 'square2';

# What is the area of the difference between square1 and the other two shapes?
select g2.name, ST_Area(ST_SymDifference(g1.my_polygons, g2.my_polygons))
from my_geom g1, my_geom g2
where g1.name = 'square1' and g2.name != 'square1';


drop table my_geom;

Filed under  //   learning   postgis   postgresql  

Looks like I've officially graduated!

Got a happy email from the U of Mn Graduate School on Jan 4th. They said:

Dear Peter,
Congratulations! You have completed all requirements for your M S degree in Computer Science. Your degree award was awarded 12/30/2011.

Your official transcript will be updated, to show the award of the degree, 2-3 weeks following the award date. Official transcripts may be obtained from the One Stop office.  Your diploma will be mailed to you 4-6 weeks following the award date by the One Stop office.  If you need to change the address to which the diploma will be mailed, you may contact One Stop at 612-624-1111.

Note: Posting of your degree is contingent upon payment of all assessed University fees, fines and bills.  

Congratulations on your accomplishments at the University of Minnesota.  We wish you all the best with your new endeavors.

Thankfully, my student account shows a balance of $0.00. Yay!

I passed my final oral exam for my master's degree!

Hey - grad school? We need to talk. It's been a good run, this relationship, but I think we need to start seeing other people. Or at least, I do. It's not you, really, it's me. I'm through. I'm done. We had some good times, you and me, but now it's time to move on. Thanks. Really - I mean that. Let's stay in touch - you know where to find me.

Filed under  //   grad school   umn  

Overheard at a party last night

Girl: Yeah, I got dumped a couple weeks ago...

Guy: So, what does your dad do?

Girl: He's a cop.

Guy: Well, that's the end of that conversation!

 

Thanks, Steve.

In 1992, I was working for a small and ultimately unsuccessful NeXTStep ISV named Appsoft. NeXT had recently cancelled their beautiful black hardware and announced that the OS was being ported to the Intel 486 architecture. They set up a porting lab at NeXT HQ in Redwood City, and I spent a couple days at the porting lab getting the spreadsheet running on Intel.

On one of those days in the porting lab, Steve Jobs walked by, and I waved to him. He came in and asked what I was working on, and what I thought of the Intel stuff. I gave him a demo of the spreadsheet as best I could (the UI layer worked fine on Intel but the calc engine was horribly broken). He had some good ideas (including suggesting that we should explore junking the existing spreadsheet and seeing if Borland would license the Quattro Pro engine to us). Steve had some minor suggestions about the UI, and got me in touch with some of the compiler guys to help troubleshoot the calc engine issues. He was helpful and polite and put me at ease - lord knows I was intimidated at doing an impromptu demo for the guy. It wasn't a long meeting in any sense, and I never had the privilege of meeting him again for any length of time, but it certainly made an impression on me.

That memory is nearly twenty years old, but I remember it vividly. I'm grateful to have had the opportunity to meet one of my heroes.

Steve's been an inspiration to multiple generations of technologists, and the field is far better for it. His passion for getting the design right and intolerance for close-enough solutions is well-documented and is a source of personal inspiration. As I type this, I sit in my home office surrounded by products that he'd had a hand in developing - an iPhone and iPad, a Macbook Air, and a NeXTCube (Yes, I have one. Yes, it still boots. No, I'm never getting rid of it.) I've got other stuff in the office as well, but the gear that runs Mac OS/X and iOS - the stuff that blossomed from the NeXTStep environment - is what gets used. That ethos of close-enough isn't good enough is the reason why.

My career would be very different if he hadn't been around - frankly, I'd probably be a chemist rather than a software guy. I'll miss him. We'll not soon see his like again.

 

Filed under  //   NeXT   apple   appsoft   sad   steve jobs  

Crazy Politics

Our own Michelle Bachmann recently said:

“I don't know how much God has to do to get the attention of the politicians. We've had an earthquake; we’ve had a hurricane. He said, 'Are you going to start listening to me here? Listen to the American people because the American people are roaring right now. They know government is on a morbid obesity diet and we've got to rein in the spending.' ”

Hmmm...

I note that, as I write this, both Texas - the home state of Rick Perry - and Minnesota - the home state of Michelle Bachmann - are on fire. Perry and Bachmann are the two presidential candidates most strongly associated with the extrovert, outrageous side of the Tea Party.

Both states are ON FIRE. What's the message from God in that, Michelle?

Filed under  //   fire   politics   presidential election   tea party  

IOS iPad iTunes error E800002D

id Software put their IOS video game, Rage HD, out for free today. I was happy to download it, but was unhappy when it wouldn't install on my first-gen iPad. iTunes responded with an error, with the unhelpful error code of 0xE800002D. Googling this turned up surprisingly little.

It turned out that the solution was to turn off Parental Controls on the iPad. I had things set to only allow apps rated 12 or younger to run for when my kids are playing with it, and that appeared to be preventing Rage from installing. Turning off parental controls allowed it to install and run.

YMMV.

Apple Boot Camp 4.0 and an old MacBook pro "Boot Camp x64 is unsupported on this computer model"

I'm working on getting Win7 set up on a middle-aged MacBook Pro, and when running the boot camp installer from within Win7, I got a surprising error stating "Boot Camp x64 is unsupported on this computer model". Which kind of sucks.

There are a variety of web pages and messages on apple forums stating how to get around this, most of which say go to the Drivers/Apple folder and then run the BootCampx64.msi file in compatibility mode. This evidently worked in BootCamp 3, but it doesn't in Bootcamp 4 which ships with Lion. The installer responds with an error saying that it needs to run with elevated privileges.

What worked for me was to run a command prompt window as administrator, and then run msiexec /i bootcampx64.msi from the command line.

Hope this works for you as well.

Goodbye Florida?

Looks like Google Maps had a hiccup... or maybe the post-rapture apocalypse got an early start.

 

Goodbye_florida

Posted June 2, 2011