James
James

Reputation: 720

PHP convert WKB to WKT

I have been trying to figure this out for days. We have a spatialite database that is read by php and data is returned in a json feed. I do not have access to spatialite addon to sqlite in my hosting plan. We are initially trying to find a library or other means of recreating the AsText() function used in mysql.

Our first attempt was using the geoPHP library but they only support small endian.

Below is our initial code using sqlite3. We are able to get the binary but can not figure out how to parse it to text.

$db = new SQLite3($checkDB);
$results = $db->query("SELECT * FROM ".$data['table']." LIMIT ". $limit .";" );
while ($row = $results->fetchArray(SQLITE3_ASSOC)){ 
  $binary = unpack('H*', $row['GEOMETRY']);
  
  
}

It could also be that our unpack is not correct and our binary is incorrect. Below is a sample of what we are receiving

0001110f00002239c4f5464063c1fc6e0077089555419499b113354063c126bce1344b9555417c0600000001000000690300000001000000130000002224b3313d4063c1fc6e007708955541fa546fd1424063c19ea95870109555419b8ff46f464063c12aae85851e9555412239c4f5464063c1c2335e9f27955541764d5fde424063c100ca750124955541bde0a2913f4063c180e53d6a259555417259cb293f4063c1c758a1922d9555419f80bd7c424063c12ed7418c37955541e8c44f97414063c1920795c44395554112ec8cbf3f4063c11b270af44a9555418bf133db374063c126bce1344b9555418ca2a532394063c143208025419555413d9d2d513a4063c1099ca9ac389555410596e3a9374063c1dda0cc0d399555419499b113354063c10e7b1fd0349555417715a655354063c1d917d2662b95554117e2eef3384063c12285daa01e95554156768ba63c4063c18bb65948139555412224b3313d4063c1fc6e007708955541fe 

Upvotes: 0

Views: 155

Answers (0)

Related Questions