PHP JSON转换器“不支持的操作数类型”错误
问题描述:
我想创建一个转换器,它将geoJSON文件作为输入并将每个坐标除以1000,然后返回geoJSON。PHP JSON转换器“不支持的操作数类型”错误
代码:
// Copy file content into a string var
$Json_File = file_get_contents("static/data/pol_gem.json");
// Convert the string to a json object
$Json = json_decode($Json_File);
//Declare features variable
$JSONFeatures = array();
//Loop through each feature
foreach ($Json->features as $Feature)
{
//Create array which contains coordinate data of feature
$CoordinateData = array();
//Loop through each coordinate pair of feature
foreach ($Feature->geometry->coordinates as $Coordinates)
{
//Create scaled coordinate pair array
$ScaledCoordinates = array();
//Loop through every coordinate of coordinate pair
foreach ($Coordinates as $Coordinate)
{
//Divide coordinate
$ScaledCoordinate = $Coordinate/1000.00; // ****** ERROR LINE ******
//add coordinate to coordinate pair array
$ScaledCoordinates[] = $ScaledCoordinate;
}
//Add coordinate pair array to coordinate array of feature
$CoordinateData[] = $ScaledCoordinates;
}
//Build feature JSON
$CurrentFeature = [
"type" => "Feature",
"geometry" => [
"type" => "Polygon",
"coordinates" => $CoordinateData,
"properties" => $Feature->properties
]
];
//Add current feature to features array
$JSONFeatures[] = $CurrentFeature;
}
//Create JSON File
$JSONMapData = [
"type" => "FeatureCollection",
"features" => $JSONFeatures
];
我得到的错误: “不支持的操作类型 500内部服务器错误 - FatalThrowableError”。
如果我删除“/ 1000.00”,它将返回与输入文件相同的JSON而不会出错。
的GeoJSON的输入文件的 “静态/数据/ pol_gem.json”(太大引擎收录):
JSON只有1个功能:
{"type":"FeatureCollection","features":[
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-33797.1,216324.69],[-33803.19,216328.5],[-33804.84,216329.53],[-33806.911211649945,216330.8245072812],[-33808.92,216332.08],[-33810.4,216333],[-33813.93,216336.22],[-33815.5938169951,216337.4602241875],[-33825.91,216345.15],[-33830.36,216348.46],[-33831.25,216349.12],[-33833.44,216350.75],[-33834.35,216351.43],[-33891.6,216403.36],[-33909.22,216419.65],[-33905.33,216424.09],[-33904.411,216425.138],[-33893.671,216437.383],[-33889.59,216442.11],[-33885.88,216445.99],[-33877.94,216455.2],[-33868.95,216465.2],[-33859.28,216475.97],[-33853.93,216481.92],[-33850.92,216485.27],[-33844.864,216492.01],[-33837.684,216500],[-33799.01,216543.04],[-33796.487,216545.791],[-33789.553,216553.352],[-33773.081,216571.312],[-33764.312,216580.874],[-33759.633,216585.976],[-33756.871,216588.988],[-33750,216596.541],[-33746.58,216600.3],[-33741.58,216605.84],[-33719.43,216630.31],[-33715.39,216634.56],[-33712.6,216637.49],[-33704.69,216632.22],[-33689.67,216622.85],[-33607.81,216574.76],[-33584.26,216559.32],[-33570.37,216549.14],[-33549.24,216530.06],[-33542.59,216524.02],[-33533.99,216515.37],[-33530.58,216511.55],[-33528.12,216514.42],[-33527.67,216515.14],[-33512.48,216539.47],[-33512.36,216539.67],[-33509.421,216550.085],[-33507.54,216556.75],[-33498.2,216588.55],[-33488.34,216624.34],[-33486.14,216636.31],[-33515.9,216691.96],[-33433.36,216763.54],[-33413.61,216744.95],[-33396.69,216729.22],[-33392.98,216715.88],[-33383.5,216710.91],[-33368.48,216695.13],[-33356.5,216677.58],[-33338.6,216662.98],[-33321.37,216647.08],[-33317.05,216645.21],[-33309.01,216641.73],[-33274.64,216626.87],[-33251.88,216613.45],[-33243.92,216607.93],[-33239.29,216604.71],[-33214.66,216585.1],[-33213.54,216582.77],[-33193.66,216558.77],[-33188.37,216552.28],[-33184.35,216547.43],[-33180.14,216542.2],[-33156.93,216511.72],[-33152.3,216509.58],[-33131.529,216500],[-33125,216496.989],[-33105.25,216487.88],[-33089.11,216480.48],[-33077.943,216500],[-33076.89,216501.84],[-33075.67,216503.98],[-33063.8,216524.72],[-33088.12,216550.71],[-33066.71,216573.69],[-33062.47,216570.31],[-33043.67,216555.35],[-33030.31,216544.71],[-33020.03,216536.53],[-33005.96,216525.66],[-32988.8,216512.45],[-32972.189,216500],[-32946.84,216481],[-32931.85,216468.06],[-32930.5,216466.94],[-32898.59,216440.54],[-32897.68,216440.04],[-32895.82,216439.14],[-32861.76,216422.72],[-32841.05,216412.82],[-32760.41,216374.82],[-32755.91,216371.09],[-32726.07,216346.78],[-32721.65,216343.17],[-32721.55,216343.09],[-32606.01,216282.74],[-32602.71,216282.09],[-32500,216259.116],[-32496.04,216258.23],[-32500,216232.449],[-32502.74,216214.61],[-32500,216214.368],[-32422.19,216207.49],[-32317.69,216208.78],[-32308.34,216208.26],[-32299.33,216208.22],[-32287.32,216208.97],[-32272,216211.21],[-32260.27,216208.38],[-32224.03,216207.29],[-32224.02,216204.75],[-32223.03,216197.67],[-32210.447,216197.782],[-32203.91,216197.84],[-32187.2,216197.99],[-32188.5,216209.2],[-32171.83,216205.85],[-32158.72,216203.22],[-32138.64,216198.99],[-32132.33,216197.66],[-32111.621,216188.028],[-32107.11,216185.93],[-32102.13,216183.91],[-32076.34,216181.75],[-32067.59,216180.33],[-32061.67,216179.37],[-32070.1,216151.04],[-32072.4,216143.06],[-32043.66,216138.19],[-32043.54,216138.17],[-32020.95,216133.86],[-31997.94,216129.6],[-31994.15,216145.38],[-31975.25,216145.39],[-31962.33,216145.4],[-31949.33,216145.41],[-31942.33,216145.41],[-31930.11,216148.87],[-31922.17,216151.11],[-31916.65,216152.68],[-31896,216156.46],[-31887.58,216157.66],[-31875,216159.477],[-31869.09,216160.33],[-31862.82,216161.22],[-31846.54,216164.31],[-31824.48,216167.54],[-31818.11,216168.47],[-31807.86,216171.47],[-31806.16,216171.97],[-31799.66,216173.91],[-31791.21,216176.39],[-31756.686,216187.196],[-31755.78,216187.48],[-31755.439,216187.587],[-31753.07,216188.33],[-31744.48,216187.18],[-31740.499135574093,216182.9988626065],[-31733.15,216175.28],[-31714.68,216163.7],[-31714.13,216163.35],[-31710.94258021671,216167.46137364558],[-31706.92,216172.65],[-31706.834004814245,216173.9542603173],[-31706.743145447377,216175.3322940481],[-31706.62,216177.2],[-31706.51572213893,216181.66656838247],[-31706.488442557707,216182.83504377818],[-31706.44,216184.91],[-31706.17,216191.66],[-31706.1,216193.45],[-31705.99,216196.27],[-31704.39,216200.84],[-31699.587223010694,216214.52462484624],[-31698.55,216217.48],[-31691.53,216218.6],[-31705.585816937597,216226.4058169376],[-31717.82,216233.2],[-31732.85665213545,216241.54603168985],[-31732.88159201141,216241.55987446505],[-31735.26,216242.88],[-31737.73,216243.25],[-31737.36,216245.95],[-31735.07,216262.54],[-31737.639,216271.579],[-31738.48,216274.54],[-31747.85,216275.75],[-31757.77,216299.47],[-31759.11,216302.41],[-31759.32,216319.01],[-31770.84,216331.77],[-31772.63,216346.97],[-31774.714,216356.721],[-31775.72,216361.43],[-31781.29,216369.37],[-31781.17327643576,216372.41333263853],[-31779.92,216405.09],[-31764.843558931334,216407.01989395433],[-31757.89,216407.91],[-31742.13,216409.91],[-31700.7,216422.31],[-31694.77,216405.55],[-31693.231,216401.181],[-31691.19,216395.39],[-31656.07255402788,216395.7025023001],[-31655.23,216395.71],[-31646.46304520607,216396.63125624333],[-31637.72,216397.55],[-31628.58,216392.46],[-31609.54,216389.78],[-31602.39,216389.4],[-31585.28,216388.07],[-31570.4,216386.52],[-31561.85,216386.02],[-31556.58,216385.66],[-31549.89,216385.66],[-31544.02,216385.65],[-31521.87,216383.85],[-31521.141,216383.79],[-31521.13,216383.79],[-31516.16,216383.38],[-31514.43,216383.24],[-31488.72,216379.21],[-31471.53,216382.66],[-31467.79,216414.95],[-31465.99,216419.44],[-31413.21,216411.99],[-31398.23,216412.35],[-31355.2,216409.12],[-31347.39,216408.84],[-31343.87,216408.91],[-31316.73,216409.43],[-31308.65,216411.78],[-31293.7,216416.13],[-31266.5,216417.07],[-31258.08,216416.86],[-31251.71,216416.63],[-31250,216416.51],[-31243.72,216416.07],[-31245.07,216405.05],[-31245.51,216401.52],[-31246.07,216396.47],[-31246.86,216386.29],[-31248.66,216381.87],[-31250,216375.654],[-31253.77,216358.12],[-31259.96,216339.52],[-31250,216334.072],[-31235.08,216325.91],[-31229.66,216325.23],[-31224.7,216324.69],[-31223.569,216324.568],[-31204.46,216322.51],[-31202.95,216322.33],[-31184.67,216319.31],[-31171.02,216318.91],[-31169.95,216318.88],[-31149.78,216316.26],[-31130.75,216315.01],[-31095.71,216308.97],[-31089.54,216308.17],[-31067.02,216305.18],[-31067.18,216303.9],[-31068.44,216294.04],[-31068.71,216290.52],[-31070.57,216266.34],[-31021.7,216262.35],[-31022.52,216251.38],[-31016.4,216250.15],[-31002.11,216247.27],[-30994.286,216245.695],[-30980.65,216242.95],[-30977.77,216242.42],[-30976.9,216244.47],[-30972.02,216255.91],[-30970.22,216260.15],[-30967.097,216259.449],[-30933.94,216252.01],[-30890.81,216252.74],[-30864.91,216253.87],[-30851.84,216242.73],[-30819.43,216242.7],[-30803.62,216251.23],[-30792.98,216266.72],[-30778.02,216288.96],[-30760.12,216297.75],[-30728.94,216312.96],[-30707.48,216320.96],[-30694.88,216345.39],[-30686.88,216364.94],[-30652.97,216404.99],[-30645.61,216396.83],[-30625,216378.92],[-30599.960160440507,216357.17443273787],[-30595.28,216353.11],[-30590.89,216349.33],[-30585.56,216344.74],[-30576.07,216354.61],[-30562.55,216364.84],[-30535.22,216370.69],[-30517.44,216370.96],[-30512.56,216371.3],[-30491.02,216392.72],[-30449.83,216408.33],[-30422.07,216415.96],[-30406.63,216427.58],[-30376.65,216449.52],[-30344.56,216467.41],[-30311.47,216475.82],[-30301.4,216500],[-30291.32,216524.19],[-30269.97,216567.25],[-30257.02,216592.18],[-30204.49,216633.23],[-30193.08,216640.7],[-30188.3,216643.13],[-30184.42,216644.82],[-30152.9,216651.67],[-30134.02,216658.05],[-30123.1,216666.21],[-30112.2,216674.25],[-30077.1,216719.67],[-30024.66,216754.89],[-30021.48,216756.04],[-30019.49913662527,216756.51641017874],[-30016.507356293132,216757.23595228393],[-30015.573922444604,216757.4604490323],[-30013.58,216757.94],[-30003.34521672179,216758.92730236336],[-30000,216759.25],[-29989.7,216760.24],[-29979.25,216761.28],[-29972,216761.56],[-29968.75,216761.9],[-29946.91,216764.47],[-29927.93,216770.63],[-29900.35,216800.84],[-29878.53,216830.98],[-29835.64,216882.88],[-29797.73041881423,216913.85599982875],[-29793.187386121586,216917.56812155386],[-29785.12,216924.16],[-29758.78,216942.59],[-29696.47,216976.26],[-29655.38,216987.63],[-29635.49,216998.29],[-29633.07,217000],[-29627.99,217003.59],[-29612.81,217008.2],[-29604.17,217012.46],[-29594.09,217016.95],[-29583.71,217025.4],[-29572.66,217034.61],[-29553.32,217056.47],[-29550.45,217059.23],[-29535.11,217072.77],[-29515.43,217089.49],[-29494.26,217107.58],[-29485.28,217114.29],[-29480.399523776345,217117.4725626467],[-29473.38,217122.05],[-29471.959666700073,217122.84029319818],[-29469.90809720577,217123.98181499244],[-29454.513936111256,217132.54734028532],[-29424.19,217149.42],[-29423.62375765895,217150.18001348438],[-29414.23520642691,217162.7813769251],[-29400.52,217181.19],[-29397.52,217184.95],[-29375,217197.467],[-29309.83,217233.69],[-29289.03,217239.51],[-29280.18,217240.22],[-29244.55,217243.08],[-29223.855,217244.74],[-29166.5,217249.34],[-29159.52,217251.67],[-29125.12,217264.05],[-29074.59,217273.46],[-29026.38,217290.59],[-29022.344245823253,217294.27480724826],[-29011.488,217304.187],[-28973.26,217339.09],[-28941.200481509746,217363.0049055624],[-28936.81,217366.28],[-28927.09,217382.71],[-28921.27,217382.92],[-28920.79,217382.94],[-28915.68,217382.24],[-28905.12,217380.28],[-28887.96,217370.08],[-28862.46,217343.91],[-28862.4,217343.85],[-28833.01,217309.75],[-28817.9,217284.57],[-28799.11,217253.56],[-28762.3,217210.12],[-28760.67,217207.29],[-28756.96,217200.02],[-28750,217181.37],[-28743.673,217164.431],[-28742.48,217161.404],[-28742.05,217160.25],[-28729.105,217148.269],[-28726.987,217146.309],[-28726.755,217146.094],[-28721.35,217141.17],[-28708.66,217129.71],[-28690.39,217105.57],[-28687.82,217100.26],[-28670.55,217064.36],[-28639.91,217044.15],[-28609.49,217000],[-28599.1,216984.92],[-28601.53,216907.46],[-28577.61236028948,216881.81273686307],[-28577.29778561379,216881.47541346573],[-28560.391,216863.346],[-28553.4,216855.85],[-28543.262,216825.802],[-28514.28,216736.84],[-28508.5,216709.17],[-28502.15,216678.5],[-28501.723361198096,216676.5823708588],[-28500.25,216669.96],[-28497.49092437767,216657.54315530357],[-28489.262,216620.51],[-28487.95,216614.68],[-28469.113821407667,216577.14052590946],[-28465.27,216569.48],[-28455.09080536913,216550.13953020136],[-28452.37,216544.97],[-28430.92,216539.91],[-28425.63755843274,216503.56133742252],[-28425.12,216500],[-28424.405757232882,216495.0855566533],[-28422.906587952344,216484.77032094423],[-28418.811583554187,216456.5940928524],[-28416.53450035442,216440.92631587773],[-28413.14,216417.57],[-28412.370939138567,216383.41374970152],[-28412.12850014246,216372.6463222474],[-28411.567387271993,216347.72565262226],[-28411.372117675488,216339.05315666206],[-28411.13,216328.3],[-28413.548277168306,216307.90851999473],[-28415.863722590417,216288.38414138043],[-28417.409,216275.354],[-28436.83,216111.58],[-28423.52535540432,216086.1002597537],[-28381.47,216005.56],[-28380.11,216000],[-28332.786846596486,215806.76530412547],[-28328.01,215787.26],[-28265.091,215535.859],[-28232.99,215500],[-28160.13,215420.84],[-28160.12028157483,215420.84736298816],[-28149.32,215429.03],[-28143.726,215427.825],[-28141.78366514915,215427.40647382662],[-28125,215423.79],[-28079.924932567777,215414.0910915302],[-28077.88528126364,215413.65221495306],[-28005.045,215397.979],[-27999.524911631765,215396.79121099046],[-27995.333761678798,215395.88937726617],[-27840.44,215362.56],[-27705.11,215392.93],[-27500,215440.07],[-27239.21,215500],[-26970.46,215562.12],[-26992.58,215500],[-27024.27,215410.99],[-26875,215185.12],[-26752.66,215000],[-26526.46748412832,214657.73409233193],[-26440.928,214528.299],[-26422.16,214500],[-26363.75,214411.87],[-26250,214239.73],[-26205.09,214171.77],[-26250,214061.707],[-26275.179,214000],[-26333.25,213863],[-26538.08,213597.79],[-26598.57,213541.95],[-26658.647,213500],[-26685.07,213481.55],[-26778.466,213500],[-26875,213519.094],[-27224.69,213588.26],[-27276.38,213500],[-27315.01,213434.03],[-27393.97,213287.37],[-27374.44,213010.42],[-27369.86,213000],[-27328.12,212904.94],[-27292.19,212865.94],[-27288.55,212751.83],[-27248.72,212653.78],[-27237.5,212609.52],[-27462.03,212665.2],[-27500,212661.01],[-27809.7,212626.84],[-27875.990598600943,212550.5534864222],[-27887.67789343962,212537.10387222026],[-27919.92,212500],[-27940.604881234885,212476.19967046438],[-27945.254166298084,212470.85013447466],[-27949.2,212466.31],[-27967.41,212445.35],[-27974.41,212440.15],[-28032.604869819766,212396.84444284425],[-28041.089,212390.531],[-28049.284780513844,212384.43230094737],[-28056.37,212379.16],[-28057.348749028006,212378.43182099127],[-28072.35375349833,212367.26825508344],[-28125,212328.1],[-28138.416594598406,212318.11926627558],[-28153.875165394937,212306.61948682345],[-28175.024559834656,212290.88624894497],[-28190.629546206157,212279.2775495388],[-28198.784676140618,212273.21086996768],[-28209.97,212264.89],[-28262.935239419894,212225.4748589703],[-28267.86,212221.81],[-28278.071455203022,212214.35258786092],[-28290.607337550126,212205.19764967327],[-28305.291698118494,212194.47368070116],[-28323.44,212181.22],[-28336.237819119164,212171.26315],[-28354.872366291896,212158.26361063973],[-28365.79,212150.29],[-28371.402575776443,212149.6379093555],[-28401.215836569605,212146.17409002903],[-28561.17,212127.59],[-28600.36,212123.04],[-28608.19,212122.13],[-28628.14,212104.75],[-28645.99,212088.75],[-28650.655261128686,212084.57732469903],[-28664.76490997901,212071.9574559202],[-28688.226732700776,212050.97287103068],[-28701.585848142506,212039.02428990978],[-28722.46884403451,212020.3462440802],[-28729.98567127952,212013.6230878577],[-28735.68,212008.53],[-28738.041520578037,212006.43605295938],[-28740.994759429374,212003.81743264734],[-28745.3,212000],[-28750,211995.83],[-28763.146881707446,211983.59411145435],[-28764.72,211982.13],[-28768.73,211980.14],[-28837.018,211946.264],[-28934.25,211898.03],[-28940.42,211894.97],[-28956.09,211888.267],[-29027.17,211857.86],[-29131.59,211813.98],[-29192.569,211788.696],[-29212.130344049157,211780.58558506897],[-29230.86,211772.82],[-29269.51753821725,211763.47286105555],[-29280.82,211760.74],[-29285.78,211760.01],[-29289.55,211759.695],[-29338.14,211755.64],[-29359.66,211751.9],[-29375,211749.206],[-29385.74,211747.32],[-29387.75019390584,211746.97003878118],[-29395.39,211745.64],[-29397.99854228326,211744.95445330886],[-29405.93,211742.87],[-29407.418288798748,211742.44402138615],[-29437.155739244114,211733.93255645354],[-29442.44002466418,211732.420086172],[-29452.929283428195,211729.41784634304],[-29459.56,211727.52],[-29467.77412543556,211725.08498257838],[-29470.11068931843,211724.39232530084],[-29476.283799342298,211722.5623519736],[-29489.92,211718.52],[-29496.140956632647,211716.51323979592],[-29502.376135135113,211714.5018918919],[-29506.614583611823,211713.1346504478],[-29507.753821138278,211712.76715447154],[-29509.14,211712.32],[-29512.325785304532,211711.29401203044],[-29515.877653976288,211710.15012624455],[-29518.714929722424,211709.2363764141],[-29523.899985572032,211707.56651971795],[-29523.941060066456,211707.5532916021],[-29524.822364820902,211707.26946579805],[-29528.05,211706.23],[-29529.67,211705.95],[-29542.87,211698.35],[-29566.13,211720.81],[-29588.61,211756.93],[-29597.66,211772.77],[-29596.64,211827.48],[-29602.88,211846.39],[-29627.84,211894.21],[-29633.34,211966.78],[-29633.865,212000],[-29634.759,212056.534],[-29658.079,212216.566],[-29669.914,212251.948],[-29690.97,212283.001],[-29712.428,212331.39],[-29723.093,212346.013],[-29738.438,212394.72],[-29743.03,212446.849],[-29747.422,212500],[-29750.789,212540.745],[-29762.49,212577.815],[-29792.119,212621.206],[-29799.19010702753,212689.05040526413],[-29799.63,212693.271],[-29802.346,212753.812],[-29799.172,212847.523],[-29802.305,212929.076],[-29808.131,212981.339],[-29815.019,213000],[-29815.99,213002.63],[-29823.1608581132,213011.8832618744],[-29833.07,213024.67],[-29842.4,213036.99],[-29863.62,213054.88],[-29869.5,213060.82],[-29880.3,213072.16],[-29887.19,213081.17],[-29899.052329608894,213105.14191986623],[-29906.38,213119.95],[-29928.54,213167.07],[-29937.03,213191.11],[-29949.91,213228.39],[-29971.46,213254.75],[-29985.81,213265.73],[-30000,213276.614],[-30017.74,213290.22],[-30023.1245456455,213294.3127819411],[-30042.25,213308.85],[-30059.471,213321.973],[-30159.919,213377.959],[-30164.528,213380.528],[-30165.831,213381.543],[-30188.73,213399.391],[-30196.686,213405.591],[-30204.913,213412.003],[-30206.216,213413.019],[-30267.431,213461.961],[-30279.334,213500],[-30282.552,213510.285],[-30282.963,213514.154],[-30286.242,213545.011],[-30289.90193885786,213579.4555466625],[-30291.689,213596.274],[-30309.121,213684.223],[-30315.026,213698.44],[-30338.048910315,213739.5150021658],[-30350.217,213761.224],[-30385.17,213828.391],[-30421.024,213898.22],[-30434.695,213927.74],[-30435.834,213930.199],[-30461.304,213985.197],[-30472.154,213996.64],[-30475.339,214000],[-30484.813,214009.992],[-30497.497,214024.066],[-30507.478,214032.532],[-30527.667,214049.199],[-30564.898,214079.281],[-30589.903,214100.819],[-30599.839,214111.044],[-30612.195,214123.858],[-30625,214137.136],[-30641.227,214153.963],[-30649.679,214162.728],[-30659.198,214175.856],[-30661.617,214179.192],[-30662.014,214179.754],[-30671.793,214193.602],[-30700.089,214222.124],[-30743.072,214253.249],[-30751.536,214256.492],[-30777.061,214266.272],[-30784.775,214267.877],[-30795.163,214270.038],[-30813.753,214273.7],[-30821.457,214275.218],[-30836.118,214278.106],[-30838.823,214279.824],[-30841.76,214281.689],[-30846.813,214284.898],[-30871.705,214300.432],[-30880.112,214306.166],[-30900.282,214317.058],[-30925.259,214336.137],[-30930.562,214340.188],[-30951.549,214360.613],[-30954.782,214363.819],[-30984.546,214393.338],[-31012.919,214420.309],[-31031.545,214433.119],[-31049.884,214442.152],[-31063.295,214445.858],[-31065.62,214446.5],[-31091.21,214453.763],[-31159.358,214474.662],[-31180.458,214481.133],[-31217.173,214500],[-31250,214516.821],[-31257.14,214520.48],[-31287.396820223075,214537.72023523794],[-31300.91,214545.42],[-31317.54,214555.16],[-31329.26,214561.7],[-31358.01,214576.64],[-31394.030442339135,214595.29007755374],[-31394.32,214595.44],[-31416.03,214606.5],[-31485.72,214654.74],[-31525.064503760008,214682.2862490703],[-31532.04,214687.17],[-31589.25,214727.04],[-31652.85,214771.14],[-31662.97,214777.79],[-31671.181134116167,214782.66275494438],[-31692.51,214795.32],[-31724.96,214814.44],[-31739.41,214823.37],[-31749.72,214827.37],[-31758.08,214830.62],[-31777.23,214837.82],[-31783.16,214839.82],[-31787.501936749777,214841.82290979646],[-31809.087780286976,214851.78033202002],[-31842.97,214867.41],[-31849.74,214870.2],[-31864.93,214874.91],[-31873.67,214877.62],[-31875,214877.906],[-31877.21,214878.38],[-31889.08,214883.25],[-31905.56,214909.67],[-31926.454,214944.012],[-31944.96,214974.43],[-31962.63,215000],[-31982.468784892615,215028.69970558397],[-31988.168196285813,215036.94473822444],[-31988.87,215037.96],[-32046.345614347432,215089.46286067567],[-32083.56,215122.81],[-32093.828234736255,215132.22924663918],[-32124.44,215160.31],[-32148.641382,215185.2451426723],[-32153.228354862465,215190.34118478795],[-32211.361108944006,215250.9836038631],[-32221.729186668035,215261.7992847005],[-32223.58,215263.73],[-32242.98,215283.85],[-32296.011687443395,215333.95743642192],[-32316.79,215353.59],[-32334.59,215365.38],[-32394.48,215399.68],[-32441.03,215420.52],[-32477.445367249096,215439.99556602517],[-32490,215446.71],[-32491.599069379834,215447.63682061253],[-32497.40809168447,215451.0037299403],[-32500,215452.506],[-32504.521,215455.127],[-32549.54157436142,215476.45866561643],[-32553.50311769334,215478.33572558023],[-32559.793,215481.316],[-32563.072,215485.845],[-32563.663,215486.599],[-32574.169,215500],[-32582.604,215510.759],[-32591.62,215522.26],[-32612.33320143056,215548.68074828084],[-32614.216056653848,215551.08242646034],[-32614.922671084758,215551.98374932312],[-32617.88769253844,215555.76578590195],[-32618.66098424834,215556.75215904583],[-32622.01,215561.024],[-32678.868,215645.232],[-32679.571543529753,215645.85849614695],[-32722.891473834705,215684.4343173635],[-32736.03,215696.134],[-32783.675,215711.642],[-32885.475,215747.879],[-32964.855,215788.695],[-33125,215913.825],[-33134.169,215920.989],[-33153.844,215934.917],[-33228.423,215983.591],[-33253.722,216000],[-33282.26,216018.51],[-33295.51,216026.01],[-33350.421235024616,216045.31020126666],[-33411.05,216066.62],[-33433.02498671886,216090.01252984424],[-33446.86,216104.74],[-33459.220005923606,216115.94640537072],[-33459.61,216116.3],[-33473.02806772143,216131.69623271885],[-33475.410261578494,216134.42962263507],[-33478.06,216137.47],[-33484.08,216144.61],[-33492.51,216154.33],[-33505.88,216171.78],[-33538.071051316925,216188.5867372223],[-33538.152,216188.629],[-33541.09131871106,216190.33608079838],[-33559.976693575416,216201.30422136784],[-33561.742418622045,216202.3297091147],[-33562.38,216202.7],[-33630.74,216253.88],[-33657.28,216272.13],[-33668.85,216279.7],[-33678.588,216289.393],[-33686.25,216297.02],[-33718.77,216303.42],[-33750,216311.9],[-33797.1,216324.69]]]},"properties":{"AREA":18069976.57113,"PERIMETER":23909.55891,"POL_GEM_":94,"POL_GEM_ID":103,"PGEM_NAME":"Schruns","PGEM_ABK":"Schruns","PBEZ_NAME":"Bludenz","PBEZ_ABK":"Bludenz","PVBG_NR":"8","PBEZ_NR":"01","PGEM_NR":"22","PGEM_GESNR":80122,"GBEZ_NAME":"Montafon","GBEZ_ABK":"Montafon","KAT_FLAECH":18069977,"PGEM_GESN":"80122"}}
]}
答
正如@deceze所说,我的$ Coordinate变量是一个数组。
这是我的解决方案代码:
public function ConvertmapAction()
{
// Copy file content into a string var
$Json_File = file_get_contents("static/data/pol_gem.json");
// Convert the string to a json object
$Json = json_decode($Json_File);
//Declare features variable
$JSONFeatures = array();
//Loop through each feature
foreach ($Json->features as $Feature)
{
//Create array which contains coordinate data of feature
$CoordinateData = array();
//Loop through each coordinate pair of feature
foreach ($Feature->geometry->coordinates as $Coordinates)
{
//Create scaled coordinate pair array
$ScaledCoordinates = array();
//Loop through every coordinate of coordinate pair
foreach ($Coordinates as $Coordinate)
{
if(is_array($Coordinate))
{
$CoordinateArray = array();
foreach ($Coordinate as $CoordinatePoint)
{
$CoordinateArray[] = ($CoordinatePoint/1000.00);
}
$ScaledCoordinates[] = $CoordinateArray;
}
else
{
//Divide coordinate
$ScaledCoordinate = $Coordinate;
//add coordinate to coordinate pair array
$ScaledCoordinates[] = $ScaledCoordinate;
}
}
//Add coordinate pair array to coordinate array of feature
$CoordinateData[] = $ScaledCoordinates;
}
//Build feature JSON
$CurrentFeature = [
"type" => "Feature",
"geometry" => [
"type" => "Polygon",
"coordinates" => $CoordinateData,
"properties" => $Feature->properties
]
];
//Add current feature to features array
$JSONFeatures[] = $CurrentFeature;
}
//Create JSON File
$JSONMapData = [
"type" => "FeatureCollection",
"features" => $JSONFeatures
];
return new JsonResponse($JSONMapData);
}
答
也许你需要检查$Coordinate
是执行分割操作之前的Integer, Float or Double
之一,如下所示:
<?php
// Copy file content into a string var
$Json_File = file_get_contents("static/data/pol_gem.json");
// Convert the string to a json object
$Json = json_decode($Json_File);
//Declare features variable
$JSONFeatures = array();
//Loop through each feature
foreach ($Json->features as $Feature)
{
//Create array which contains coordinate data of feature
$CoordinateData = array();
//Loop through each coordinate pair of feature
foreach ($Feature->geometry->coordinates as $Coordinates)
{
//Create scaled coordinate pair array
$ScaledCoordinates = array();
//Loop through every coordinate of coordinate pair
foreach ($Coordinates as $Coordinate)
{
//Divide coordinate
// SET THE SCALED COORDINATE TO DEFAULT TO IT'S ORIGINAL VALUE
// SHOULD THING GO SOUR...
$ScaledCoordinate = floatval($Coordinate);
// CHECK THAT $Coordinate IS EITHER AN INTEGER, FLOAT OR DOUBLE...
if(is_numeric($Coordinate) || is_int($Coordinate) || is_float($Coordinate)){
// STILL CONVERT THE $Coordinate TO FLOAT BEFORE DIVISION
// AND SINCE IT IS NOW A FLOAT, YOU WOULDN'T NEED THE DECIMA. PART: ".00"
$ScaledCoordinate = (floatval($Coordinate)/1000);
}
//add coordinate to coordinate pair array
$ScaledCoordinates[] = $ScaledCoordinate;
}
//Add coordinate pair array to coordinate array of feature
$CoordinateData[] = $ScaledCoordinates;
}
//Build feature JSON
$CurrentFeature = [
"type" => "Feature",
"geometry" => [
"type" => "Polygon",
"coordinates" => $CoordinateData,
"properties" => $Feature->properties
]
];
//Add current feature to features array
$JSONFeatures[] = $CurrentFeature;
}
//Create JSON File
$JSONMapData = [
"type" => "FeatureCollection",
"features" => $JSONFeatures
];
// DO NOT FORGET TO ENCODE THE JSON DATA BECAUSE $JSONMapData IS AN ARRAY, STILL
$JSONMapResponse = json_encode($JSONMapData);
// SEND BACK THE JSON DATA TO THE "REQUESTING SCRIPT"
die($JSONMapResponse);
+0
如果我使用这个解决方案,每个坐标都是“1”。 $ ScaledCoordinate = floatval($ Coordinate);将其设置为“1” – Orlando
什么是你要分开两个值?什么是'$坐标'? – deceze
它是一个浮点数 – Orlando
你确定'$ Coordinate'是浮点类型,而不是一个字符串,或者甚至还埋藏在另一个更深的数组中? – WillardSolutions