[postgis-users] shp2pgsql (php)

Paul Scott paul at in2one.co.za
Wed Dec 29 00:27:37 PST 2004


This is what I have so far, I am busy writing a function now that gets
the extents from postGIS and writes them to a mapfile (not Included)

//function to insert shapefiles (ESRI) into PostGIS DB
function create_sql($filename,$dbname)
{
	//create the tablename from the filename (replace the .shp with shp)
	$tablename1 = str_replace('.','',$filename);
	//Remove last three chars from table name ('shp' is discarded)
	$tablename = substr($tablename1,0,-3);
	//Give the log file a name by tacking .log onto the table name
	$logfile = $tablename.".log";
	//execute the shell script that does all the real work (thanks
refractions.net)
	$ret = shell_exec("/usr/local/pgsql/bin/shp2pgsql $filename
$tablename|/usr/local/pgsql/bin/psql -d $dbname 2>&1");
	//echo $ret; //debug only (displays the results)
	//open a file handle for binary safe write - this creates a
logfile...Use it or leave it, just an extra
	$handle = fopen($logfile,'w');
	//Write the log data to a file
	fwrite($handle, $ret);
	//close the file handle
	fclose($handle);
}

//loop through all the shapefiles and perform the function on them
foreach (glob("*.shp") as $filename) 
{
  //display the file size and name that we are currently working on
  //echo "$filename size " . filesize($filename) . "<br><br>\n";
  //do the sql-ize and insert the data, also write a log
  create_sql($filename,$dbname);
}//end foreach

On Wed, 2004-12-29 at 10:20, "Guillaume SUEUR (Géosignal)" wrote:
> I think I can be interested in that. If I can help !
> 
> regards
> 
> Guillaume
> 
> Paul Scott wrote:
> > ***********************
> > Votre mail a étét scanné par InterScan VirusWall.
> > ***********-***********
> > 
> > 
> > Hope you all had a good holiday!
> > 
> > I have written a shapefile dumper function in PHP using shp2pgsql that
> > basically goes through a directory of files and inserts them all into a
> > postgis db, and then writes a log file for each shapefile (for error
> > checking).
> > 
> > 
> > I am planning on making a PHP class to handle a bunch of functions for
> > creating db's, populating them and doing some other basic stuff, which I
> > will release on the phpclasses.org site. I would also like to include
> > some functions to create a UMN Mapserver .map file to use the data
> > automagically for "regular" users that don't need to know the
> > intricacies of postgis, mapserver and php to set up a quick app. i.e.
> > The users will be able to fill out a webform, upload their data in shp
> > format and in a few minutes have a ready to go mapserver app.
> > 
> > If anyone is interested in the code that I have written so far, or would
> > like to help out on this project, please contact me.
> > 
> > 
> > --Paul
> > --
> > 
> > Linux User #348957
> > 
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > 
> > 
> > 
> > 
-- 
Linux User #348957




More information about the postgis-users mailing list