Commit a1f04b238427aca07ec2a32ff82abda67accbda9

Authored by Edmar Moretti
1 parent 451815dd

Adaptação nos códigos para funcionar na versão 4 e 5 do Mapserver

Showing 1 changed file with 66 additions and 52 deletions   Show diff stats
classesphp/classe_analise.php
@@ -1332,60 +1332,74 @@ $operacao - Tipo de análise. @@ -1332,60 +1332,74 @@ $operacao - Tipo de análise.
1332 foreach ($lista as $l) 1332 foreach ($lista as $l)
1333 { 1333 {
1334 $geos = &$this->unserializeGeo($dir.$l); 1334 $geos = &$this->unserializeGeo($dir.$l);
1335 - foreach ($geos["dados"] as &$geo) 1335 + $v = explode(" ",ms_GetVersion());
  1336 + $v = explode(".",$v[2]);
  1337 + if (($v != 5) && ($postgis_con == ""))
  1338 + {return ("erro. Nao foi definida a conexao com o Postgis.");}
  1339 + if ($v != 5)
1336 { 1340 {
1337 - $g = $geo["wkt"];  
1338 - //$pgconn = pg_connect($postgis_con);  
1339 - switch ($operacao) 1341 + $pgconn = pg_connect($postgis_con);
  1342 + foreach ($geos["dados"] as &$geo)
1340 { 1343 {
1341 - case "perimetro":  
1342 - /*  
1343 - $sql = "select perimeter(transform( GeomFromText('$g',4291),$srid_area))::float as perim";  
1344 - $result=pg_query($pgconn, $sql);  
1345 - pg_close($pgconn);  
1346 - $calculo = pg_fetch_all($result);  
1347 - $geo["valores"][] = array("item"=>"P_perim_metros","valor"=>$calculo[0]["perim"]);  
1348 - */  
1349 - $shape = ms_shapeObjFromWkt($g);  
1350 - $rect = $shape->bounds;  
1351 - $projInObj = ms_newprojectionobj("proj=latlong");  
1352 - $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000,units=m");  
1353 - $shape->project($projInObj, $projOutObj);  
1354 - $s = $shape->towkt();  
1355 - $shape = ms_shapeObjFromWkt($s);  
1356 - $area = $shape->getLength();  
1357 - $geo["valores"][] = array("item"=>"P_perim_metros","valor"=>$area);  
1358 -  
1359 - break;  
1360 - case "area":  
1361 - /*  
1362 - $sql = "select area(transform( GeomFromText('$g',4291),$srid_area))::float as aream";  
1363 - $result=pg_query($pgconn, $sql);  
1364 - pg_close($pgconn);  
1365 - $calculo = pg_fetch_all($result);  
1366 - $geo["valores"][] = array("item"=>"P_area_metros","valor"=>$calculo[0]["aream"]);  
1367 - */  
1368 - $shape = ms_shapeObjFromWkt($g);  
1369 - $rect = $shape->bounds;  
1370 - $projInObj = ms_newprojectionobj("proj=latlong");  
1371 - $projOutObj = ms_newprojectionobj("proj=laea,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=500000,y_0=10000000,ellps=GRS67,units=m,no_defs");  
1372 -  
1373 - $shape->project($projInObj, $projOutObj);  
1374 - $s = $shape->towkt();  
1375 - //echo $s;  
1376 - $shape = ms_shapeObjFromWkt($s);  
1377 - $area = $shape->getArea();  
1378 - $geo["valores"][] = array("item"=>"P_area_metros","valor"=>$area);  
1379 - break;  
1380 - case "comprimento":  
1381 - /*  
1382 - $sql = "select length(transform( GeomFromText('$g',4291),$srid_area))::float as compm";  
1383 - $result=pg_query($pgconn, $sql);  
1384 - pg_close($pgconn);  
1385 - $calculo = pg_fetch_all($result);  
1386 - $geo["valores"][] = array("item"=>"P_compr_metros","valor"=>$calculo[0]["compm"]);  
1387 - */  
1388 - break; 1344 + $g = $geo["wkt"];
  1345 + switch ($operacao)
  1346 + {
  1347 + case "perimetro":
  1348 + $sql = "select perimeter(transform( GeomFromText('$g',4291),$srid_area))::float as perim";
  1349 + $result=pg_query($pgconn, $sql);
  1350 + pg_close($pgconn);
  1351 + $calculo = pg_fetch_all($result);
  1352 + $geo["valores"][] = array("item"=>"P_perim_metros","valor"=>$calculo[0]["perim"]);
  1353 + break;
  1354 + case "area":
  1355 + $sql = "select area(transform( GeomFromText('$g',4291),$srid_area))::float as aream";
  1356 + $result=pg_query($pgconn, $sql);
  1357 + pg_close($pgconn);
  1358 + $calculo = pg_fetch_all($result);
  1359 + $geo["valores"][] = array("item"=>"P_area_metros","valor"=>$calculo[0]["aream"]);
  1360 + break;
  1361 + case "comprimento":
  1362 + $sql = "select length(transform( GeomFromText('$g',4291),$srid_area))::float as compm";
  1363 + $result=pg_query($pgconn, $sql);
  1364 + pg_close($pgconn);
  1365 + $calculo = pg_fetch_all($result);
  1366 + $geo["valores"][] = array("item"=>"P_compr_metros","valor"=>$calculo[0]["compm"]);
  1367 + break;
  1368 + }
  1369 + }
  1370 + }
  1371 + else
  1372 + {
  1373 + foreach ($geos["dados"] as &$geo)
  1374 + {
  1375 + $g = $geo["wkt"];
  1376 + switch ($operacao)
  1377 + {
  1378 + case "perimetro":
  1379 + $shape = ms_shapeObjFromWkt($g);
  1380 + $rect = $shape->bounds;
  1381 + $projInObj = ms_newprojectionobj("proj=latlong");
  1382 + $projOutObj = ms_newprojectionobj("proj=poly,ellps=GRS67,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=5000000,y_0=10000000,units=m");
  1383 + $shape->project($projInObj, $projOutObj);
  1384 + $s = $shape->towkt();
  1385 + $shape = ms_shapeObjFromWkt($s);
  1386 + $area = $shape->getLength();
  1387 + $geo["valores"][] = array("item"=>"P_perim_metros","valor"=>$area);
  1388 + break;
  1389 + case "area":
  1390 + $shape = ms_shapeObjFromWkt($g);
  1391 + $rect = $shape->bounds;
  1392 + $projInObj = ms_newprojectionobj("proj=latlong");
  1393 + $projOutObj = ms_newprojectionobj("proj=laea,lat_0=".$rect->miny.",lon_0=".$rect->minx.",x_0=500000,y_0=10000000,ellps=GRS67,units=m,no_defs");
  1394 + $shape->project($projInObj, $projOutObj);
  1395 + $s = $shape->towkt();
  1396 + $shape = ms_shapeObjFromWkt($s);
  1397 + $area = $shape->getArea();
  1398 + $geo["valores"][] = array("item"=>"P_area_metros","valor"=>$area);
  1399 + break;
  1400 + case "comprimento":
  1401 + break;
  1402 + }
1389 } 1403 }
1390 } 1404 }
1391 $this->serializeGeo($dir.$l,$geos); 1405 $this->serializeGeo($dir.$l,$geos);