Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting from geoJson to wkt and back #193

Open
D063520 opened this issue Sep 14, 2020 · 2 comments
Open

Converting from geoJson to wkt and back #193

D063520 opened this issue Sep 14, 2020 · 2 comments

Comments

@D063520
Copy link

D063520 commented Sep 14, 2020

Hello,

I'm not sure if this is a bug or me not able to use the library ....

This is my code:

            System.out.println(geoJsonString);
            Shape shape = geojsonReader.read(geoJsonString);
            WKTWriter wktWriter = new WKTWriter();
            String wkt = wktWriter.toString(shape);
            System.out.println("CONVERT TO WKT "+wkt);

            WKTReader wktReader = new WKTReader(JtsSpatialContext.GEO,
                    new SpatialContextFactory());
            Shape shape2 = wktReader.read(wkt);
            GeoJSONWriter geoJSONWriter = new GeoJSONWriter(JtsSpatialContext.GEO, new SpatialContextFactory());
            String geoJson = geoJSONWriter.toString(shape2);
            System.out.println("CONVERT TO GEOJSON "+geoJson);

This is the console output:

{"type": "Polygon", "coordinates": [[[9.96781, 47.54624], [9.97038, 47.54455], [9.96555, 47.53738], [9.96763, 47.52661], [9.96503, 47.523], [9.97235, 47.51565], [9.98497, 47.51023], [9.99445, 47.50318], [9.98849, 47.49755], [9.99953, 47.48302], [10.01032, 47.48229], [10.03692, 47.48871], [10.04361, 47.48777], [10.05372, 47.47501], [10.05285, 47.4681], [10.0569, 47.46557], [10.06633, 47.46224], [10.07201, 47.45622], [10.07982, 47.45585], [10.08945, 47.45947], [10.09388, 47.45225], [10.09395, 47.44201], [10.10389, 47.4305], [10.10459, 47.42824], [10.09746, 47.42315], [10.09441, 47.4176], [10.08596, 47.41494], [10.07498, 47.41445], [10.07135, 47.41114], [10.07148, 47.40756], [10.08516, 47.39951], [10.08289, 47.39373], [10.08952, 47.37805], [10.09077, 47.37519], [10.09764, 47.35986], [10.09985, 47.35476], [10.11932, 47.375], [10.14128, 47.36722], [10.16639, 47.36937], [10.16909, 47.37213], [10.16943, 47.3848], [10.18027, 47.38701], [10.18234, 47.39178], [10.1947, 47.38878], [10.20088, 47.38331], [10.21206, 47.38111], [10.22698, 47.38814], [10.23481, 47.38282], [10.23268, 47.37883], [10.23601, 47.37245], [10.21751, 47.35463], [10.21657, 47.34947], [10.20511, 47.33776], [10.20699, 47.33224], [10.20046, 47.32657], [10.21025, 47.31902], [10.21372, 47.31218], [10.20904, 47.30524], [10.19906, 47.298], [10.18913, 47.2942], [10.17927, 47.29523], [10.17209, 47.27908], [10.17372, 47.27148], [10.17835, 47.27011], [10.17627, 47.26326], [10.22219, 47.25223], [10.22118, 47.24884], [10.21061, 47.24677], [10.19828, 47.23564], [10.20827, 47.23082], [10.21164, 47.22246], [10.21265, 47.20482], [10.19679, 47.1924], [10.20126, 47.17988], [10.21099, 47.17132], [10.20811, 47.161], [10.21279, 47.15728], [10.22076, 47.15044], [10.21521, 47.14498], [10.20446, 47.14196], [10.20412, 47.13751], [10.20952, 47.13307], [10.18818, 47.12988], [10.18546, 47.12007], [10.1724, 47.11959], [10.15808, 47.114], [10.15307, 47.10426], [10.13479, 47.083], [10.13356, 47.07762], [10.13502, 47.06477], [10.15096, 47.0606], [10.15623, 47.04875], [10.15223, 47.04082], [10.1353, 47.02929], [10.12547, 47.02403], [10.12454, 47.02049], [10.13309, 47.01279], [10.15518, 47.00363], [10.15851, 46.99917], [10.15475, 46.99152], [10.16037, 46.98352], [10.1441, 46.98219], [10.14202, 46.97556], [10.13643, 46.96966], [10.13477, 46.95569], [10.12623, 46.94265], [10.12135, 46.93867], [10.11333, 46.93663], [10.09805, 46.92592], [10.09931, 46.91874], [10.10824, 46.90871], [10.10968, 46.8954], [10.11706, 46.8861], [10.12907, 46.87829], [10.14114, 46.87411], [10.14056, 46.86222], [10.14497, 46.85101], [10.1391, 46.84756], [10.12216, 46.84798], [10.11816, 46.84437], [10.10517, 46.84091], [10.10203, 46.84496], [10.10054, 46.84624], [10.09801, 46.84753], [10.0968, 46.84879], [10.09258, 46.85209], [10.09188, 46.85767], [10.08748, 46.86065], [10.05391, 46.86249], [10.05116, 46.86533], [10.05166, 46.87595], [10.03312, 46.88802], [10.02619, 46.89542], [10.01779, 46.90084], [10.0047, 46.89921], [9.98964, 46.90303], [9.98268, 46.90688], [9.97789, 46.91589], [9.96669, 46.91245], [9.95792, 46.91561], [9.94543, 46.91265], [9.93845, 46.91326], [9.92193, 46.91881], [9.91303, 46.92538], [9.90551, 46.92571], [9.89462, 46.93141], [9.87615, 46.93464], [9.87954, 46.93971], [9.87683, 46.9417], [9.87559, 46.94954], [9.8783, 46.95597], [9.87201, 46.96311], [9.87558, 46.97283], [9.88335, 46.98004], [9.88405, 46.98427], [9.89167, 46.98948], [9.8888, 47.00073], [9.87297, 47.00734], [9.87187, 47.01262], [9.87968, 47.01788], [9.87626, 47.0209], [9.86043, 47.02266], [9.85289, 47.0168], [9.83663, 47.0132], [9.83073, 47.01433], [9.82289, 47.01995], [9.81068, 47.02261], [9.80141, 47.02879], [9.79787, 47.02984], [9.79315, 47.03125], [9.78334, 47.03846], [9.74928, 47.03711], [9.74204, 47.04211], [9.71814, 47.04397], [9.70729, 47.04841], [9.70816, 47.05283], [9.69692, 47.05283], [9.68642, 47.05635], [9.68101, 47.06158], [9.67745, 47.06141], [9.6588, 47.05844], [9.64677, 47.05924], [9.63656, 47.05171], [9.61911, 47.05325], [9.60708, 47.06077], [9.61255, 47.06798], [9.61152, 47.07941], [9.61833, 47.07863], [9.62398, 47.08226], [9.63226, 47.08356], [9.63508, 47.09034], [9.63421, 47.10074], [9.62083, 47.11055], [9.624, 47.1134], [9.6245, 47.11479], [9.62474, 47.118], [9.63356, 47.12717], [9.62519, 47.13311], [9.62498, 47.14572], [9.62058, 47.15165], [9.61435, 47.14805], [9.6066, 47.14875], [9.59908, 47.1606], [9.59093, 47.16468], [9.57946, 47.17113], [9.57508, 47.16981], [9.57276, 47.16954], [9.56632, 47.16983], [9.56466, 47.17031], [9.56663, 47.1727], [9.57302, 47.17649], [9.57316, 47.18784], [9.57353, 47.1911], [9.57929, 47.1951], [9.58481, 47.20457], [9.56961, 47.21886], [9.55985, 47.22327], [9.55418, 47.2237], [9.55758, 47.23148], [9.56684, 47.24187], [9.5557, 47.25269], [9.54164, 47.26006], [9.53892, 47.26507], [9.53075, 47.27058], [9.54332, 47.27834], [9.54615, 47.28], [9.55147, 47.28704], [9.55401, 47.29392], [9.55456, 47.29541], [9.55509, 47.29684], [9.55658, 47.29846], [9.55923, 47.30019], [9.56573, 47.30418], [9.57061, 47.30632], [9.58156, 47.31112], [9.5836, 47.31266], [9.58829, 47.31754], [9.58928, 47.31915], [9.59236, 47.32715], [9.59481, 47.3335], [9.59635, 47.33752], [9.59942, 47.345], [9.60073, 47.3469], [9.60508, 47.35129], [9.61324, 47.35752], [9.61967, 47.36243], [9.62448, 47.36614], [9.64677, 47.3673], [9.64955, 47.36745], [9.66109, 47.37061], [9.66983, 47.37719], [9.67332, 47.38225], [9.67358, 47.39129], [9.67247, 47.39262], [9.67063, 47.39368], [9.66869, 47.39432], [9.66246, 47.39639], [9.66011, 47.39755], [9.65735, 47.40016], [9.65439, 47.4044], [9.65164, 47.40463], [9.6519, 47.40857], [9.6509, 47.41643], [9.6503, 47.42111], [9.64903, 47.42472], [9.64677, 47.4289], [9.64512, 47.43206], [9.64434, 47.43516], [9.6447, 47.43675], [9.64677, 47.43974], [9.6508, 47.44274], [9.658, 47.44779], [9.65906, 47.44912], [9.65945, 47.45138], [9.6517, 47.45466], [9.64677, 47.45521], [9.62243, 47.45792], [9.61177, 47.46877], [9.60725, 47.47033], [9.60298, 47.46288], [9.59482, 47.46362], [9.58308, 47.48152], [9.57639, 47.48661], [9.5658, 47.49237], [9.56414, 47.4936], [9.56282, 47.49501], [9.5618, 47.49679], [9.56131, 47.4987], [9.56183, 47.50456], [9.55872, 47.54189], [9.56516, 47.54091], [9.60592, 47.5347], [9.61684, 47.53304], [9.63057, 47.53094], [9.64211, 47.52919], [9.64677, 47.52848], [9.6575, 47.52684], [9.66388, 47.52587], [9.68036, 47.52336], [9.70197, 47.52793], [9.72805, 47.53345], [9.72988, 47.53364], [9.73217, 47.53373], [9.73619, 47.5358], [9.73555, 47.54611], [9.74066, 47.55354], [9.74605, 47.55595], [9.74449, 47.55893], [9.75072, 47.56693], [9.74937, 47.57069], [9.75568, 47.57216], [9.75625, 47.57831], [9.76228, 47.58496], [9.77718, 47.59449], [9.79787, 47.59518], [9.80275, 47.59534], [9.81348, 47.58883], [9.82031, 47.58764], [9.82375, 47.58718], [9.82668, 47.5781], [9.82144, 47.56968], [9.82554, 47.56031], [9.8155, 47.5493], [9.82977, 47.54453], [9.85002, 47.54136], [9.8584, 47.53447], [9.87449, 47.52854], [9.87778, 47.53945], [9.87611, 47.54379], [9.87877, 47.54654], [9.88143, 47.54782], [9.88942, 47.54437], [9.90099, 47.54429], [9.90844, 47.5387], [9.91473, 47.53208], [9.92258, 47.53], [9.94115, 47.53758], [9.96112, 47.53522], [9.96005, 47.54264], [9.96781, 47.54624]]]}
CONVERT TO WKT POLYGON ((9.96781 47.54624, 9.97038 47.54455, 9.96555 47.53738, 9.96763 47.52661, 9.96503 47.523, 9.97235 47.51565, 9.98497 47.51023, 9.99445 47.50318, 9.98849 47.49755, 9.99953 47.48302, 10.01032 47.48229, 10.03692 47.48871, 10.04361 47.48777, 10.05372 47.47501, 10.05285 47.4681, 10.0569 47.46557, 10.06633 47.46224, 10.07201 47.45622, 10.07982 47.45585, 10.08945 47.45947, 10.09388 47.45225, 10.09395 47.44201, 10.10389 47.4305, 10.10459 47.42824, 10.09746 47.42315, 10.09441 47.4176, 10.08596 47.41494, 10.07498 47.41445, 10.07135 47.41114, 10.07148 47.40756, 10.08516 47.39951, 10.08289 47.39373, 10.08952 47.37805, 10.09077 47.37519, 10.09764 47.35986, 10.09985 47.35476, 10.11932 47.375, 10.14128 47.36722, 10.16639 47.36937, 10.16909 47.37213, 10.16943 47.3848, 10.18027 47.38701, 10.18234 47.39178, 10.1947 47.38878, 10.20088 47.38331, 10.21206 47.38111, 10.22698 47.38814, 10.23481 47.38282, 10.23268 47.37883, 10.23601 47.37245, 10.21751 47.35463, 10.21657 47.34947, 10.20511 47.33776, 10.20699 47.33224, 10.20046 47.32657, 10.21025 47.31902, 10.21372 47.31218, 10.20904 47.30524, 10.19906 47.298, 10.18913 47.2942, 10.17927 47.29523, 10.17209 47.27908, 10.17372 47.27148, 10.17835 47.27011, 10.17627 47.26326, 10.22219 47.25223, 10.22118 47.24884, 10.21061 47.24677, 10.19828 47.23564, 10.20827 47.23082, 10.21164 47.22246, 10.21265 47.20482, 10.19679 47.1924, 10.20126 47.17988, 10.21099 47.17132, 10.20811 47.161, 10.21279 47.15728, 10.22076 47.15044, 10.21521 47.14498, 10.20446 47.14196, 10.20412 47.13751, 10.20952 47.13307, 10.18818 47.12988, 10.18546 47.12007, 10.1724 47.11959, 10.15808 47.114, 10.15307 47.10426, 10.13479 47.083, 10.13356 47.07762, 10.13502 47.06477, 10.15096 47.0606, 10.15623 47.04875, 10.15223 47.04082, 10.1353 47.02929, 10.12547 47.02403, 10.12454 47.02049, 10.13309 47.01279, 10.15518 47.00363, 10.15851 46.99917, 10.15475 46.99152, 10.16037 46.98352, 10.1441 46.98219, 10.14202 46.97556, 10.13643 46.96966, 10.13477 46.95569, 10.12623 46.94265, 10.12135 46.93867, 10.11333 46.93663, 10.09805 46.92592, 10.09931 46.91874, 10.10824 46.90871, 10.10968 46.8954, 10.11706 46.8861, 10.12907 46.87829, 10.14114 46.87411, 10.14056 46.86222, 10.14497 46.85101, 10.1391 46.84756, 10.12216 46.84798, 10.11816 46.84437, 10.10517 46.84091, 10.10203 46.84496, 10.10054 46.84624, 10.09801 46.84753, 10.0968 46.84879, 10.09258 46.85209, 10.09188 46.85767, 10.08748 46.86065, 10.05391 46.86249, 10.05116 46.86533, 10.05166 46.87595, 10.03312 46.88802, 10.02619 46.89542, 10.01779 46.90084, 10.0047 46.89921, 9.98964 46.90303, 9.98268 46.90688, 9.97789 46.91589, 9.96669 46.91245, 9.95792 46.91561, 9.94543 46.91265, 9.93845 46.91326, 9.92193 46.91881, 9.91303 46.92538, 9.90551 46.92571, 9.89462 46.93141, 9.87615 46.93464, 9.87954 46.93971, 9.87683 46.9417, 9.87559 46.94954, 9.8783 46.95597, 9.87201 46.96311, 9.87558 46.97283, 9.88335 46.98004, 9.88405 46.98427, 9.89167 46.98948, 9.8888 47.00073, 9.87297 47.00734, 9.87187 47.01262, 9.87968 47.01788, 9.87626 47.0209, 9.86043 47.02266, 9.85289 47.0168, 9.83663 47.0132, 9.83073 47.01433, 9.82289 47.01995, 9.81068 47.02261, 9.80141 47.02879, 9.79787 47.02984, 9.79315 47.03125, 9.78334 47.03846, 9.74928 47.03711, 9.74204 47.04211, 9.71814 47.04397, 9.70729 47.04841, 9.70816 47.05283, 9.69692 47.05283, 9.68642 47.05635, 9.68101 47.06158, 9.67745 47.06141, 9.6588 47.05844, 9.64677 47.05924, 9.63656 47.05171, 9.61911 47.05325, 9.60708 47.06077, 9.61255 47.06798, 9.61152 47.07941, 9.61833 47.07863, 9.62398 47.08226, 9.63226 47.08356, 9.63508 47.09034, 9.63421 47.10074, 9.62083 47.11055, 9.624 47.1134, 9.6245 47.11479, 9.62474 47.118, 9.63356 47.12717, 9.62519 47.13311, 9.62498 47.14572, 9.62058 47.15165, 9.61435 47.14805, 9.6066 47.14875, 9.59908 47.1606, 9.59093 47.16468, 9.57946 47.17113, 9.57508 47.16981, 9.57276 47.16954, 9.56632 47.16983, 9.56466 47.17031, 9.56663 47.1727, 9.57302 47.17649, 9.57316 47.18784, 9.57353 47.1911, 9.57929 47.1951, 9.58481 47.20457, 9.56961 47.21886, 9.55985 47.22327, 9.55418 47.2237, 9.55758 47.23148, 9.56684 47.24187, 9.5557 47.25269, 9.54164 47.26006, 9.53892 47.26507, 9.53075 47.27058, 9.54332 47.27834, 9.54615 47.28, 9.55147 47.28704, 9.55401 47.29392, 9.55456 47.29541, 9.55509 47.29684, 9.55658 47.29846, 9.55923 47.30019, 9.56573 47.30418, 9.57061 47.30632, 9.58156 47.31112, 9.5836 47.31266, 9.58829 47.31754, 9.58928 47.31915, 9.59236 47.32715, 9.59481 47.3335, 9.59635 47.33752, 9.59942 47.345, 9.60073 47.3469, 9.60508 47.35129, 9.61324 47.35752, 9.61967 47.36243, 9.62448 47.36614, 9.64677 47.3673, 9.64955 47.36745, 9.66109 47.37061, 9.66983 47.37719, 9.67332 47.38225, 9.67358 47.39129, 9.67247 47.39262, 9.67063 47.39368, 9.66869 47.39432, 9.66246 47.39639, 9.66011 47.39755, 9.65735 47.40016, 9.65439 47.4044, 9.65164 47.40463, 9.6519 47.40857, 9.6509 47.41643, 9.6503 47.42111, 9.64903 47.42472, 9.64677 47.4289, 9.64512 47.43206, 9.64434 47.43516, 9.6447 47.43675, 9.64677 47.43974, 9.6508 47.44274, 9.658 47.44779, 9.65906 47.44912, 9.65945 47.45138, 9.6517 47.45466, 9.64677 47.45521, 9.62243 47.45792, 9.61177 47.46877, 9.60725 47.47033, 9.60298 47.46288, 9.59482 47.46362, 9.58308 47.48152, 9.57639 47.48661, 9.5658 47.49237, 9.56414 47.4936, 9.56282 47.49501, 9.5618 47.49679, 9.56131 47.4987, 9.56183 47.50456, 9.55872 47.54189, 9.56516 47.54091, 9.60592 47.5347, 9.61684 47.53304, 9.63057 47.53094, 9.64211 47.52919, 9.64677 47.52848, 9.6575 47.52684, 9.66388 47.52587, 9.68036 47.52336, 9.70197 47.52793, 9.72805 47.53345, 9.72988 47.53364, 9.73217 47.53373, 9.73619 47.5358, 9.73555 47.54611, 9.74066 47.55354, 9.74605 47.55595, 9.74449 47.55893, 9.75072 47.56693, 9.74937 47.57069, 9.75568 47.57216, 9.75625 47.57831, 9.76228 47.58496, 9.77718 47.59449, 9.79787 47.59518, 9.80275 47.59534, 9.81348 47.58883, 9.82031 47.58764, 9.82375 47.58718, 9.82668 47.5781, 9.82144 47.56968, 9.82554 47.56031, 9.8155 47.5493, 9.82977 47.54453, 9.85002 47.54136, 9.8584 47.53447, 9.87449 47.52854, 9.87778 47.53945, 9.87611 47.54379, 9.87877 47.54654, 9.88143 47.54782, 9.88942 47.54437, 9.90099 47.54429, 9.90844 47.5387, 9.91473 47.53208, 9.92258 47.53, 9.94115 47.53758, 9.96112 47.53522, 9.96005 47.54264, 9.96781 47.54624))
CONVERT TO GEOJSON {"type":"Unknown","wkt":"POLYGON ((9.96781 47.54624, 9.97038 47.54455, 9.96555 47.53738, 9.96763 47.52661, 9.96503 47.523, 9.97235 47.51565, 9.98497 47.51023, 9.99445 47.50318, 9.98849 47.49755, 9.99953 47.48302, 10.01032 47.48229, 10.03692 47.48871, 10.04361 47.48777, 10.05372 47.47501, 10.05285 47.4681, 10.0569 47.46557, 10.06633 47.46224, 10.07201 47.45622, 10.07982 47.45585, 10.08945 47.45947, 10.09388 47.45225, 10.09395 47.44201, 10.10389 47.4305, 10.10459 47.42824, 10.09746 47.42315, 10.09441 47.4176, 10.08596 47.41494, 10.07498 47.41445, 10.07135 47.41114, 10.07148 47.40756, 10.08516 47.39951, 10.08289 47.39373, 10.08952 47.37805, 10.09077 47.37519, 10.09764 47.35986, 10.09985 47.35476, 10.11932 47.375, 10.14128 47.36722, 10.16639 47.36937, 10.16909 47.37213, 10.16943 47.3848, 10.18027 47.38701, 10.18234 47.39178, 10.1947 47.38878, 10.20088 47.38331, 10.21206 47.38111, 10.22698 47.38814, 10.23481 47.38282, 10.23268 47.37883, 10.23601 47.37245, 10.21751 47.35463, 10.21657 47.34947, 10.20511 47.33776, 10.20699 47.33224, 10.20046 47.32657, 10.21025 47.31902, 10.21372 47.31218, 10.20904 47.30524, 10.19906 47.298, 10.18913 47.2942, 10.17927 47.29523, 10.17209 47.27908, 10.17372 47.27148, 10.17835 47.27011, 10.17627 47.26326, 10.22219 47.25223, 10.22118 47.24884, 10.21061 47.24677, 10.19828 47.23564, 10.20827 47.23082, 10.21164 47.22246, 10.21265 47.20482, 10.19679 47.1924, 10.20126 47.17988, 10.21099 47.17132, 10.20811 47.161, 10.21279 47.15728, 10.22076 47.15044, 10.21521 47.14498, 10.20446 47.14196, 10.20412 47.13751, 10.20952 47.13307, 10.18818 47.12988, 10.18546 47.12007, 10.1724 47.11959, 10.15808 47.114, 10.15307 47.10426, 10.13479 47.083, 10.13356 47.07762, 10.13502 47.06477, 10.15096 47.0606, 10.15623 47.04875, 10.15223 47.04082, 10.1353 47.02929, 10.12547 47.02403, 10.12454 47.02049, 10.13309 47.01279, 10.15518 47.00363, 10.15851 46.99917, 10.15475 46.99152, 10.16037 46.98352, 10.1441 46.98219, 10.14202 46.97556, 10.13643 46.96966, 10.13477 46.95569, 10.12623 46.94265, 10.12135 46.93867, 10.11333 46.93663, 10.09805 46.92592, 10.09931 46.91874, 10.10824 46.90871, 10.10968 46.8954, 10.11706 46.8861, 10.12907 46.87829, 10.14114 46.87411, 10.14056 46.86222, 10.14497 46.85101, 10.1391 46.84756, 10.12216 46.84798, 10.11816 46.84437, 10.10517 46.84091, 10.10203 46.84496, 10.10054 46.84624, 10.09801 46.84753, 10.0968 46.84879, 10.09258 46.85209, 10.09188 46.85767, 10.08748 46.86065, 10.05391 46.86249, 10.05116 46.86533, 10.05166 46.87595, 10.03312 46.88802, 10.02619 46.89542, 10.01779 46.90084, 10.0047 46.89921, 9.98964 46.90303, 9.98268 46.90688, 9.97789 46.91589, 9.96669 46.91245, 9.95792 46.91561, 9.94543 46.91265, 9.93845 46.91326, 9.92193 46.91881, 9.91303 46.92538, 9.90551 46.92571, 9.89462 46.93141, 9.87615 46.93464, 9.87954 46.93971, 9.87683 46.9417, 9.87559 46.94954, 9.8783 46.95597, 9.87201 46.96311, 9.87558 46.97283, 9.88335 46.98004, 9.88405 46.98427, 9.89167 46.98948, 9.8888 47.00073, 9.87297 47.00734, 9.87187 47.01262, 9.87968 47.01788, 9.87626 47.0209, 9.86043 47.02266, 9.85289 47.0168, 9.83663 47.0132, 9.83073 47.01433, 9.82289 47.01995, 9.81068 47.02261, 9.80141 47.02879, 9.79787 47.02984, 9.79315 47.03125, 9.78334 47.03846, 9.74928 47.03711, 9.74204 47.04211, 9.71814 47.04397, 9.70729 47.04841, 9.70816 47.05283, 9.69692 47.05283, 9.68642 47.05635, 9.68101 47.06158, 9.67745 47.06141, 9.6588 47.05844, 9.64677 47.05924, 9.63656 47.05171, 9.61911 47.05325, 9.60708 47.06077, 9.61255 47.06798, 9.61152 47.07941, 9.61833 47.07863, 9.62398 47.08226, 9.63226 47.08356, 9.63508 47.09034, 9.63421 47.10074, 9.62083 47.11055, 9.624 47.1134, 9.6245 47.11479, 9.62474 47.118, 9.63356 47.12717, 9.62519 47.13311, 9.62498 47.14572, 9.62058 47.15165, 9.61435 47.14805, 9.6066 47.14875, 9.59908 47.1606, 9.59093 47.16468, 9.57946 47.17113, 9.57508 47.16981, 9.57276 47.16954, 9.56632 47.16983, 9.56466 47.17031, 9.56663 47.1727, 9.57302 47.17649, 9.57316 47.18784, 9.57353 47.1911, 9.57929 47.1951, 9.58481 47.20457, 9.56961 47.21886, 9.55985 47.22327, 9.55418 47.2237, 9.55758 47.23148, 9.56684 47.24187, 9.5557 47.25269, 9.54164 47.26006, 9.53892 47.26507, 9.53075 47.27058, 9.54332 47.27834, 9.54615 47.28, 9.55147 47.28704, 9.55401 47.29392, 9.55456 47.29541, 9.55509 47.29684, 9.55658 47.29846, 9.55923 47.30019, 9.56573 47.30418, 9.57061 47.30632, 9.58156 47.31112, 9.5836 47.31266, 9.58829 47.31754, 9.58928 47.31915, 9.59236 47.32715, 9.59481 47.3335, 9.59635 47.33752, 9.59942 47.345, 9.60073 47.3469, 9.60508 47.35129, 9.61324 47.35752, 9.61967 47.36243, 9.62448 47.36614, 9.64677 47.3673, 9.64955 47.36745, 9.66109 47.37061, 9.66983 47.37719, 9.67332 47.38225, 9.67358 47.39129, 9.67247 47.39262, 9.67063 47.39368, 9.66869 47.39432, 9.66246 47.39639, 9.66011 47.39755, 9.65735 47.40016, 9.65439 47.4044, 9.65164 47.40463, 9.6519 47.40857, 9.6509 47.41643, 9.6503 47.42111, 9.64903 47.42472, 9.64677 47.4289, 9.64512 47.43206, 9.64434 47.43516, 9.6447 47.43675, 9.64677 47.43974, 9.6508 47.44274, 9.658 47.44779, 9.65906 47.44912, 9.65945 47.45138, 9.6517 47.45466, 9.64677 47.45521, 9.62243 47.45792, 9.61177 47.46877, 9.60725 47.47033, 9.60298 47.46288, 9.59482 47.46362, 9.58308 47.48152, 9.57639 47.48661, 9.5658 47.49237, 9.56414 47.4936, 9.56282 47.49501, 9.5618 47.49679, 9.56131 47.4987, 9.56183 47.50456, 9.55872 47.54189, 9.56516 47.54091, 9.60592 47.5347, 9.61684 47.53304, 9.63057 47.53094, 9.64211 47.52919, 9.64677 47.52848, 9.6575 47.52684, 9.66388 47.52587, 9.68036 47.52336, 9.70197 47.52793, 9.72805 47.53345, 9.72988 47.53364, 9.73217 47.53373, 9.73619 47.5358, 9.73555 47.54611, 9.74066 47.55354, 9.74605 47.55595, 9.74449 47.55893, 9.75072 47.56693, 9.74937 47.57069, 9.75568 47.57216, 9.75625 47.57831, 9.76228 47.58496, 9.77718 47.59449, 9.79787 47.59518, 9.80275 47.59534, 9.81348 47.58883, 9.82031 47.58764, 9.82375 47.58718, 9.82668 47.5781, 9.82144 47.56968, 9.82554 47.56031, 9.8155 47.5493, 9.82977 47.54453, 9.85002 47.54136, 9.8584 47.53447, 9.87449 47.52854, 9.87778 47.53945, 9.87611 47.54379, 9.87877 47.54654, 9.88143 47.54782, 9.88942 47.54437, 9.90099 47.54429, 9.90844 47.5387, 9.91473 47.53208, 9.92258 47.53, 9.94115 47.53758, 9.96112 47.53522, 9.96005 47.54264, 9.96781 47.54624))"}

The problem is the conversion back to geoJson. It is not working (type unknown). Do I miss something?

@dsmiley
Copy link
Contributor

dsmiley commented Sep 22, 2020

I don't have my IDE in front of me as I write this, but I can see you are not starting from a spatial context. Use JtsSpatialContext.GEO (declare as a variable/field as you wish, typically named "ctx"), and don't use/reference the factory of the spatial context unless you need to tweak the configuration to produce a different spatial context than typical. The idea is that the spatial context is the facade to everything else. From this, you can get a GeoJSONWriter & Reader without trying to use their constructors as you are doing now. If you are calling a constructor of anything other than possibly a SpatialContextFactory, then you're probably not using the APIs as intended. So once you have the context, then grab ctx.getFormats().getGeoJsonWriter (or Reader). Let me know how that works.

@janhoy
Copy link

janhoy commented Nov 4, 2022

I had the same issue, but solved it by using JtsGeoJSONWriter instead of GeoJSONWriter from spatial4j:

org.locationtech.spatial4j.io.jts.JtsGeoJSONWriter(JtsSpatialContext.GEO, JtsSpatialContextFactory()).toString(myShape)

I also had some success with https://github.com/bjornharrtell/jts2geojson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants