Tengo un problema que no puedo superar .... Tengo un mapa en el que hay varias líneas que representan algunas carreteras de la comuna Hago clic en el mapa y me da la posición (latitud, longitud) en el mapa:
var point = map.getCoordinateFromPixel(event.pixel)
var lonLat = ol.proj.toLonLat(point);
console.log(lonLat);
Luego transformo esta coordenada en x, y para poder trabajar con ella después en PHP:
var point = ol.proj.transform(lonLat, 'EPSG:4326','EPSG:31700');
console.log(point);
Envío con AJAX a PHP y allí ejecuto la siguiente consulta:
SELECT ST_Distance(
'SRID=31700;ST_MakePoint(POINT(657985.7511906754, 539226.2498239303))'::geometry,
'SRID=31700;LINESTRING(655005.644 538263.882,655022.827 538274.417,655041.77 538285.655,655053.567 538293.496,655076.022 538308.016,655099.239 538323.029,655130.453 538342.21,655159.135 538361.382,655164.652 538367.248,655169.448 538374.679,655177.824 538390.878,655182.348 538400.376,655187.471 538410.97,655200.832 538436.01,655214.941 538460.905,655225.973 538479.774,655236.708 538497.544,655245.755 538511.807,655252.275 538522.334,655263.903 538542.097,655289.626 538586.425,655308.932 538619.565,655325.531 538647.831,655345.282 538681.499,655356.946 538701.269,655368.285 538720.025,655378.715 538737.489,655388.661 538753.338,655400.411 538765.869,655414.762 538775.136,655440.242 538787.448,655467.745 538799.498,655485.767 538807.159,655503.73 538813.411,655523.562 538817.523,655546.647 538819.018,655571.107 538818.718,655596.962 538817.575,655623.66 538816.803,655650.635 538816.944,655678.038 538817.854,655705.798 538818.905,655733.618 538820.266,655761.429 538821.7,655789.429 538823.675,655817.44 538826.142,655858.986 538830.156,655886.768 538833.429,655914.6 538837.063,655942.587 538841.285,655970.602 538845.928,655998.497 538850.768,656025.982 538855.867,656052.535 538860.748,656091.606 538867.653,656131.437 538876.496,656158.378 538884.064,656199.326 538897.344,656227.351 538907.131,656255.793 538918.168,656299.158 538935.983,656343.111 538954.487,656372.162 538966.741,656400.232 538978.413,656424.809 538988.279,656446.235 538995.848,656482.221 539005.447,656529.602 539014.327,656562.394 539020.024,656595.198 539025.641,656628.124 539031.261,656661.3 539037.235,656694.729 539043.518,656728.408 539049.173,656761.664 539054.799,656791.384 539060.052,656818.837 539064.694,656841.709 539068.461,656872.713 539074.021,656893.432 539077.731,656924.887 539083.294,656946 539086.933,656967.081 539090.77,656987.767 539094.436,657007.356 539097.868,657025.601 539101,657043.433 539104.052,657060.611 539107.298,657077.464 539110.251,657094.439 539113.274,657111.582 539116.259,657137.707 539121.001,657164.532 539125.962,657182.191 539129.051,657207.418 539133.498,657223.206 539136.998,657237.38 539139.845,657250.534 539142.585,657262.945 539144.989,657274.61 539147.17,657284.853 539148.79,657295.34 539149.37,657306.006 539149,657316.423 539146.695,657335.145 539139.883,657356.79 539131.82,657371.207 539126.374,657392.552 539118.555,657407.373 539114.878,657422.48 539112.776,657438.637 539112.344,657462.828 539114.814,657479.714 539118.998,657506.025 539126.619,657532.646 539134.222,657559.422 539142.092,657577.394 539147.428,657595.55 539152.577,657613.866 539157.802,657631.083 539162.941,657646.797 539167.508,657661.692 539171.899,657675.877 539175.678,657688.569 539177.568,657699.585 539178.358,657723.526 539178.707,657754.242 539178.872,657787.597 539179.001,657822.97 539179.076,657859.239 539179.314,657893.513 539179.401,657923.13 539179.412,657946.83 539179.397,657966.668 539179.412,657995.253 539179.689,658022.976 539179.692,658051.051 539179.87,658079.167 539179.987,658106.574 539180.021,658124.876 539180.205,658152.53 539180.326,658170.79 539180.47,658197.076 539180.626,658213.103 539180.595,658226.513 539180.622,658237.88 539180.736,658247.974 539179.952,658257.776 539177.062,658267.157 539172.168,658275.728 539164.936,658282.277 539156.307,658286.74 539146.6,658289.917 539134.879,658292.164 539121.524,658296.495 539094.065,658298.709 539080.229,658301.131 539066.339,658303.495 539052.853,658305.656 539039.715,658307.979 539026.256,658310.783 539012.525,658315.642 538999.106,658322.46 538986.302,658330.958 538974.18,658340.804 538962.754,658352.158 538952.665,658370.735 538940.486,658391.137 538930.28,658406.236 538925.812,658422.715 538923.549,658448.2 538922.163,658473.699 538920.769,658490.199 538919.907,658505.153 538918.872,658519.044 538917.304,658541.298 538913.59,658574.828 538903.829,658600.922 538894.734,658628.719 538883.695,658656.704 538871.617,658671.024 538863.332,658681.604 538856.002,658703.533 538836.281,658716.642 538821.16,658728.495 538804.99,658739.291 538787.326,658749.495 538769.207,658759.232 538751.798,658769.136 538734.385,658778.711 538717.289,658788.215 538700.212,658798.009 538683.209,658807.917 538666.185,658819.563 538650.45,658828.584 538640.188,658840.142 538630.463,658861.228 538613.646,658878.854 538599.695,658891.753 538589.556,658936.475 538553.924,658978.597 538524.621,658997.996 538512.766,659017.407 538501.011,659036.539 538490.081,659056.347 538480.672,659070.275 538475.384,659083.815 538470.359,659096.332 538464.129,659108.252 538457.032,659120.491 538450.139,659133.415 538445.387,659140.875 538443.095,659147.321 538443.117,659155.938 538442.999,659162.686 538444.37,659178.937 538448.493,659194.708 538453.629,659210.037 538458.638,659224.844 538463.431,659239.461 538467.613,659254.069 538471.333,659268.447 538474.842,659282.347 538477.806,659295.576 538479.968,659307.88 538481.911,659320.857 538483.421,659358.17193439 538486.32543723)'::geometry
)
Para saber la distancia del punto que obtuve del clic opuesto al liestring ... Y tengo el siguiente error:
ERROR: parse error - invalid geometry
LINE 2: 'SRID=31700;ST_MakePoint(POINT(657985.7511906754, ...
^
HINT: "SRID=31700;ST" <-- parse error at position 13 within geometry
Otras opiniones sugerencias ¿cómo podría hacer?