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

convert wkb to wkt via php #160

Open
sanabadai opened this issue Dec 15, 2018 · 3 comments
Open

convert wkb to wkt via php #160

sanabadai opened this issue Dec 15, 2018 · 3 comments

Comments

@sanabadai
Copy link

hi
i have this wkb string:
0xE61000000104060000004A5429C0E349424010806D3742964D4040038179E2494240BC8752993B964D407543AEF8E1494240BB1A3C373B964D40D29E7A81DF494240BDC654F23B964D409EE3FDE0E04942406CEB561143964D404A5429C0E349424010806D3742964D4001000000020000000001000000FFFFFFFF0000000003

i want to convert this to wkt via php?
can i do this?
please help me!
thanks.

@BathoryPeter
Copy link

geoPHP::load($wkbString)->out('wkt');

But keep in mind, that geoPHP's WKB adapter is buggy and sometimes crashes. I had completely rewrite the WKB adapter in my fork supporting every OGC type and EWKB too. Give a try: https://github.com/funiq/geoPHP

@sanabadai
Copy link
Author

i have this
require 'geoPHP.inc';
$dbString1='0xE61000000104060000004A5429C0E349424010806D3742964D4040038179E2494240BC8752993B964D407543AEF8E1494240BB1A3C373B964D40D29E7A81DF494240BDC654F23B964D409EE3FDE0E04942406CEB561143964D404A5429C0E349424010806D3742964D4001000000020000000001000000FFFFFFFF0000000003';
geoPHP::load($dbString1)->out('wkt');

but give me error:
Fatal error: Uncaught Error: Call to a member function out() on boolean in E:\xampp\htdocs\golbahar\test\test.php:4 Stack trace: #0 {main} thrown in E:\xampp\htdocs\golbahar\test\test.php on line 4

@BathoryPeter
Copy link

Because it is an invalid WKB.
At first, remove the unneeded 0x prefix, then we get a hex string.
Then look at the first byte: E6100000 = 4326 in decimal, so it is an EWKB and the geometry is in EPSG:4326. Its nice, but the first 10 bit (endianness and geometry type) is missing. From the EPSG code, we know that the string is little endian coded, and we can try to guess the type mask. For that, the have to investigate in the remaining part. Geometries are built from UInt32 and Double (64 bit) values, thus the remaining part must be divisible by 32. The string is 248 character which is 31 UInt32 value, hooray. Its too long to be a single point, so it must be some collection. Then the next UInt32 value (01040600) is the number of geometries. But if we convert 01040600 to decimal, we get a huge number: 394241. Its certainly bad.

At this point, we have to stop guessing. Your string is not a WKB and cannot be recover.

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

2 participants