diff --git a/README.md b/README.md index 894c3d13..fd788f2f 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,50 @@ Clearly, more complex analysis is possible. echo $geom2->envelope()->area(); +Working with PostGIS +--------------------- +geoPHP, through it's WKB adapter, has good integration with postGIS. Here's an example of reading and writing postGIS geometries + +```php +out('wkb')); + pg_query($connection, "INSERT INTO $table ($column) values (GeomFromWKB('$insert_string'))"); +} + +// Using a direct SELECT and INSERTs in PostGIS without using wrapping functions +$result = pg_fetch_all(pg_query($connection, "SELECT $column as geom FROM $table")); +foreach ($result as $item) { + $wkb = pack('H*',$item['geom']); // Unpacking the hex blob + $geom = geoPHP::load($wkb, 'wkb'); // We now have a geoPHP Geometry + + // To insert directly into postGIS we need to unpack the WKB + $unpacked = unpack('H*', $geom->out('wkb')); + $insert_string = $unpacked[1]; + pg_query($connection, "INSERT INTO $table ($column) values ('$insert_string')"); +} +``` + + Credit -------------------------------------------------