[postgis-users] issue with ST_AsEWKB

Sky Lendar skylendar at gmail.com
Sat Mar 18 07:22:05 PDT 2023


Hi there, and thank you for reading and answering this post.

First of all, thank you for PostGis itself. I have been wanting to use
postgis for years, but found not suitable data. But, thank to natural
earth, I got a decent set a geom data, and now, I can start up my
project.

That being said, I installed postgis 3.2.4 and created a table named
'coastline' containing the outlines of all the continents.

Here is an example of what I got:

select ST_AsEWKT(geometry) from coastline limit 1

MULTILINESTRING((180 -16.152929687500006,179.84814453125
-16.21425781250001,179.78886718750005
-16.221484375000003,179.7150390625 -16.207617187500006,179.63525390625
-16.223242187500006,179.5517578125 -16.24990234375001,179.47509765625
-16.29414062500001,179.35917968750005
-16.3798828125,179.29355468750003 -16.39863281250001,179.224609375
-16.40517578125001,179.09140625000003 -16.4375,178.96054687500003
-16.48281250000001,178.86572265625 -16.5400390625,178.80507812500002
-16.631445312500006,178.74453125000002
-16.63417968750001,178.68632812500005
-16.665625000000006,178.63427734375
-16.648535156250006,178.58359375000003
-16.621875000000003,178.56777343750002
-16.663867187500003,178.5419921875
-16.700488281250003,178.51376953125003
-16.72607421875,178.49746093750002 -16.787890625000003,178.6037109375
-16.800585937500003,178.63808593750002
-16.85126953125001,178.6650390625
-16.920019531250006,178.70664062500003
-16.976171875000006,178.8029296875 -16.9521484375,178.88369140625002
-16.886035156250003,178.950390625 -16.90400390625001,179.0068359375
-16.900195312500003,179.05546875000005
-16.813574218750006,179.20234375 -16.712695312500003,179.30048828125
-16.71035156250001,179.32333984375003
-16.718066406250003,179.34599609375005 -16.76972656250001,179.375
-16.7919921875,179.41933593750002
-16.80654296875001,179.46542968750003
-16.80605468750001,179.58896484375003
-16.78701171875001,179.71474609375002
-16.74355468750001,179.82080078125 -16.736914062500006,179.9279296875
-16.744433593750003,179.89003906250002 -16.6669921875,179.90595703125
-16.583593750000006,179.92656250000005
-16.55166015625001,179.93037109375 -16.51943359375001,179.8849609375
-16.51845703125001,179.841015625 -16.53750000000001,179.69707031250005
-16.631933593750006,179.56816406250005
-16.74746093750001,179.56416015625 -16.63691406250001,179.619140625
-16.52773437500001,179.74814453125003
-16.4462890625,179.79384765625002
-16.37031250000001,179.84824218750003 -16.30166015625001,179.99921875
-16.168554687500006))

So far so good. The data is correct and I can read it and display the
coastline. Fine !
But a need to read it faster, so I rather intend to use the hex form:

select ST_AsEWKB(geometry, 'NDR') from coastline limit 1;

and I got:

\x010500000001000000010200000038000000000000000080664068666666262730c000000000247b66409c999999d93630c0686666663e79664034333333b33830c09a999999e176664068666666263530c0000000005474664068666666263930c000000000a87166409c999999f93f30c000000000346f6640d0cccccc4c4b30c0686666667e6b664000000000406130c0cecccccc64696640d0cccccc0c6630c000000000306766409c999999b96730c0ceccccccec62664000000000007030c0ceccccccbc5e66409c999999997b30c000000000b45b664000000000408a30c034333333c359664068666666a6a130c034333333d35766409c99999959a230c068666666f65566406866666666aa30c0000000004c5466406866666606a630c0ceccccccac52664034333333339f30c0343333332b52664034333333f3a930c000000000585166403433333353b330c0cecccccc7050664000000000e0b930c034333333eb4f664034333333b3c930c09a9999995153664034333333f3cc30c0343333336b546640d0ccccccecd930c000000000485566406866666686eb30c0cecccccc9c56664068666666e6f930c09a999999b159664000000000c0f330c034333333475c664034333333d3e230c09a999999695e6640d0cccccc6ce730c000000000386066403433333373e630c068666666c66166406866666646d030c09a999999796666403433333373b630c09a9999999d6966409c999999d9b530c0cecccccc586a664034333333d3b730c068666666126b6640d0cccccc0cc530c000000000006c664000000000c0ca30c0343333336b6d66409c99999979ce30c0cecccccce46e66409c99999959ce30c0ceccccccd87266409c99999979c930c034333333df7666409c99999959be30c000000000447a664068666666a6bc30c09a999999b17d66403433333393be30c0343333337b7c664000000000c0aa30c09a999999fd7c664068666666669530c068666666a67d66409c999999398d30c09a999999c57d66409c999999f98430c09a999999517c66409c999999b98430c09a999999e97a66409c999999998930c0686666664e76664068666666c6a130c0686666662e7266409c99999959bf30c09a9999990d726640d0cccccc0ca330c000000000d07366409c999999198730c0ceccccccf077664000000000407230c03433333367796640d0cccccccc5e30c0cecccccc247b66409c999999394d30c09a999999f97f664068666666262b30c0

Seems good but when I process this string with libgeom or libgeom_c or
a handmade C routine, I rather got this:

Geometry: MULTILINESTRING ((180.0000000000000000 0.0000000000000000,
179.5356445312500000 0.0000000000000000, 179.7876464843750455
0.0000000000000000, 179.6955078124997272 0.0000000000000000,
179.6352539062500000 0.0000000000000000, 179.5322265625000000
0.0000000000000000, 179.1625976562500000 0.0000000000000000,
179.0454589843750455 0.0000000000000000, 179.2934733072917197
0.0000000000000000, 179.2246093750000000 0.0000000000000000,
179.0705729166667197 0.0000000000000000, 178.6272135416667197
0.0000000000000000, 178.5336914062500000 0.0000000000000000,
178.7855468750000227 0.0000000000000000, 178.7250000000000227
0.0000000000000000, 178.6667968750000455 0.0000000000000000,
178.6330566406250000 0.0000000000000000, 178.5627604166667197
0.0000000000000000, 178.5665527343750227 0.0000000000000000,
178.5419921875000000 0.0000000000000000, 178.5136881510417197
0.0000000000000000, 178.1642089843750227 0.0000000000000000,
178.6037109374997272 0.0000000000000000, 178.6368652343750227
0.0000000000000000, 178.6650390625000000 0.0000000000000000,
178.7053385416667197 0.0000000000000000, 178.7833984374997272
0.0000000000000000, 178.5711914062500227 0.0000000000000000,
178.6378906249997272 0.0000000000000000, 179.0068359375000000
0.0000000000000000, 179.0359375000000455 0.0000000000000000,
179.2023437499997272 0.0000000000000000, 179.2992675781247272
0.0000000000000000, 179.0107584635417197 0.0000000000000000,
179.0334960937500455 0.0000000000000000, 179.0625000000000000
0.0000000000000000, 179.1056152343750227 0.0000000000000000,
179.1333170572917197 0.0000000000000000, 179.5693522135417197
0.0000000000000000, 179.6939941406250227 0.0000000000000000,
179.5083007812500000 0.0000000000000000, 179.5958984374997272
0.0000000000000000, 179.5763183593750227 0.0000000000000000,
179.5727050781247272 0.0000000000000000, 179.5945312500000455
0.0000000000000000, 179.5983398437497272 0.0000000000000000,
179.5724609374997272 0.0000000000000000, 179.5089843749997272
0.0000000000000000, 179.6958496093750455 0.0000000000000000,
179.5669433593750455 0.0000000000000000, 179.5629394531247272
0.0000000000000000, 179.5996093750000000 0.0000000000000000,
179.7285319010417197 0.0000000000000000, 179.7938476562500227
0.0000000000000000, 179.5356608072917197 0.0000000000000000,
179.6671874999997272 0.0000000000000000))

Oops, the y part is always 0.0000 What's wrong ???

Thank you again for everything
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20230318/c30cd6e8/attachment.htm>


More information about the postgis-users mailing list