Skip to content

Instantly share code, notes, and snippets.

@lukec
Created February 25, 2010 19:11
Show Gist options
  • Save lukec/314923 to your computer and use it in GitHub Desktop.
Save lukec/314923 to your computer and use it in GitHub Desktop.
Code:
sub put_package {
my $self = shift;
my $name = shift;
my $package = shift;
my $ua = $self->user_agent;
my $url = $self->api_base . '/package';
my $json = JSON->new->utf8(1)->pretty(1)->encode($package);
$json = URI::Escape::uri_escape_utf8($json);
warn $json;
my $resp = $ua->post($url, Content => $json);
croak "Could not fetch $url: ", $resp->status_line, $resp->content, "\n" if $resp->code != 200;
}
This is the non-urlencoded JSON that gives a 400:
{
"maintainer" : "Government of Canada, Natural Resources Canada, Canada Centre for Remote Sensing, Applications Division",
"version" : "1999-01-01",
"license_id" : 9,
"name" : "geogratisWATERFRACTION1KM_v100",
"author_email" : "richard.fernandes@nrcan.gc.ca",
"author" : "Government of Canada, Natural Resources Canada, Earth Science Sector, Data Management and Dissemination Branch",
"tags" : [
"GeoGratis",
"Canada",
"GCMD",
"Hydrosphere",
"Ground Water",
"Surface Water",
"Hydropattern",
"Rivers/Streams",
"Earth Science",
"Land Surface",
"Land Use/Land Cover",
"Land Cover",
"Landscape"
],
"extras" : {
"License" : "http://geogratis.ca/geogratis/en/licence.jsp",
"Ministry" : "Natural Resources Canada",
"Level of Government" : "Federal"
},
"maintainer_email" : "richard.fernandes@nrcan.gc.ca",
"notes" : "\n This product is a raster coverage representing the fraction of area within each 1km grid cell over Canada's land mass covered by waterbodies, as mapped within the National Topographic Data Base v3.1. In NTDB, waterbody is defined as area covered by open water belonging to one of five categories (section 1.5.1). The product involves negligible errors due to aggregation and data format conversion in comparison with the NTDB digital base maps used in its generation. As such, the errors between mapped and actual water fractions are primarily due to differences between the NTDB source maps and the actual waterbody coverage in a grid cell. Since water area fluctuates seasonally and interanually one should use caution in applying this product for local mapping and modeling purposes. At a minimum, one should verify that the survey dates of the source NTDB maps are appropriate. Furthermore, some consideration should be given to seasonal shifts in waterbody extent. The majority of NTDB source maps were surveyed within the growing season (post snow-melt) and should therefore be relatively unbiased during the growing season in the absence of drought or severe precipitation events. At regional and national scales we expect that seasonal (weather-induced) fluctuations in water extent are the major uncertainty in water fractions.\n ",
"url" : "http://geogratis.cgdi.gc.ca/geogratis/en/collection/metadata.do?id=67",
"title" : "Geogratis - 1-km Water Fraction From National Topographic Data Base Maps, Canada"
}
This is the URL encoded JSON that gives a 500:
%7B%0A%20%20%20%22maintainer%22%20%3A%20%22Government%20of%20Canada%2C%20Natural%20Resources%20Canada%2C%20Canada%20Centre%20for%20Remote%20Sensing%2C%20Applications%20Division%22%2C%0A%20%20%20%22version%22%20%3A%20%221999-01-01%22%2C%0A%20%20%20%22license_id%22%20%3A%209%2C%0A%20%20%20%22name%22%20%3A%20%22geogratisWATERFRACTION1KM_v100%22%2C%0A%20%20%20%22author_email%22%20%3A%20%22richard.fernandes%40nrcan.gc.ca%22%2C%0A%20%20%20%22author%22%20%3A%20%22Government%20of%20Canada%2C%20Natural%20Resources%20Canada%2C%20Earth%20Science%20Sector%2C%20Data%20Management%20and%20Dissemination%20Branch%22%2C%0A%20%20%20%22tags%22%20%3A%20%5B%0A%20%20%20%20%20%20%22GeoGratis%22%2C%0A%20%20%20%20%20%20%22Canada%22%2C%0A%20%20%20%20%20%20%22GCMD%22%2C%0A%20%20%20%20%20%20%22Hydrosphere%22%2C%0A%20%20%20%20%20%20%22Ground%20Water%22%2C%0A%20%20%20%20%20%20%22Surface%20Water%22%2C%0A%20%20%20%20%20%20%22Hydropattern%22%2C%0A%20%20%20%20%20%20%22Rivers%2FStreams%22%2C%0A%20%20%20%20%20%20%22Earth%20Science%22%2C%0A%20%20%20%20%20%20%22Land%20Surface%22%2C%0A%20%20%20%20%20%20%22Land%20Use%2FLand%20Cover%22%2C%0A%20%20%20%20%20%20%22Land%20Cover%22%2C%0A%20%20%20%20%20%20%22Landscape%22%0A%20%20%20%5D%2C%0A%20%20%20%22extras%22%20%3A%20%7B%0A%20%20%20%20%20%20%22License%22%20%3A%20%22http%3A%2F%2Fgeogratis.ca%2Fgeogratis%2Fen%2Flicence.jsp%22%2C%0A%20%20%20%20%20%20%22Ministry%22%20%3A%20%22Natural%20Resources%20Canada%22%2C%0A%20%20%20%20%20%20%22Level%20of%20Government%22%20%3A%20%22Federal%22%0A%20%20%20%7D%2C%0A%20%20%20%22maintainer_email%22%20%3A%20%22richard.fernandes%40nrcan.gc.ca%22%2C%0A%20%20%20%22notes%22%20%3A%20%22%5Cn%20%20%20%20%20%20%20%20%20This%20product%20is%20a%20raster%20coverage%20representing%20the%20fraction%20of%20area%20within%20each%201km%20grid%20cell%20over%20Canada's%20land%20mass%20covered%20by%20waterbodies%2C%20as%20mapped%20within%20the%20National%20Topographic%20Data%20Base%20v3.1.%20In%20NTDB%2C%20waterbody%20is%20defined%20as%20area%20covered%20by%20open%20water%20belonging%20to%20one%20of%20five%20categories%20(section%201.5.1).%20The%20product%20involves%20negligible%20errors%20due%20to%20aggregation%20and%20data%20format%20conversion%20in%20comparison%20with%20the%20NTDB%20digital%20base%20maps%20used%20in%20its%20generation.%20As%20such%2C%20the%20errors%20between%20mapped%20and%20actual%20water%20fractions%20are%20primarily%20due%20to%20differences%20between%20the%20NTDB%20source%20maps%20and%20the%20actual%20waterbody%20coverage%20in%20a%20grid%20cell.%20Since%20water%20area%20fluctuates%20seasonally%20and%20interanually%20one%20should%20use%20caution%20in%20applying%20this%20product%20for%20local%20mapping%20and%20modeling%20purposes.%20At%20a%20minimum%2C%20one%20should%20verify%20that%20the%20survey%20dates%20of%20the%20source%20NTDB%20maps%20are%20appropriate.%20Furthermore%2C%20some%20consideration%20should%20be%20given%20to%20seasonal%20shifts%20in%20waterbody%20extent.%20The%20majority%20of%20NTDB%20source%20maps%20were%20surveyed%20within%20the%20growing%20season%20(post%20snow-melt)%20and%20should%20therefore%20be%20relatively%20unbiased%20during%20the%20growing%20season%20in%20the%20absence%20of%20drought%20or%20severe%20precipitation%20events.%20At%20regional%20and%20national%20scales%20we%20expect%20that%20seasonal%20(weather-induced)%20fluctuations%20in%20water%20extent%20are%20the%20major%20uncertainty%20in%20water%20fractions.%5Cn%20%20%20%20%22%2C%0A%20%20%20%22url%22%20%3A%20%22http%3A%2F%2Fgeogratis.cgdi.gc.ca%2Fgeogratis%2Fen%2Fcollection%2Fmetadata.do%3Fid%3D67%22%2C%0A%20%20%20%22title%22%20%3A%20%22Geogratis%20-%201-km%20Water%20Fraction%20From%20National%20Topographic%20Data%20Base%20Maps%2C%20Canada%22%0A%7D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment