Last active
January 19, 2023 17:29
-
-
Save yuletide/3909376 to your computer and use it in GitHub Desktop.
EPSG postgis scraper for `node-proj4js-defs`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -u | |
echo "module.exports = function(Proj4js){" > epsg.js | |
psql -t -h localhost -U $USER --command "SELECT 'Proj4js.defs[\"EPSG:' || srid || '\"] = \"' || trim(proj4text) || '\";' from | |
spatial_ref_sys" >> epsg.js | |
echo "};" >> epsg.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment