Skip to content

Commit

Permalink
add testcase for #122 #128
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Jun 26, 2015
1 parent 41cbf37 commit da46868
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
Binary file added test/data/NZ_Coastline_NZMG.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions test/data/NZ_Coastline_NZMG.prj
@@ -0,0 +1 @@
PROJCS["NZGD49_New_Zealand_Map_Grid",GEOGCS["GCS_New_Zealand_1949",DATUM["D_New_Zealand_1949",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["New_Zealand_Map_Grid"],PARAMETER["latitude_of_origin",-41],PARAMETER["Longitude_Of_Origin",173],PARAMETER["false_easting",2510000],PARAMETER["false_northing",6023150],UNIT["Meter",1]]
1 change: 1 addition & 0 deletions test/data/NZ_Coastline_NZMG.qpj
@@ -0,0 +1 @@
PROJCS["NZGD49 / New Zealand Map Grid",GEOGCS["NZGD49",DATUM["New_Zealand_Geodetic_Datum_1949",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY["EPSG","6272"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4272"]],PROJECTION["New_Zealand_Map_Grid"],PARAMETER["latitude_of_origin",-41],PARAMETER["central_meridian",173],PARAMETER["false_easting",2510000],PARAMETER["false_northing",6023150],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","27200"]]
Binary file added test/data/NZ_Coastline_NZMG.shp
Binary file not shown.
Binary file added test/data/NZ_Coastline_NZMG.shx
Binary file not shown.
77 changes: 77 additions & 0 deletions test/vector_tile.cpp
Expand Up @@ -1151,3 +1151,80 @@ TEST_CASE( "vector tile transform", "should not throw on coords outside merc ran
mapnik::save_to_file(im,"test/fixtures/transform-actual-1.png","png32");
}
}

TEST_CASE( "vector tile transform2", "should not throw reprojected data from local NZ projection" ) {
typedef mapnik::vector_tile_impl::backend_pbf backend_type;
typedef mapnik::vector_tile_impl::processor<backend_type> renderer_type;
typedef vector_tile::Tile tile_type;
tile_type tile;
backend_type backend(tile,64);
unsigned tile_size = 256;
mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
mapnik::Map map(tile_size,tile_size,"+init=epsg:3857");
// Note: 4269 is key. 4326 will trigger custom mapnik reprojection code
// that does not hit proj4 and clamps values
mapnik::layer lyr("layer","+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +ellps=intl +units=m +no_defs");
mapnik::parameters params;
params["type"] = "shape";
params["file"] = "./test/data/NZ_Coastline_NZMG.shp";
std::shared_ptr<mapnik::datasource> ds =
mapnik::datasource_cache::instance().create(params);
lyr.set_datasource(ds);
map.add_layer(lyr);
map.zoom_to_box(bbox);
mapnik::request m_req(tile_size,tile_size,bbox);
renderer_type ren(backend,map,m_req);
// should no longer throw after https://github.com/mapbox/mapnik-vector-tile/pull/128
ren.apply();

// serialize to message
std::string buffer;
CHECK(tile.SerializeToString(&buffer));
CHECK(231 == buffer.size());
// now create new objects
mapnik::Map map2(tile_size,tile_size,"+init=epsg:3857");
tile_type tile2;
CHECK(tile2.ParseFromString(buffer));
std::string key("");
CHECK(false == mapnik::vector_tile_impl::is_solid_extent(tile2,key));
CHECK("" == key);
CHECK(1 == tile2.layers_size());
vector_tile::Tile_Layer const& layer2 = tile2.layers(0);
CHECK(std::string("layer") == layer2.name());
CHECK(2 == layer2.features_size());

mapnik::layer lyr2("layer",map.srs());
std::shared_ptr<mapnik::vector_tile_impl::tile_datasource> ds2 = std::make_shared<
mapnik::vector_tile_impl::tile_datasource>(
layer2,0,0,0,map2.width());
ds2->set_envelope(bbox);
CHECK( ds2->type() == mapnik::datasource::Vector );
CHECK( ds2->get_geometry_type() == mapnik::datasource_geometry_t::Collection );
mapnik::layer_descriptor lay_desc = ds2->get_descriptor();
std::vector<std::string> expected_names;
expected_names.push_back("featurecla");
expected_names.push_back("scalerank");
std::vector<std::string> names;
for (auto const& desc : lay_desc.get_descriptors())
{
names.push_back(desc.get_name());
}
CHECK(names == expected_names);
lyr2.set_datasource(ds2);
lyr2.add_style("style");
map2.add_layer(lyr2);
mapnik::load_map(map2,"test/data/polygon-style.xml");
//std::clog << mapnik::save_map_to_string(map2) << "\n";
map2.zoom_to_box(bbox);
mapnik::image_rgba8 im(map2.width(),map2.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren2(map2,im);
ren2.apply();
if (!mapnik::util::exists("test/fixtures/transform-expected-2.png")) {
mapnik::save_to_file(im,"test/fixtures/transform-expected-2.png","png32");
}
unsigned diff = testing::compare_images(im,"test/fixtures/transform-expected-2.png");
CHECK(0 == diff);
if (diff > 0) {
mapnik::save_to_file(im,"test/fixtures/transform-actual-2.png","png32");
}
}

0 comments on commit da46868

Please sign in to comment.