Different result WKT & WKB
akhenakh opened this issue · 3 comments
akhenakh commented
I was wondering if the WKB parser is stricter or if it was coming from my data?
Same data stored in Spatialite
select global_id , ST_AsText(GEOM) as geom, hex(ST_AsBinary(GEOM)) as bin from mytable;
package main
import (
"encoding/hex"
"fmt"
"log"
"github.com/peterstace/simplefeatures/geom"
)
func main() {
data := `MULTIPOLYGON Z(((-118.073275 33.859562 0, -118.071182 33.859985 0, -118.069076 33.860365 0, -118.06696 33.860701 0, -118.066681 33.860739 0, -118.066681 33.858339 0, -118.075015 33.858339 0, -118.075015 33.859171 0, -118.073275 33.859562 0)), ((-118.066681 33.858339 0, -118.058348 33.858339 0, -118.050015 33.858339 0, -118.041681 33.858339 0, -118.033348 33.858339 0, -118.033348 33.850005 0, -118.025015 33.850005 0, -118.016681 33.850005 0, -118.008348 33.850005 0, -118.008348 33.841672 0, -118.000015 33.841672 0, -118.000015 33.833339 0, -117.991681 33.833339 0, -117.991681 33.825005 0, -117.983348 33.825005 0, -117.976869 33.825005 0, -117.976234 33.824049 0, -117.975237 33.822456 0, -117.974289 33.820842 0, -117.973389 33.81921 0, -117.972539 33.817558 0, -117.971738 33.81589 0, -117.970988 33.814206 0, -117.970289 33.812506 0, -117.96964 33.810792 0, -117.969044 33.809065 0, -117.968499 33.807326 0, -117.968007 33.805577 0, -117.967567 33.803818 0, -117.96718 33.80205 0, -117.966846 33.800274 0, -117.966566 33.798492 0, -117.966339 33.796705 0, -117.966166 33.794914 0, -117.966047 33.793119 0, -117.965981 33.791323 0, -117.965969 33.789526 0, -117.966012 33.787729 0, -117.966108 33.785933 0, -117.966257 33.78414 0, -117.966461 33.782351 0, -117.966718 33.780567 0, -117.967029 33.778788 0, -117.967392 33.777017 0, -117.967809 33.775254 0, -117.968278 33.7735 0, -117.9688 33.771756 0, -117.969374 33.770024 0, -117.969999 33.768305 0, -117.970676 33.766599 0, -117.971404 33.764907 0, -117.972182 33.763232 0, -117.97301 33.761573 0, -117.973888 33.759932 0, -117.974814 33.75831 0, -117.975789 33.756707 0, -117.976811 33.755126 0, -117.97788 33.753567 0, -117.978996 33.75203 0, -117.980157 33.750517 0, -117.981364 33.749029 0, -117.982614 33.747566 0, -117.983908 33.74613 0, -117.985245 33.744722 0, -117.986623 33.743342 0, -117.988042 33.741991 0, -117.989501 33.74067 0, -117.990999 33.739381 0, -117.992535 33.738123 0, -117.994108 33.736897 0, -117.995718 33.735705 0, -117.997363 33.734546 0, -117.999042 33.733423 0, -118.000754 33.732335 0, -118.002498 33.731283 0, -118.004273 33.730267 0, -118.006077 33.729289 0, -118.007911 33.72835 0, -118.009772 33.727448 0, -118.011659 33.726586 0, -118.013571 33.725764 0, -118.015508 33.724982 0, -118.017467 33.724241 0, -118.019448 33.72354 0, -118.021449 33.722882 0, -118.02347 33.722265 0, -118.025508 33.721691 0, -118.027562 33.72116 0, -118.029632 33.720671 0, -118.031716 33.720227 0, -118.033813 33.719825 0, -118.03592 33.719468 0, -118.038038 33.719155 0, -118.040165 33.718886 0, -118.042299 33.718662 0, -118.044439 33.718483 0, -118.046583 33.718348 0, -118.048731 33.718258 0, -118.050881 33.718213 0, -118.053032 33.718213 0, -118.055182 33.718258 0, -118.05733 33.718348 0, -118.059475 33.718483 0, -118.061615 33.718662 0, -118.063748 33.718886 0, -118.065875 33.719155 0, -118.067993 33.719468 0, -118.070101 33.719825 0, -118.072197 33.720227 0, -118.074281 33.720671 0, -118.076351 33.72116 0, -118.078405 33.721691 0, -118.080443 33.722265 0, -118.082464 33.722882 0, -118.084465 33.72354 0, -118.086446 33.724241 0, -118.088405 33.724982 0, -118.090342 33.725764 0, -118.092254 33.726586 0, -118.094142 33.727448 0, -118.096002 33.72835 0, -118.097836 33.729289 0, -118.099641 33.730267 0, -118.101416 33.731283 0, -118.10316 33.732335 0, -118.104872 33.733423 0, -118.10655 33.734546 0, -118.108195 33.735705 0, -118.109805 33.736897 0, -118.111378 33.738123 0, -118.112914 33.739381 0, -118.114412 33.74067 0, -118.115871 33.741991 0, -118.116681 33.742762 0, -118.116681 33.750005 0, -118.108348 33.750005 0, -118.100015 33.750005 0, -118.100015 33.758339 0, -118.091681 33.758339 0, -118.083348 33.758339 0, -118.083348 33.766672 0, -118.075015 33.766672 0, -118.075015 33.775005 0, -118.075015 33.783339 0, -118.066681 33.783339 0, -118.066681 33.791672 0, -118.066681 33.800005 0, -118.058348 33.800005 0, -118.058348 33.808339 0, -118.058348 33.816672 0, -118.058348 33.825005 0, -118.058348 33.833339 0, -118.066681 33.833339 0, -118.066681 33.841672 0, -118.066681 33.850005 0, -118.066681 33.858339 0)))`
g, err := geom.UnmarshalWKT(data)
if err != nil {
log.Fatal(err)
}
fmt.Println(g)
wkb := `01EE0300000200000001EB030000010000000900000007B50E8AB0845DC001E77D1D06EE4040000000000000000007B5463D8E845DC00197E3FF13EE404000000000000000000735D8BD6B845DC00117297220EE4040000000000000000007B54F1149845DC001274D722BEE4040000000000000000007CD2C8244845DC0018F42B22CEE4040000000000000000007CD2C8244845DC0018F560BDEED4040000000000000000007CDB60ACD845DC0018F560BDEED4040000000000000000007CDB60ACD845DC001AFD54EF9ED4040000000000000000007B50E8AB0845DC001E77D1D06EE4040000000000000000001EB030000010000009C000000CD0D2D8244845DC0E2A8560BDEED40400000000000000000CD0DA3F9BB835DC0E2A8560BDEED40400000000000000000CD0D197133835DC0E2A8560BDEED40400000000000000000CD0D8FE8AA825DC0E2A8560BDEED40400000000000000000CD0D056022825DC0E2A8560BDEED40400000000000000000CD0D056022825DC0E2A842FACCEC40400000000000000000CD0D7BD799815DC0E2A842FACCEC40400000000000000000CD0DF14E11815DC0E2A842FACCEC40400000000000000000CD0D67C688805DC0E2A842FACCEC40400000000000000000CD0D67C688805DC0E2A82EE9BBEB40400000000000000000CD0DDD3D00805DC0E2A82EE9BBEB40400000000000000000CD0DDD3D00805DC0E2A81AD8AAEA40400000000000000000CD0D53B5777F5DC0E2A81AD8AAEA40400000000000000000CD0D53B5777F5DC0E2A806C799E940400000000000000000CD0DC92CEF7E5DC0E2A806C799E940400000000000000000CD8D7306857E5DC0E2A806C799E940400000000000000000CD0DEC9D7A7E5DC0E288E16F7AE940400000000000000000CD0D2F4A6A7E5DC0E2486F3B46E940400000000000000000CDED4CC05A7E5DC0E248795C11E940400000000000000000CD6DC2024C7E5DC0E2C87EDBDBE840400000000000000000CDFDEA133E7E5DC0E28814C1A5E840400000000000000000CDADFEF5307E5DC0E288EB156FE840400000000000000000CD4D16AB247E5DC0E208CCE237E840400000000000000000CD4D2735197E5DC0E2C88F3000E840400000000000000000CDED06960E7E5DC0E2082C08C8E740400000000000000000CDED65CF047E5DC0E2089F728FE740400000000000000000CD8DD1E2FB7D5DC0E208037956E740400000000000000000CDCDB5D1F37D5DC0E2487A241DE740400000000000000000CD255A9DEC7D5DC0E2083B7EE3E640400000000000000000CDCDE446E67D5DC0E288818FA9E640400000000000000000CD4554CFE07D5DC0E2489D616FE640400000000000000000CDDD8737DC7D5DC0E2C8E4FD34E640400000000000000000CD353780D87D5DC0E288B46DFAE540400000000000000000CD8DF7A9D57D5DC0E28871BABFE540400000000000000000CDB53AB5D37D5DC0E2C889ED84E540400000000000000000CDD74BA2D27D5DC0E2C868104AE5404000000000000000004DD35471D27D5DC0E288822C0FE5404000000000000000004DE15822D37D5DC0E248474BD4E4404000000000000000004DDD38B5D47D5DC0E2082B7699E4404000000000000000004D11B029D77D5DC0E2C89BB65EE4404000000000000000004D55567FDA7D5DC0E208051624E4404000000000000000004DFD9EB5DE7D5DC0E248D09DE9E3404000000000000000004DF5D9CBE37D5DC0E2485C57AFE3404000000000000000004DA532C1E97D5DC0E248014C75E3404000000000000000004DEDAF94F07D5DC0E2C80C853BE3404000000000000000004D653745F87D5DC0E2C8C30B02E3404000000000000000004D1589D1007E5DC0E2885EE9C8E2404000000000000000004DC543380A7E5DC0E288012790E2404000000000000000004DB5E277147E5DC0E248CBCD57E2404000000000000000004DA5BB8E1F7E5DC0E248C0E61FE2404000000000000000004D55077B2B7E5DC0E208D67AE8E1404000000000000000004DC5D63A387E5DC0E208F192B1E1404000000000000000004DE51CCC457E5DC0E2C8DD377BE1404000000000000000004D45AA2C547E5DC0E2484F7245E1404000000000000000004D352E5A637E5DC0E248E74A10E1404000000000000000004DA53652737E5DC0E24827CADBE0404000000000000000004D853112847E5DC0E2887BF8A7E0404000000000000000004D656D97957E5DC0E2C82FDE74E0404000000000000000004DA518DFA77E5DC0E2C8738342E0404000000000000000004DC542E6BA7E5DC0E28857F010E0404000000000000000004DE5DDA9CE7E5DC0E208D12CE0DF404000000000000000004D45BC26E37E5DC0E208A940B0DF404000000000000000004DE59259F87E5DC0E2C8923381DF404000000000000000004D25FC3E0E7F5DC0E2C8140D53DF404000000000000000004D0572D3247F5DC0E2C892D425DF404000000000000000004DE555133C7F5DC0E2484A91F9DE404000000000000000004D05ECFA537F5DC0E208564ACEDE404000000000000000004D055E866C7F5DC0E2C89F06A4DE404000000000000000004DC5BCB1857F5DC0E288EECC7ADE404000000000000000004D45FF789F7F5DC0E208DAA352DE404000000000000000004DC501D8B97F5DC0E2C8D3912BDE404000000000000000004DE589CAD47F5DC0E2881B9D05DE404000000000000000004DC5454CF07F5DC0E208C2CBE0DD404000000000000000004DE5CD580C805DC0E248B123BDDD404000000000000000004D25A2EB28805DC0E2889DAA9ADD404000000000000000004D252F0046805DC0E288096679DD404000000000000000004DE5CA9163805DC0E208495B59DD404000000000000000004D25BA9B81805DC0E2687E8F3ADD404000000000000000004D452C19A0805DC0E20896071DDD404000000000000000004D453E05BF805DC0E2484BC800DD404000000000000000004D25FC5ADE805DC0E28823D6E5DC404000000000000000004DC56215FE805DC0E2A86E35CCDC404000000000000000004DC55C2F1E815DC0E2A846EAB3DC404000000000000000004DC5C6A33E815DC0E20890F89CDC404000000000000000004D456D6D5F815DC0E248F56387DC404000000000000000004D45118780815DC0E2E8E82F73DC404000000000000000004D4565EBA1815DC0E248AC5F60DC404000000000000000004DC51395C3815DC0E2C83BF64EDC404000000000000000004D85B67EE5815DC0E2C864F63EDC404000000000000000004D45E0A207825DC0E228B66230DC404000000000000000004D051CFC29825DC0E2D8823D23DC404000000000000000004D45E9844C825DC0E2F8E78817DC404000000000000000004D85C0376F825DC0E268C4460DDC404000000000000000004D85160F92825DC0E218BD7804DC404000000000000000004DC55405B5825DC0E2A03820FDDB404000000000000000004D45E614D8825DC0E2B0633EF7DB404000000000000000004D452C38FB825DC0E21033D4F2DB404000000000000000004D0589691E835DC0E2E056E2EFDB404000000000000000004D855AA341835DC0E2AA4B69EEDB404000000000000000004D85FDDF64835DC0A1694B69EEDB404000000000000000004D05CF1988835DC0A11D56E2EFDB404000000000000000004DC52B4BAB835DC0A1CD31D4F2DB404000000000000000004DC5716ECE835DC0A1E5613EF7DB404000000000000000004D85037EF1835DC0A1553620FDDB404000000000000000004D05427414845DC0A145BA7804DC404000000000000000004D05974B37845DC0A115C1460DDC404000000000000000004D856FFE59845DC0A125E48817DC404000000000000000004DC53C877C845DC0A1857E3D23DC404000000000000000004D8577E09E845DC0A155B16230DC404000000000000000004D85A204C1845DC0A1755FF63EDC404000000000000000004D8545EEE2845DC0A10536F64EDC404000000000000000004D05F39704855DC0A105A65F60DC404000000000000000004D4548FC25855DC0A125E22F73DC404000000000000000004D45EC1547855DC0A105EE6387DC404000000000000000004D0593DF67855DC0A14588F89CDC404000000000000000004D05FD5388855DC0A1653EEAB3DC404000000000000000004D05F76DA8855DC0A1E56535CCDC404000000000000000004DC55D28C8855DC0A1651AD6E5DC404000000000000000004DC51B7EE7855DC0A1C541C800DD404000000000000000004DE52D6A06865DC0A1258C071DDD404000000000000000004D25A0E724865DC0A105748F3ADD404000000000000000004D658EF142865DC0A1453E5B59DD404000000000000000004D452B8360865DC0A145FE6579DD404000000000000000004D65B7977D865DC0A1C591AA9ADD404000000000000000004DE58C2A9A865DC0A145A523BDDD404000000000000000004D251437B6865DC0A1C5B5CBE0DD404000000000000000004D45D1B8D1865DC0A1C50E9D05DE404000000000000000004DA559ABEC865DC0A185C6912BDE404000000000000000004D655C0A07875DC0A145CCA352DE404000000000000000004D059ED120875DC0A145E0CC7ADE404000000000000000004D05FEFC39875DC0A1459106A4DE404000000000000000004D45708852875DC0A145474ACEDE404000000000000000004DA506706A875DC0A1053B91F9DE404000000000000000004D156EB577875DC0A1E53FD512DF404000000000000000004D156EB577875DC0A1E54C2D00E0404000000000000000004D15E42CEF865DC0A1E54C2D00E0404000000000000000004D155AA466865DC0A1E54C2D00E0404000000000000000004D155AA466865DC0A1E5603E11E1404000000000000000004D15D01BDE855DC0A1E5603E11E1404000000000000000004D15469355855DC0A1E5603E11E1404000000000000000004D15469355855DC0A1E5744F22E2404000000000000000004D15BC0ACD845DC0A1E5744F22E2404000000000000000004D15BC0ACD845DC0A1E5886033E3404000000000000000004D15BC0ACD845DC0A1E59C7144E4404000000000000000004D15328244845DC0A1E59C7144E4404000000000000000004D15328244845DC0A1E5B08255E5404000000000000000004D15328244845DC0A1E5C49366E6404000000000000000004D15A8F9BB835DC0A1E5C49366E6404000000000000000004D15A8F9BB835DC0A1E5D8A477E7404000000000000000004D15A8F9BB835DC0A1E5ECB588E8404000000000000000004D15A8F9BB835DC0A1E500C799E9404000000000000000004D15A8F9BB835DC0A1E514D8AAEA404000000000000000004D15328244845DC0A1E514D8AAEA404000000000000000004D15328244845DC0A1E528E9BBEB404000000000000000004D15328244845DC0A1E53CFACCEC40400000000000000000CD0D2D8244845DC0E2A8560BDEED40400000000000000000`
b, err := hex.DecodeString(wkb)
if err != nil {
log.Fatal(err)
}
fromWKB, err := geom.UnmarshalWKB(b)
if err != nil {
log.Fatal(err)
}
fmt.Println(fromWKB)
}
https://goplay.tools/snippet/s6hcMwJh9hX
output:
MultiPolygon[XYZ] with 2 polygons consisting of 2 total rings and 165 total points
2009/11/10 23:00:00 failed geometry constraint: multipolygon child polygon interiors intersect at {-118.06668142676436 33.85833875397647}
akhenakh commented
Could it be because of lost of precision with the WKT 32bits vs 64bits double encoding
akhenakh commented
hex(ST_AsBinary(ST_MakeValid(GEOM)))
solved the issue sorry for the noise
peterstace commented
Looks like you got to the bottom of it.
Just to confirm, WKB and WKT parsing use the same geometry validation routines, and both operate on float64
s.