[postgis-users] Re:PHP access to PostGIS
Martin Høgh
mh at svaj.dk
Fri Mar 11 04:31:21 PST 2005
Hi,
I've written a php geometry lib which can do this. It's a part of the
MapLink projekt at http://sourceforge.net/projects/maplink/
the lib is called "libs/phpgeometry_class.php" get the latest from cvs.
The one in distro is buggy
some examples of uses
<?
$wkt="MULTILINESTRING((1 1,2 2,3 3),(20 20,30 30,40 40))"
include("phpgeometry_class.php"); // include the lib
$f=new geometryfactory; // new object which can create geometry objects
$g=$f->createGeometry($wkt);// $g is a new geometry object
$ver= $g->getVertices(); // get all vertices in one string. EXPLODE
THIS STRING e.g. explode(",",$ver) and you've the array you want!
some other methods of $g
$array=$g->getShapeArray();// array of shapes
$gml = $g->getGML(); // get the feature in gml format
$num= $g->getNumOfShapes();// numbers of shapes. In this case 2
$type= $g->getGeomType();// get the type of geometry. Here MULTILINESTRING
$g->updateShape("4 4,5 5,6 6",0);// updates the wkt on shape level. Each
shape of feature has a id starting from 0
$g->snapShape($shapeId,$snapTolerance,$snapLayerStr);// snaps shape with
$shapeId to $snapLayerStr using tolerance of $snapTolerance
$wkt= $g->getWKT();// get the wkt string back. Altered in this case
?>
new object in the next release of the lib
$con= new gmlConverter;
$con->gmlToWKT($gml); // where $gml is a gml stream. Return an array
with WKT strings for each feature member
/martin
Hi all,
I new to working with PostGIS. I'm using PHP and I need to get my
ployline into a PHP array. What is the best way to do this?
What I'm doing so far is:
// get the segment and offset the point right/left
// retrieve the segment geometry
$sql = "select AsText(geom) as geom from geocode" .
" where id = $this->oRefId";
// execute SQL query
$result = @pg_query($this->conn, $sql);
if (!$result) {
return false;
}
// get the number of rows in the resultset - must be one
$rows = pg_num_rows($result);
if ($rows < 1) {
return false;
}
// read the points
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
print_r($row);
echo "<br>\n";
Which gives me:
Array ( [geom] => LINESTRING(-73.338249206543
41.1630020141602,-73.3395233154297 41.1648445129395) )
So I'm wondering if I need to parse the text, or if there is an easier
way this into a PHP structure, like:
$line = [ [-73.338249206543, 41.1630020141602],
[-73.3395233154297, 41.1648445129395] ];
or some other array structure.
-Steve W.
--
Martin Høgh
Sven Allan Jensen as
Sankelmarksgade 9
9000 Aalborg
Tlf. 98129300
Direkte tlf. 96314082
More information about the postgis-users
mailing list