July 26th, 2010

I’ve been banging my head against a wall for a few days on this one, first struggling with ImageMagick, then switching to gdal to get full-resolution geoTIFFs from Cartagen Knitter. I had a ‘duh’ moment just now when I realized that gdalwarp can only do polynomial or thin plate spline warps, neither of which are what I want – that is, perspectival warping. I want to map 4 corner ground control points or GCPs to four latitude/longitude positions. Back to ImageMagick…
I know there are 5 GCPs in the image above – it was the same deal with just 4… it can’t do more than a shear unless you either add the minimum 6 GCPs for a single polynomial warp, or go for a thin plate spline (TPS) distort. A good way to think about TPS is as if the image were a sheet of thin metal (the reason it’s called a TPS) and that you’re bending it in the z-dimension, aplanar. This causes funny curved edges and is not what I’m looking for.
OK, one more note for future reference: see this page for a discussion of different warping techniques and also for the minimum number of GCPs required for different-order polynomial warps.
Tags: bugs, cartagen, code, knitter
Posted in Blog | No Comments »
August 20th, 2009
I was surprised that Google News has no API, so I built my own: Using HTTParty, I wrote a small Ruby library for Google News. Put this in a ‘googlenews.rb’ file in the /lib/ directory of your Rails application to grab google news stories and topic lists.
Haven’t figured out how to get more than 10 items… Safari seems to be able to with feed://news.google.com?output=rss… but I’m not sure how.
gem "httparty"
require "httparty"
class Googlenews
include HTTParty
base_uri 'news.google.com'
def self.items
options = { :query => { :output => 'rss' } }
features = self.get('/news', options)
features['rss']['channel']['item']
end
def self.extract_topic(item)
# ncl=duPfj30A5WoxBHMupoOtlciO1jY1M&
item['description'].match(/ncl=([a-zA-Z0-9]+)&/)[1]
end
def self.topic(item)
options = { :query => { :output => 'rss', :ncl => self.extract_topic(item) } }
features = self.get('/news/more', options)
features['rss']['channel']['item']
end
# store in database (unused)
# def self.story(item)
# item['category']
# item['title']
# item['guid']
# item['description']
# item['link']
# item['pubDate']
# t.string :category, :default => ''
# t.string :title, :default => ''
# t.string :guid, :default => ''
# t.text :description, :default => ''
# t.string :link, :default => ''
# end
end
Once you’ve dropped this in /lib/, you can use it in a Rails controller like this (I needed JSON, to work with the feed in JavaScript):
class DataController < ApplicationController
def latest
render :json => Googlenews.items
end
end
Update: to get more than 10 items, add a GET parameter ‘num=20′ to the feed URL. This works both for topic and for the main feed. I haven’t confirmed this but I think it’s still limited to 30 items. Again, Safari manages to get more, but perhaps it does repeated queries. Still investigating. Anyways, that makes it:
def self.items
options = { :query => { :output => 'rss', :num => '20' } }
features = self.get('/news', options)
features['rss']['channel']['item']
end
Update: This now has a real home on Github, where it’s called ruby-googlenews.
Tags: code
Posted in Blog, code | 2 Comments »