[postgis-users] shp2pgsql (php)

Robert W. Burgholzer rburgholzer at maptech-inc.com
Wed Dec 29 10:22:44 PST 2004


Paul,

Don't know if this is helpful or just an ugly hack, but I happened to write 
a coordinate extractor this morning. The "projectid" field in my queries is 
used because my db has several projects stored in the same db, so eliminate 
it if yours doesn't need this. The "quickview" function is included, and as 
you can see is just a simple wrapper for setextent, and is implemented as a 
method on the object "amap".  The object "amap" is a custom object that I 
have written, carved out of the old gMap suite routines, and some home-made 
additions. The "listobject", "listobject->performquery()" and 
"listobject->getRecordValue" are proprietary functions that I use to make 
my applications somewhat db independent, and are not included in the 
interest of brevity:


# quickview function, sets the extent of a map,
    function quickView($lox,$loy,$hix,$hiy) {
       $this->map->setextent($lox,$loy,$hix,$hiy);
    }

# get the extent, and set your map to that extent
$listobject->querystring = "select extent(the_geom) as thisext from 
watersheds_dd where projectid = $projectid";

$listobject->performQuery();
$extext = $listobject->getRecordValue(1,'thisext');
#print("Extent: $extext <br>");
list($open, $tail) = explode("(", $extext);
list($coordpair, $close) = split(")", $tail);
list($locoords, $hicoords) = split(",", $coordpair);
list($lox, $loy, $loz) = split(" ", $locoords);
list($hix, $hiy, $hiz) = split(" ", $hicoords);

#print("$open, $tail, $coordpair, $close, $locoords, $hicoords, $lox, $loy, 
$loz, $hix, $hiy, $hiz<br>");


if (!isset($HTTP_POST_VARS['extent']) ) {
    $amap->quickView($lox,$loy,$hix,$hiy);
}

At 10:27 AM 12/29/2004 +0200, you wrote:
>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
>
>_______________________________________________
>postgis-users mailing list
>postgis-users at postgis.refractions.net
>http://postgis.refractions.net/mailman/listinfo/postgis-users

Robert Burgholzer
Environmental Engineer
MapTech Inc.
phone: 804-869-3066
http://www.maptech-inc.com/ 




More information about the postgis-users mailing list