public
Created

EPSG postgis scraper

  • Download Gist
get_defs.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?php
/* from http://lists.osgeo.org/pipermail/openlayers-users/2010-June/017976.html */
$conn_string = "host=localhost port=5432
dbname=mydatabase_with_postgis_activated user=my_user password=my_password";
$link = pg_connect($conn_string) or die("Could not connect");
 
 
$start_epsg = 'Proj4js.defs["EPSG:';
$end_epsg_start_proj4js = '"] = "';
$end_proj4js ='";';
 
$select_epsg = pg_query("SELECT srid,trim(proj4text) as proj4text from
spatial_ref_sys");
 
/*
//Uncomment if you want to make a particular file for proj4js file depending
on defined epsgvalues
$epsgvalues = "4326,2154";
$select_epsg = pg_query("SELECT srid,trim(proj4text) as proj4text from
spatial_ref_sys WHERE srid IN(".$epsgvalues.")");
*/
 
$stringData="";
while($proj4_code = pg_fetch_array($select_epsg)) {
//To view result
echo
$start_epsg.$proj4_code["srid"].$end_epsg_start_proj4js.$proj4_code["proj4text"].$end_proj4js.'<br/>';
//To prepare content for writing result
$stringData.=$start_epsg.$proj4_code["srid"].$end_epsg_start_proj4js.$proj4_code["proj4text"].$end_proj4js."\r\n";
}
 
$myFile = "epsg.js";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $stringData);
fclose($fh);
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.