php and PROJ
Chad Streck
chads at adci.com
Wed Apr 11 09:14:06 PDT 2001
My apologies for not checking the archive first.
I got the php_proj.c file compiled into a library and linked it to my
php program the same way I link php_mapscript.so (dl), but it appears
that pj_init is not returning an object. Here is the code I'm using to
pull the parameters from my map file....
// a function to initialize the php_proj from the map file
function proj_init($mapfile) {
if(file_exists($mapfile) && $fp = fopen($mapfile, 'r')) {
while (!feof($fp)) {
$line = fgets($fp, 1000);
if(preg_match("/projection/", $line)) {
$projarray = array();
$line = fgets($fp, 1000);
while(!preg_match("/end/", $line)) {
$line = preg_replace("/^ *\"/",
"", $line);
$line = preg_replace("/\".*$/",
"", $line);
$projarray[] = $line;
$line = fgets($fp, 1000);
}
/////////////////
print_debug($projarray);
fclose($fp);
$pj = pj_init($projarray);
/////////////////
print_debug($pj);
return $pj;
}
}
fclose($fp);
}
return NULL;
}
print_debug will print out a table of the object whether its an array or
object. I get what I'm expecting for the first print_debug, but nothing
for the second. Here is what I am getting.....
0
proj=tmerc
1
ellps=GRS80
2
units=ft
3
lon_0=-111.916666667
4
lat_0=31.000000000
5
x_0=213360.000
6
y_0=0.000000
7
k=0.999900
8
no_defs
*Fatal error*: Object expected as argument. in
*/var/www/html/maps/ace.php* on line *246*
Is there any insight as to what I'm doing wrong?
Thanks,
Chad
Assefa Yewondwossen wrote:
> Hi There,
>
> Here is an answer posted earlier on the list:
>
>
> There is a php/proj module available in the mapserver distribution
> (.../mapserver/mapscript/php3/php_proj.c). This module give access to basic
> Proj4 fonctionalities. So
> in your case you could use the functions to convert the Georeferenced
> coordinated to Lat/Long
> coordinates.
>
> If you are on a Windows platform, You can download the binary versions at :
>
> http://www2.dmsolutions.ca/mapserver/dl/php4.0.4pl1_php_proj_dll.zip
> http://www2.dmsolutions.ca/mapserver/dl/php4.0.3_php_proj_dll.zip
>
> Later,
>
>
> PS :
>
> Here is a little bit of docs on how to use it :
>
> /*
> * PHP PROJ4 Module
> *
> * This is a PHP module that gives acces to basic PROJ4 projection
> * functionalities.
> *
> * There are four functions available in this module :
> *
> * 1) pj_init : create and initializes a projection structures
> *
> * PJ pj_init(array_of_parameters)
> *
> * Example : $projarray[0] = "proj=lcc";
> * $projarray[1] = "ellps=GRS80";
> * $projarray[2] = "lat_0=49";
> * $projarray[3] = "lon_0=-95";
> * $projarray[4] = "lat_1=49";
> * $projarray[5] = "lat_2=77";
> *
> * $pj = pj_init($projarray);
> *
> * 2) pj_fwd : Performs a projection from lat/long coordinates to
> * cartesian coordinates.
> *
> * retrun_array pj_fwd(double lat, double long, PJ pj)
> *
> * Example : $lat = 45.25;
> * $long = -75.42;
> *
> * $ret = pj_fwd($ingeox, $ingeoy, $pj);
> * printf("geo x = %f<br>\n", $ret["u"]);
> * printf("geo y = %f<br>\n",$ret["v"]);
> *
> * 3) pj_inv : Performs a projection from cartesian coordinates to
> * lat/long coordinates .
> *
> * retrun_array pj_fwd(double geox, double geoy, PJ pj)
> *
> * Example : $ingeox = 1537490.335842;
> * $ingeoy = -181633.471555;
> *
> * $ret = pj_inv($ingeox, $ingeoy, $pj);
> * printf("lat = %f<br>\n", $ret["u"]);
> * printf("lon = %f<br>\n",$ret["v"]);
> *
> * 4) pj_free : frees PJ structure
> *
> * void pj_free(PJ pj);
> *
> **********************************************************************/
>
>
>
> Chad Streck wrote:
>
>> Thanks everyone for the help in getting our demo up and running. Its
>> looking like we may be getting this job, which means that for a point
>> file, I'll have to be dynamically creating lat/long points on the map
>> that is projected in AZ-C. I plan on placing the points on a blank
>> geographic projected layer which will place the points in the correct
>> position, but I'll need to be able to get the world coordinates of a
>> click on the image in lat/long and not AZ-C. Is there an easy way to do
>> this with php_mapscript or a way to access the PROJ library directly
>> from PHP other than system/exec?
>>
>> Thanks,
>> Chad Streck
>
>
> --
> ----------------------------------------------------------------
> Assefa Yewondwossen
> Software Analyst
>
> Email: assefa at dmsolutions.ca
> http://www.dmsolutions.ca/
>
> Phone: (613) 565-5056
> ----------------------------------------------------------------
>
>
>
>
More information about the MapServer-users
mailing list