Posts Tagged ‘work’

WMS GetFeatureInfo spanning the dateline in OpenLayers

Friday, July 27th, 2012

If you’re using OpenLayers to draw a WMS layer and calling GetFeatureInfo, you’re probably having trouble when looking across the antimeridian, where 180° longitude becomes -180°. This is because OpenLayers sends a bounding box to the WMS server (I’m only dealing with Geoserver 2.1.4 at the moment, not sure on other systems) that includes coordinates beyond the normal limit. If centered over New Zealand it might send a bounding box stretching from 160° to 190°. If your data is in normal (-180->180) space Geoserver won’t find any of the data beyond 180 and if you convert OpenLayers to sending rationalized coordinates (160° to -170°) Geoserver will complain that the minX is greater than the maxX. So what are we to do?
The solution I have come up with is to trim the box you are sending to the server so that it doesn’t cross the dateline. depending on where you were clicking in my example you’d either send 160° to 180° or -180° to -170°. The trick is to work out which side of the dateline you clicked on and which side your view is based on. If your view had been centered on the Chatham Islands OpenLayers would see those same boundaries as -200° to -170°.

Starting from the OpenGeo code to query a wms layer using OpenLayers I added come calculation to trim the bounding box and shift the X and Y values (which are the point the user clicked relative to the top left of the bounding box) if the left boundary has been moved.


map.events.register('click', map, function (e) {

bbox = map.getExtent();
width = map.size.w;
clickX = e.xy.x;

//Start dateline solution
clickRatio = e.xy.x/map.size.w;
fullMapWidth = Math.abs(map.getMaxExtent().left) + Math.abs(map.getMaxExtent().right);
if (bbox.right > map.getMaxExtent().right)
{
datelineRatio = (map.getMaxExtent().right-bbox.left)/(bbox.right-bbox.left);
if(datelineRatio < clickRatio)//Click was far side of dateline, normal bbox would not find data
{
bbox.left = map.getMaxExtent().left;
bbox.right -= fullMapWidth;
clickX -= width * datelineRatio;

width = width * (1-datelineRatio);
}
} else if (bbox.left < map.getMaxExtent().left){
datelineRatio = (map.getMaxExtent().left-bbox.left)/(bbox.right-bbox.left);
if(datelineRatio > clickRatio)//Click was far side of dateline, normal bbox would not find data
{
bbox.right = map.getMaxExtent().right;
bbox.left += fullMapWidth;
width = width * datelineRatio;
}
}
//end dateline solution

var url = wfsPath
+ "?REQUEST=GetFeatureInfo"
+ "&EXCEPTIONS=application/vnd.ogc.se_xml"
+ "&BBOX=" + bbox.toBBOX()
+ "&X=" + Math.round(clickX)
+ "&Y=" + Math.round(e.xy.y)
+ "&INFO_FORMAT=text/html"
+ "&QUERY_LAYERS=" + wfsLayer
+ "&LAYERS=" + wfsLayer
+ "&FEATURE_COUNT=50"
+ "&SRS=EPSG:900913"
+ "&STYLES="
+ "&WIDTH=" + Math.round(width)
+ "&HEIGHT=" + map.size.h;
window.open(url,
"getfeatureinfo",
"location=0,status=0,scrollbars=1,width=600,height=150"
);
});

From a Taranaki oil rig worker

Tuesday, February 10th, 2009

I don’t generally forward on chain emails, let alone post them on my site, but I really like this one.

 

I work, they pay me. I pay my taxes and the government distributes my taxes as it sees fit.

In order to earn that pay cheque, I work on a rig for a drilling contractor.
I am required to pass a random urine test, with which I have no problem.

What I do have a problem with is the distribution of my taxes to people who don’t have to pass a urine test. Shouldn’t one have to pass a urine test to get a welfare cheque because I have to pass one to earn it for them?

Please understand that I have no problem with helping people get back on their feet. I do on the other hand have a problem with helping someone sit on their ass drinking beer and smoking dope.

 

 

Could you imagine how much money the government would save if people had to pass a urine test to get a welfare cheque?

Geotagger 2 – beta testers needed

Tuesday, December 2nd, 2008

I’ve been at my new job for two weeks now and I think my brain is finally starting to warm up after seven months of thinking of pretty much everything other than software development. So now I am pleased to announce Geotagger 2 is just around the corner. I’ve moved pretty much all the code into Objective-C rather than Applescript and thus been able to add a progress indicator to show how many images it has left to process. Personally I don’t want to see hundreds of photos of a city all tagged at a single point within in, but some people have good reasons for tagging lots at the same time and now they’ll know when it’s finished.

Before I start uploading it to bigger sites I’m inviting anyone checking this site to download version 2 and tell me how it goes. I only have one Mac here to test on, so I while I know it works on an Intel running OS X 10.5 I can’t be sure about anything else. So pleeeeease send me feedback.

I’ve also included the latest build of exiftool so it should work with any file type that exiftool can write GPS data to.

Developing

Thursday, November 6th, 2008

I’ve spent this morning setting up my new MacBook’s dev environment to match what I had before. I’m now ready to get back into coding and polishing up the donationware items I released in my former life as a developer. The last two years have seen a lot of my personal time devoted to getting my body and mind into shape for months of isolation and hardcore exercise that comes with crossing countries on foot. Now I’m back on solid ground, thinking about arranging millions of 1s and 0s in a row. It’s an entirely different challenge and one I welcome. I haven’t decided if I can announce where I work just yet. Not that it’s a state secret but I’m not sure on their policies of personal blogs. Rest assured that it’s something I’m really looking forward to in a field I can be pretty happy I’m working in. I’ll try not to bang on about it at parties though :-)

I’ve a week of induction and set up. Then once my brain is back in gear it should flow through to my own projects, if I’m not busy moving house, which I will be.