diff --git a/mbtiles.cpp b/mbtiles.cpp index b456f705..47246ce7 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -550,7 +550,7 @@ std::map merge_layermaps(std::vectorsecond.sample_values) { auto pt = std::lower_bound(fk2->second.sample_values.begin(), fk2->second.sample_values.end(), val); - if (pt == fk2->second.sample_values.end() || *pt != val) { // not found + if (pt == fk2->second.sample_values.end() || *pt != val) { // not found fk2->second.sample_values.insert(pt, val); if (fk2->second.sample_values.size() > 1000) { @@ -610,7 +610,7 @@ void add_to_file_keys(std::map &file_keys, s } auto pt = std::lower_bound(fka->second.sample_values.begin(), fka->second.sample_values.end(), val); - if (pt == fka->second.sample_values.end() || *pt != val) { // not found + if (pt == fka->second.sample_values.end() || *pt != val) { // not found fka->second.sample_values.insert(pt, val); if (fka->second.sample_values.size() > 1000) { diff --git a/mbtiles.hpp b/mbtiles.hpp index 8a91528c..bd156066 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -14,7 +14,7 @@ struct type_and_string { }; struct type_and_string_stats { - std::vector sample_values; // sorted + std::vector sample_values; // sorted double min = INFINITY; double max = -INFINITY; int type = 0; diff --git a/tests/join-population/joined-i.mbtiles.json b/tests/join-population/joined-i.mbtiles.json index 6767c8fc..1662a749 100644 --- a/tests/join-population/joined-i.mbtiles.json +++ b/tests/join-population/joined-i.mbtiles.json @@ -7,7 +7,7 @@ "maxzoom": "12", "minzoom": "0", "name": "tests/join-population/tabblock_06001420.mbtiles", -"tilestats": "{\"layerCount\": 1,\"layers\": [{\"layer\": \"tabblock_06001420\",\"count\": 0,\"geometry\": \"Point\",\"attributeCount\": 15,\"attributes\": [{\"attribute\": \"ALAND10\",\"count\": 257,\"type\": \"number\",\"values\": [0,10019,10125,1018,1027,10320,10339,1037,1060,10769,10776,1094,10961,10975,11206,11282,11297,11306,11372,11825,11921,11928,11997,1201,12044,12062,1214,12213,1246,12579,1269,12945,13013,13106,1324,13452,13985,14000,14042,14044,14053,14087,14101,14158,14169,14185,14193,14219,14237,14270,14291,14449,14452,14453,14523,14539,14541,14557,14565,1457,14593,1461,14639,1466,14791,14799,14980,1509,15100,15240,15260,15494,15574,15665,15730,15921,15930,15974,16117,16120,16165,16183,16238,16246,16253,16332,16353,16431,16453,16535,16537,16605,16635,16691,16994,1704,17210,17230,17265,17308],\"min\": 0.000000,\"max\": 542505.000000},{\"attribute\": \"AWATER10\",\"count\": 4,\"type\": \"number\",\"values\": [0,1111196,1632801,24],\"min\": 0.000000,\"max\": 1632801.000000},{\"attribute\": \"BLOCKCE10\",\"count\": 82,\"type\": \"string\",\"values\": [\"1000\",\"1001\",\"1002\",\"1003\",\"1004\",\"1005\",\"1006\",\"1007\",\"1008\",\"1009\",\"1010\",\"1011\",\"1012\",\"1013\",\"1014\",\"1015\",\"1016\",\"1017\",\"1018\",\"1019\",\"1020\",\"1021\",\"1022\",\"1023\",\"1024\",\"1025\",\"1026\",\"1027\",\"1028\",\"1029\",\"1030\",\"1031\",\"2000\",\"2001\",\"2002\",\"2003\",\"2004\",\"2005\",\"2006\",\"2007\",\"2008\",\"2009\",\"2010\",\"2011\",\"2012\",\"2013\",\"2014\",\"2015\",\"2016\",\"2017\",\"3000\",\"3001\",\"3002\",\"3003\",\"3004\",\"3005\",\"3006\",\"3007\",\"3008\",\"3009\",\"3010\",\"3011\",\"3012\",\"3013\",\"3014\",\"3015\",\"3016\",\"3017\",\"3018\",\"3019\",\"3020\",\"3021\",\"3022\",\"3023\",\"3024\",\"3025\",\"3026\",\"3027\",\"3028\",\"3029\",\"3030\",\"3031\"]},{\"attribute\": \"COUNTYFP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"001\"]},{\"attribute\": \"FUNCSTAT10\",\"count\": 1,\"type\": \"string\",\"values\": [\"S\"]},{\"attribute\": \"INTPTLAT10\",\"count\": 260,\"type\": \"string\",\"values\": [\"+37.8827246\",\"+37.8828579\",\"+37.8829654\",\"+37.8832245\",\"+37.8833234\",\"+37.8834620\",\"+37.8834653\",\"+37.8834818\",\"+37.8834939\",\"+37.8835272\",\"+37.8835363\",\"+37.8835790\",\"+37.8836558\",\"+37.8836932\",\"+37.8837071\",\"+37.8837458\",\"+37.8838362\",\"+37.8838716\",\"+37.8838753\",\"+37.8839314\",\"+37.8839739\",\"+37.8839955\",\"+37.8840099\",\"+37.8840797\",\"+37.8841984\",\"+37.8842028\",\"+37.8843388\",\"+37.8843696\",\"+37.8844362\",\"+37.8846770\",\"+37.8847438\",\"+37.8847470\",\"+37.8847579\",\"+37.8848967\",\"+37.8849026\",\"+37.8849195\",\"+37.8849426\",\"+37.8853070\",\"+37.8853080\",\"+37.8853992\",\"+37.8854489\",\"+37.8854914\",\"+37.8856449\",\"+37.8856461\",\"+37.8856733\",\"+37.8858112\",\"+37.8858279\",\"+37.8859970\",\"+37.8861594\",\"+37.8861944\",\"+37.8861973\",\"+37.8862375\",\"+37.8862789\",\"+37.8863229\",\"+37.8863390\",\"+37.8864397\",\"+37.8864607\",\"+37.8864950\",\"+37.8865874\",\"+37.8865962\",\"+37.8866087\",\"+37.8867580\",\"+37.8868308\",\"+37.8869296\",\"+37.8870993\",\"+37.8871632\",\"+37.8872385\",\"+37.8872675\",\"+37.8873248\",\"+37.8873799\",\"+37.8874129\",\"+37.8875706\",\"+37.8877645\",\"+37.8877763\",\"+37.8877891\",\"+37.8878520\",\"+37.8878852\",\"+37.8878859\",\"+37.8879165\",\"+37.8879459\",\"+37.8880279\",\"+37.8881229\",\"+37.8882387\",\"+37.8883258\",\"+37.8883323\",\"+37.8883405\",\"+37.8884164\",\"+37.8884185\",\"+37.8884410\",\"+37.8884411\",\"+37.8884580\",\"+37.8885068\",\"+37.8885114\",\"+37.8885408\",\"+37.8886165\",\"+37.8886345\",\"+37.8887349\",\"+37.8887826\",\"+37.8888233\",\"+37.8888488\"]},{\"attribute\": \"INTPTLON10\",\"count\": 260,\"type\": \"string\",\"values\": [\"-122.2823202\",\"-122.2823713\",\"-122.2826795\",\"-122.2826890\",\"-122.2829474\",\"-122.2830673\",\"-122.2832122\",\"-122.2834249\",\"-122.2836511\",\"-122.2837239\",\"-122.2837979\",\"-122.2838288\",\"-122.2839247\",\"-122.2839734\",\"-122.2844715\",\"-122.2845719\",\"-122.2845906\",\"-122.2848310\",\"-122.2850205\",\"-122.2850766\",\"-122.2850935\",\"-122.2851750\",\"-122.2856099\",\"-122.2856518\",\"-122.2856823\",\"-122.2859011\",\"-122.2859716\",\"-122.2861793\",\"-122.2863241\",\"-122.2863490\",\"-122.2863663\",\"-122.2866157\",\"-122.2866366\",\"-122.2868181\",\"-122.2868653\",\"-122.2869139\",\"-122.2870554\",\"-122.2870824\",\"-122.2870976\",\"-122.2871259\",\"-122.2872058\",\"-122.2872753\",\"-122.2873239\",\"-122.2873798\",\"-122.2875836\",\"-122.2875914\",\"-122.2876349\",\"-122.2877473\",\"-122.2877578\",\"-122.2878360\",\"-122.2879267\",\"-122.2879697\",\"-122.2881508\",\"-122.2882217\",\"-122.2882377\",\"-122.2883131\",\"-122.2883823\",\"-122.2883829\",\"-122.2884737\",\"-122.2886022\",\"-122.2886289\",\"-122.2886774\",\"-122.2886965\",\"-122.2887646\",\"-122.2887874\",\"-122.2889102\",\"-122.2890200\",\"-122.2892190\",\"-122.2894711\",\"-122.2894724\",\"-122.2895305\",\"-122.2895702\",\"-122.2895731\",\"-122.2896635\",\"-122.2897641\",\"-122.2899595\",\"-122.2901174\",\"-122.2903402\",\"-122.2904413\",\"-122.2905229\",\"-122.2905730\",\"-122.2906157\",\"-122.2909643\",\"-122.2909809\",\"-122.2911376\",\"-122.2912175\",\"-122.2913154\",\"-122.2913507\",\"-122.2913917\",\"-122.2914745\",\"-122.2914849\",\"-122.2915924\",\"-122.2918172\",\"-122.2919263\",\"-122.2920141\",\"-122.2921162\",\"-122.2921539\",\"-122.2922894\",\"-122.2923093\",\"-122.2923947\"]},{\"attribute\": \"MTFCC10\",\"count\": 1,\"type\": \"string\",\"values\": [\"G5040\"]},{\"attribute\": \"NAME10\",\"count\": 82,\"type\": \"string\",\"values\": [\"Block 1000\",\"Block 1001\",\"Block 1002\",\"Block 1003\",\"Block 1004\",\"Block 1005\",\"Block 1006\",\"Block 1007\",\"Block 1008\",\"Block 1009\",\"Block 1010\",\"Block 1011\",\"Block 1012\",\"Block 1013\",\"Block 1014\",\"Block 1015\",\"Block 1016\",\"Block 1017\",\"Block 1018\",\"Block 1019\",\"Block 1020\",\"Block 1021\",\"Block 1022\",\"Block 1023\",\"Block 1024\",\"Block 1025\",\"Block 1026\",\"Block 1027\",\"Block 1028\",\"Block 1029\",\"Block 1030\",\"Block 1031\",\"Block 2000\",\"Block 2001\",\"Block 2002\",\"Block 2003\",\"Block 2004\",\"Block 2005\",\"Block 2006\",\"Block 2007\",\"Block 2008\",\"Block 2009\",\"Block 2010\",\"Block 2011\",\"Block 2012\",\"Block 2013\",\"Block 2014\",\"Block 2015\",\"Block 2016\",\"Block 2017\",\"Block 3000\",\"Block 3001\",\"Block 3002\",\"Block 3003\",\"Block 3004\",\"Block 3005\",\"Block 3006\",\"Block 3007\",\"Block 3008\",\"Block 3009\",\"Block 3010\",\"Block 3011\",\"Block 3012\",\"Block 3013\",\"Block 3014\",\"Block 3015\",\"Block 3016\",\"Block 3017\",\"Block 3018\",\"Block 3019\",\"Block 3020\",\"Block 3021\",\"Block 3022\",\"Block 3023\",\"Block 3024\",\"Block 3025\",\"Block 3026\",\"Block 3027\",\"Block 3028\",\"Block 3029\",\"Block 3030\",\"Block 3031\"]},{\"attribute\": \"STATEFP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"06\"]},{\"attribute\": \"TRACTCE10\",\"count\": 6,\"type\": \"string\",\"values\": [\"420100\",\"420200\",\"420300\",\"420400\",\"420500\",\"420600\"]},{\"attribute\": \"UACE10\",\"count\": 1,\"type\": \"string\",\"values\": [\"78904\"]},{\"attribute\": \"UATYP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"U\"]},{\"attribute\": \"UR10\",\"count\": 2,\"type\": \"string\",\"values\": [\"R\",\"U\"]},{\"attribute\": \"population\",\"count\": 73,\"type\": \"number\",\"values\": [1,10,11,1118,113,116,12,13,133,145,15,16,17,18,19,2,21,212,22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,4,40,41,414,42,43,44,45,46,47,49,50,51,53,54,55,56,57,58,60,62,63,64,65,66,68,69,7,70,73,82,83,84,86,87,9,90,91,98],\"min\": 1.000000,\"max\": 1118.000000}]}]}", +"tilestats": "{\"layerCount\": 1,\"layers\": [{\"layer\": \"tabblock_06001420\",\"count\": 0,\"geometry\": \"Point\",\"attributeCount\": 15,\"attributes\": [{\"attribute\": \"ALAND10\",\"count\": 162,\"type\": \"number\",\"values\": [10019,10125,10320,10339,10769,10776,10975,11206,11297,11306,11372,11825,11928,11997,1201,12044,12062,12213,12579,12945,13013,13106,13452,13985,14000,14042,14044,14053,14087,14101,14158,14169,14185,14193,14219,14237,14270,14291,14449,14452,14523,14541,14557,1457,14593,14639,14791,14799,14980,15100,15240,15260,15494,15574,15665,15730,15921,15930,15974,16117,16120,16165,16183,16238,16246,16253,16332,16353,16431,16453,16535,16537,16605,16635,16691,16994,17210,17230,17265,17308,17581,17622,17780,17893,18064,18095,18377,18586,18637,1878,18897,19453,19544,19676,19773,19818,19896,20277,20386,20486],\"min\": 280.000000,\"max\": 412555.000000},{\"attribute\": \"AWATER10\",\"count\": 1,\"type\": \"number\",\"values\": [0],\"min\": 0.000000,\"max\": 0.000000},{\"attribute\": \"BLOCKCE10\",\"count\": 72,\"type\": \"string\",\"values\": [\"1000\",\"1001\",\"1002\",\"1003\",\"1004\",\"1005\",\"1006\",\"1007\",\"1008\",\"1009\",\"1010\",\"1011\",\"1012\",\"1013\",\"1014\",\"1015\",\"1016\",\"1017\",\"1018\",\"1019\",\"1020\",\"1021\",\"1022\",\"1023\",\"1024\",\"1026\",\"1029\",\"1030\",\"1031\",\"2000\",\"2001\",\"2002\",\"2003\",\"2004\",\"2005\",\"2006\",\"2007\",\"2008\",\"2009\",\"2010\",\"2011\",\"2012\",\"2013\",\"2014\",\"2015\",\"3000\",\"3001\",\"3002\",\"3003\",\"3004\",\"3005\",\"3006\",\"3007\",\"3008\",\"3009\",\"3010\",\"3012\",\"3013\",\"3014\",\"3015\",\"3016\",\"3017\",\"3018\",\"3019\",\"3020\",\"3021\",\"3023\",\"3024\",\"3026\",\"3027\",\"3028\",\"3031\"]},{\"attribute\": \"COUNTYFP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"001\"]},{\"attribute\": \"FUNCSTAT10\",\"count\": 1,\"type\": \"string\",\"values\": [\"S\"]},{\"attribute\": \"INTPTLAT10\",\"count\": 162,\"type\": \"string\",\"values\": [\"+37.8827246\",\"+37.8828579\",\"+37.8829654\",\"+37.8832245\",\"+37.8833234\",\"+37.8834620\",\"+37.8834818\",\"+37.8834939\",\"+37.8835272\",\"+37.8835363\",\"+37.8835790\",\"+37.8836932\",\"+37.8837071\",\"+37.8838362\",\"+37.8838753\",\"+37.8839739\",\"+37.8840099\",\"+37.8840797\",\"+37.8843388\",\"+37.8843696\",\"+37.8846770\",\"+37.8847438\",\"+37.8847470\",\"+37.8848967\",\"+37.8849195\",\"+37.8853070\",\"+37.8853080\",\"+37.8854489\",\"+37.8854914\",\"+37.8856461\",\"+37.8858112\",\"+37.8859970\",\"+37.8861594\",\"+37.8861944\",\"+37.8861973\",\"+37.8863229\",\"+37.8863390\",\"+37.8864607\",\"+37.8864950\",\"+37.8865962\",\"+37.8866087\",\"+37.8868308\",\"+37.8872385\",\"+37.8875706\",\"+37.8877891\",\"+37.8879459\",\"+37.8880279\",\"+37.8882387\",\"+37.8883323\",\"+37.8883405\",\"+37.8884164\",\"+37.8884185\",\"+37.8884410\",\"+37.8884411\",\"+37.8884580\",\"+37.8885408\",\"+37.8886165\",\"+37.8886345\",\"+37.8887349\",\"+37.8887826\",\"+37.8888488\",\"+37.8888596\",\"+37.8888638\",\"+37.8889080\",\"+37.8889300\",\"+37.8889340\",\"+37.8890070\",\"+37.8890495\",\"+37.8891261\",\"+37.8891773\",\"+37.8892518\",\"+37.8893267\",\"+37.8894113\",\"+37.8895187\",\"+37.8895455\",\"+37.8896695\",\"+37.8898284\",\"+37.8899556\",\"+37.8900585\",\"+37.8901108\",\"+37.8901660\",\"+37.8901726\",\"+37.8902095\",\"+37.8902144\",\"+37.8902784\",\"+37.8906969\",\"+37.8908584\",\"+37.8910287\",\"+37.8911018\",\"+37.8912006\",\"+37.8912058\",\"+37.8913200\",\"+37.8914257\",\"+37.8915386\",\"+37.8916581\",\"+37.8917135\",\"+37.8917853\",\"+37.8918042\",\"+37.8918093\",\"+37.8918237\"]},{\"attribute\": \"INTPTLON10\",\"count\": 162,\"type\": \"string\",\"values\": [\"-122.2823713\",\"-122.2826890\",\"-122.2830673\",\"-122.2834249\",\"-122.2836511\",\"-122.2837239\",\"-122.2837979\",\"-122.2844715\",\"-122.2845719\",\"-122.2848310\",\"-122.2850205\",\"-122.2851750\",\"-122.2856099\",\"-122.2859011\",\"-122.2859716\",\"-122.2863490\",\"-122.2863663\",\"-122.2866366\",\"-122.2868653\",\"-122.2869139\",\"-122.2870976\",\"-122.2871259\",\"-122.2872058\",\"-122.2872753\",\"-122.2873239\",\"-122.2873798\",\"-122.2875836\",\"-122.2876349\",\"-122.2877473\",\"-122.2877578\",\"-122.2878360\",\"-122.2879267\",\"-122.2879697\",\"-122.2883823\",\"-122.2886022\",\"-122.2886289\",\"-122.2886965\",\"-122.2887646\",\"-122.2887874\",\"-122.2889102\",\"-122.2890200\",\"-122.2892190\",\"-122.2894724\",\"-122.2895305\",\"-122.2895702\",\"-122.2896635\",\"-122.2897641\",\"-122.2899595\",\"-122.2901174\",\"-122.2903402\",\"-122.2904413\",\"-122.2905229\",\"-122.2906157\",\"-122.2909643\",\"-122.2909809\",\"-122.2911376\",\"-122.2912175\",\"-122.2913917\",\"-122.2914745\",\"-122.2918172\",\"-122.2919263\",\"-122.2920141\",\"-122.2921539\",\"-122.2923093\",\"-122.2923947\",\"-122.2926742\",\"-122.2927567\",\"-122.2927774\",\"-122.2928119\",\"-122.2928245\",\"-122.2929060\",\"-122.2932964\",\"-122.2933649\",\"-122.2934559\",\"-122.2934770\",\"-122.2935084\",\"-122.2935928\",\"-122.2936333\",\"-122.2941575\",\"-122.2942136\",\"-122.2943382\",\"-122.2944181\",\"-122.2944569\",\"-122.2945038\",\"-122.2949725\",\"-122.2950398\",\"-122.2951842\",\"-122.2952863\",\"-122.2953196\",\"-122.2953591\",\"-122.2955660\",\"-122.2958883\",\"-122.2960301\",\"-122.2960835\",\"-122.2961445\",\"-122.2961756\",\"-122.2962204\",\"-122.2964053\",\"-122.2964744\",\"-122.2967302\"]},{\"attribute\": \"MTFCC10\",\"count\": 1,\"type\": \"string\",\"values\": [\"G5040\"]},{\"attribute\": \"NAME10\",\"count\": 72,\"type\": \"string\",\"values\": [\"Block 1000\",\"Block 1001\",\"Block 1002\",\"Block 1003\",\"Block 1004\",\"Block 1005\",\"Block 1006\",\"Block 1007\",\"Block 1008\",\"Block 1009\",\"Block 1010\",\"Block 1011\",\"Block 1012\",\"Block 1013\",\"Block 1014\",\"Block 1015\",\"Block 1016\",\"Block 1017\",\"Block 1018\",\"Block 1019\",\"Block 1020\",\"Block 1021\",\"Block 1022\",\"Block 1023\",\"Block 1024\",\"Block 1026\",\"Block 1029\",\"Block 1030\",\"Block 1031\",\"Block 2000\",\"Block 2001\",\"Block 2002\",\"Block 2003\",\"Block 2004\",\"Block 2005\",\"Block 2006\",\"Block 2007\",\"Block 2008\",\"Block 2009\",\"Block 2010\",\"Block 2011\",\"Block 2012\",\"Block 2013\",\"Block 2014\",\"Block 2015\",\"Block 3000\",\"Block 3001\",\"Block 3002\",\"Block 3003\",\"Block 3004\",\"Block 3005\",\"Block 3006\",\"Block 3007\",\"Block 3008\",\"Block 3009\",\"Block 3010\",\"Block 3012\",\"Block 3013\",\"Block 3014\",\"Block 3015\",\"Block 3016\",\"Block 3017\",\"Block 3018\",\"Block 3019\",\"Block 3020\",\"Block 3021\",\"Block 3023\",\"Block 3024\",\"Block 3026\",\"Block 3027\",\"Block 3028\",\"Block 3031\"]},{\"attribute\": \"STATEFP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"06\"]},{\"attribute\": \"TRACTCE10\",\"count\": 6,\"type\": \"string\",\"values\": [\"420100\",\"420200\",\"420300\",\"420400\",\"420500\",\"420600\"]},{\"attribute\": \"UACE10\",\"count\": 1,\"type\": \"string\",\"values\": [\"78904\"]},{\"attribute\": \"UATYP10\",\"count\": 1,\"type\": \"string\",\"values\": [\"U\"]},{\"attribute\": \"UR10\",\"count\": 1,\"type\": \"string\",\"values\": [\"U\"]},{\"attribute\": \"population\",\"count\": 73,\"type\": \"number\",\"values\": [1,10,11,1118,113,116,12,13,133,145,15,16,17,18,19,2,21,212,22,23,24,27,28,29,30,31,32,33,34,35,36,37,38,39,4,40,41,414,42,43,44,45,46,47,49,50,51,53,54,55,56,57,58,60,62,63,64,65,66,68,69,7,70,73,82,83,84,86,87,9,90,91,98],\"min\": 1.000000,\"max\": 1118.000000}]}]}", "type": "overlay", "version": "2" }, "features": [ diff --git a/tile-join.cpp b/tile-join.cpp index 2a8ce6fd..d3cfa70e 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -105,6 +105,8 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map for_tilestats; + if (feat.has_id) { outfeature.has_id = true; outfeature.id = feat.id; @@ -158,7 +160,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::mapsecond.file_keys, key, tas); + for_tilestats.insert(std::pair(key, tas)); } if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) { @@ -210,7 +212,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::mapsecond.file_keys, joinkey, tas); + for_tilestats.insert(std::pair(joinkey, tas)); } } } @@ -241,6 +243,10 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::mapsecond.file_keys, attr.first, attr.second); + } + if (z < file_keys->second.minzoom) { file_keys->second.minzoom = z; }