Commit 3a506a79ebff29096c9ab0c4d730c3e5102c5623

Authored by Edmar Moretti
1 parent c63ce0d7

Correção das opções que utilizam seleção para funcionarem corretamente no Postgi…

…s na versão 6 do Mapserver
classesphp/classe_analise.php
... ... @@ -1021,29 +1021,13 @@ $locaplic - Localização do I3geo.
1021 1021 //define o nome do novo shapefile que será criado
1022 1022 $nomefinal = nomeRandomico();
1023 1023 $nomeshp = $this->diretorio."/".$nomefinal;
1024   - //pega os shapes selecionados
1025   - $itemspt = pegaItens($layerPt);
1026   - $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
1027   - if ($existesel == "nao")
1028   - {$layerPt->queryByrect($this->mapa->extent);}
1029   - $res_count = $layerPt->getNumresults();
1030   - $pontos = array();
1031   - //pega um shape especifico
1032   - $sopen = $layerPt->open();
1033   - if($sopen == MS_FAILURE){return "erro";}
1034   - $spts = array();
1035   - for ($i = 0; $i < $res_count; ++$i)
1036   - {
1037   - if($this->v == 6)
1038   - {$shape = $layerPt->getShape($layerPt->getResult($i));}
1039   - else{
1040   - $result = $layerPt->getResult($i);
1041   - $shp_index = $result->shapeindex;
1042   - $shape = $layerPt->getfeature($shp_index,-1);
1043   - }
1044   - $spts[] = $shape;
  1024 + //
  1025 + $spts = retornaShapesSelecionados($layerPt,$this->arquivo,$this->mapa);
  1026 + if(count($spts) == 0){
  1027 + $spts = retornaShapesMapext($layerPt,$this->mapa);
1045 1028 }
1046   - $layerPt->close();
  1029 + //
  1030 + $itemspt = pegaItens($layerPt);
1047 1031 //gera o novo arquivo shape file
1048 1032 // cria o dbf
1049 1033 $def = $this->criaDefDb($itemspt);
... ... @@ -1098,7 +1082,7 @@ $locaplic - Localização do I3geo.
1098 1082 $lineo = $spt->line(0);
1099 1083 $pt = $lineo->point(0);
1100 1084 //faz a pesquisa
1101   - //error_reporting(E_ALL);
  1085 + error_reporting(E_ALL);
1102 1086 foreach ($layers as $layer)
1103 1087 {
1104 1088 $layer->set("template","none.htm");
... ... @@ -1109,7 +1093,7 @@ $locaplic - Localização do I3geo.
1109 1093 $itens = $listaItens[$layer->name];
1110 1094 $sopen = $layer->open();
1111 1095 if($sopen == MS_FAILURE){return "erro";}
1112   - if ($res_count > 0 && $layer->getResult(0) !== FALSE)
  1096 + if ($layer->getResult(0) !== FALSE)
1113 1097 {
1114 1098 if($this->v == 6)
1115 1099 {$shape = $layer->getShape($layer->getResult(0));}
... ... @@ -1139,8 +1123,7 @@ $locaplic - Localização do I3geo.
1139 1123 if($this->dbaseExiste == false)
1140 1124 xbase_close($db);
1141 1125 else
1142   - dbase_close($db);
1143   -
  1126 + dbase_close($db);
1144 1127 $novolayer = ms_newLayerObj($this->mapa, $layerPt);
1145 1128 $novolayer->set("data",$nomeshp.".shp");
1146 1129 $novolayer->set("name",$nomefinal);
... ... @@ -1149,9 +1132,6 @@ $locaplic - Localização do I3geo.
1149 1132 $novolayer->setmetadata("DOWNLOAD","SIM");
1150 1133 $novolayer->setmetadata("ITENS","");
1151 1134 $novolayer->setmetadata("ITENSDESC","");
1152   - //$novolayer->removeMetaData("ITENS");
1153   - //$novolayer->removeMetaData("ITENSDESC");
1154   -
1155 1135 if(ms_GetVersionInt() > 50201)
1156 1136 {$novolayer->setconnectiontype(MS_SHAPEFILE);}
1157 1137 else
... ... @@ -1171,7 +1151,7 @@ parameters:
1171 1151  
1172 1152 temaorigem - nome do layer com o ponto de origem
1173 1153  
1174   -temadestino - nome od tema com os pontos de destino
  1154 +temadestino - nome do tema com os pontos de destino
1175 1155  
1176 1156 temaoverlay - tema que será utilizado para selecionar o tema de destino
1177 1157  
... ... @@ -1182,8 +1162,9 @@ itemorigem - nome do item na tabela de atributos do tema de origem que será acre
1182 1162 itemdestino - nome do item na tabela de atributos do tema de origem que será acrescentado ao tema que será criado
1183 1163  
1184 1164 */
1185   -function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorigem,$itemdestino)
  1165 +function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorigem="",$itemdestino="")
1186 1166 {
  1167 + error_reporting(E_ALL);
1187 1168 set_time_limit(180);
1188 1169 //para manipular dbf
1189 1170 if($this->dbaseExiste == false){
... ... @@ -1195,34 +1176,21 @@ function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorig
1195 1176 //define o nome do novo shapefile que será criado
1196 1177 $nomefinal = nomeRandomico();
1197 1178 $nomeshp = $this->diretorio."/".$nomefinal;
  1179 +
1198 1180 $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
1199 1181 if ($existesel == "nao")
1200 1182 {return "errox";}
  1183 +
1201 1184 $layerorigem = $this->mapa->getlayerbyname($temaorigem);
1202 1185 $layerdestino = $this->mapa->getlayerbyname($temadestino);
1203 1186 $layeroverlay = $this->mapa->getlayerbyname($temaoverlay);
1204   - $sopen = $layerorigem->open();
1205   - if($sopen == MS_FAILURE){return "erro";}
1206   - $res_count = $layerorigem->getNumresults();
1207   - for ($i = 0; $i < $res_count; ++$i)
1208   - {
1209   - if($this->v == 6)
1210   - {$shapesorigem[] = $layerorigem->getShape($layerorigem->getResult($i));}
1211   - else{
1212   - $result = $layerorigem->getResult($i);
1213   - $shp_index = $result->shapeindex;
1214   - $shapesorigem[] = $layerorigem->getshape(-1, $shp_index);
1215   - }
  1187 +
  1188 + $shapesorigem = retornaShapesSelecionados($layerorigem,$this->arquivo,$this->mapa);
  1189 + if(count($shapesorigem) == 0){
  1190 + return "erro";
1216 1191 }
1217   - $layerorigem->close();
1218 1192 $layeroverlay->set("tolerance",0);
1219 1193 $layerdestino->set("tolerance",0);
1220   -
1221   - //if($layeroverlay->getProjection() == "" )
1222   - //{$layeroverlay->setProjection("init=epsg:4291");}
1223   - //if($layerdestino->getProjection() == "" )
1224   - //{$layerdestino->setProjection("init=epsg:4291");}
1225   -
1226 1194 $layeroverlay->queryByrect($this->mapa->extent);
1227 1195 $layerdestino->queryByFeatures($layeroverlay->index);
1228 1196  
... ... @@ -1266,13 +1234,19 @@ function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorig
1266 1234 $db=dbase_open($dbname,2);
1267 1235 foreach ($shapesorigem as $sorigem)
1268 1236 {
1269   - $valororigem = $sorigem->values[$itemorigem];
  1237 + if($itemorigem != "")
  1238 + {$valororigem = $sorigem->values[$itemorigem];}
  1239 + else
  1240 + {$valororigem = "";}
1270 1241 foreach ($shapesdestino as $sdestino)
1271 1242 {
1272 1243 $linha = ms_newLineObj();
1273 1244 $linha->add($sorigem->getCentroid());
1274 1245 $linha->add($sdestino->getCentroid());
1275   - $valordestino = $sdestino->values[$itemdestino];
  1246 + if($itemdestino != "")
  1247 + {$valordestino = $sdestino->values[$itemdestino];}
  1248 + else
  1249 + {$valordestino = "";}
1276 1250 $ShapeObj = ms_newShapeObj(MS_SHAPE_LINE);
1277 1251 $ShapeObj->add($linha);
1278 1252 $novoshpf->addShape($ShapeObj);
... ... @@ -1283,8 +1257,6 @@ function distanciaptpt($temaorigem,$temadestino,$temaoverlay,$locaplic,$itemorig
1283 1257 xbase_add_record($db,$registro);
1284 1258 else
1285 1259 dbase_add_record($db,$registro);
1286   - $linha->free();
1287   - $ShapeObj->free();
1288 1260 }
1289 1261 }
1290 1262 $novoshpf->free();
... ... @@ -1344,28 +1316,10 @@ nome do layer criado com o buffer.
1344 1316 }
1345 1317 $nomebuffer = nomeRandomico();
1346 1318 $nomeshp = $this->diretorio."/".$nomebuffer;
  1319 +
1347 1320 $listaShapes = array();
1348 1321 if($this->nome != ""){
1349   - //pega os shapes selecionados
1350   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
1351   - $sopen = $this->layer->open();
1352   - if($sopen == MS_FAILURE){return "erro";}
1353   -
1354   - $this->layer->open();
1355   - $res_count = $this->layer->getNumresults();
1356   - $buffers = array();
1357   - //pega um shape especifico
1358   - for ($i = 0; $i < $res_count; ++$i)
1359   - {
1360   - if($this->v == 6)
1361   - {$listaShapes[] = $this->layer->getShape($this->layer->getResult($i));}
1362   - else{
1363   - $result = $this->layer->getResult($i);
1364   - $shp_index = $result->shapeindex;
1365   - $listaShapes[] = $this->layer->getfeature($shp_index,-1);
1366   - }
1367   - }
1368   - $fechou = $this->layer->close();
  1322 + $listaShapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
1369 1323 }
1370 1324 else{
1371 1325 $s = ms_shapeObjFromWkt($wkt);
... ... @@ -1436,7 +1390,7 @@ nome do layer criado com o buffer.
1436 1390 else
1437 1391 dbase_close($db);
1438 1392 //adiciona no mapa atual o novo tema
1439   - $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,("Buffer (".$nomebuffer.")"),$metaClasse="SIM");
  1393 + $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,("Buffer (".$nomebuffer.")"),$metaClasse="SIM",false);
1440 1394 $novolayer->set("data",$nomeshp.".shp");
1441 1395 $novolayer->setmetadata("DOWNLOAD","SIM");
1442 1396 $novolayer->set("template","none.htm");
... ... @@ -1476,33 +1430,21 @@ $item {string} - (opcional) Item q será utilizado para ponderar os valores.
1476 1430 $nomeCentro = nomeRandomico();
1477 1431 $nomeshp = $this->diretorio."/".$nomeCentro;
1478 1432 //pega os shapes selecionados
1479   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
1480   - if($this->layer->getNumresults() == 0)
1481   - {$this->layer->querybyrect($this->mapa->extent);}
1482   - $sopen = $this->layer->open();
1483   - if($sopen == MS_FAILURE){return "erro";}
1484   - $this->layer->open();
1485   - $res_count = $this->layer->getNumresults();
1486   - $shapes = array();
  1433 + $lshapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
  1434 + if(count($lshapes) == 0){
  1435 + $lshapes = retornaShapesMapext($this->layer,$this->mapa);
  1436 + }
1487 1437 $pondera = 1;
1488 1438 $xs = 0;
1489 1439 $ys = 0;
1490   - for ($i = 0; $i < $res_count; ++$i)
1491   - {
1492   - if($this->v == 6)
1493   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
1494   - else{
1495   - $result = $this->layer->getResult($i);
1496   - $shp_index = $result->shapeindex;
1497   - $shape = $this->layer->getfeature($shp_index,-1);
1498   - }
  1440 + foreach($lshapes as $shape){
1499 1441 if($item != "")
1500 1442 {$pondera = $shape->values[$item];}
1501 1443 $pt = $shape->line(0)->point(0);
1502 1444 $xs += ($pt->x * $pondera);
1503 1445 $ys += ($pt->y * $pondera);
  1446 +
1504 1447 }
1505   - $fechou = $this->layer->close();
1506 1448 //gera o novo arquivo shape file
1507 1449 // cria o shapefile
1508 1450 $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POINT);
... ... @@ -1573,32 +1515,14 @@ $locaplic - Localização do I3geo.
1573 1515 }
1574 1516 $nomeCentroides = nomeRandomico();
1575 1517 $nomeshp = $this->diretorio."/".$nomeCentroides;
1576   - //pega os shapes selecionados
1577   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
1578   - $sopen = $this->layer->open();
1579   - if($sopen == MS_FAILURE){return "erro";}
1580   - $this->layer->open();
1581   - $res_count = $this->layer->getNumresults();
1582   - $centroides = array();
1583   - $shapes = array();
1584   - //pega um shape especifico
1585   - for ($i = 0; $i < $res_count; ++$i)
1586   - {
1587   - if($this->v == 6)
1588   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
1589   - else{
1590   - $result = $this->layer->getResult($i);
1591   - $shp_index = $result->shapeindex;
1592   - $shape = $this->layer->getfeature($shp_index,-1);
1593   - }
  1518 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
  1519 + foreach($shapes as $shape){
1594 1520 $LineObj = ms_newLineObj();
1595 1521 $LineObj->add($shape->getCentroid());
1596 1522 $ShapeObj = ms_newShapeObj(MS_SHAPE_POINT);
1597 1523 $ShapeObj->add($LineObj);
1598   - $centroides[] = $ShapeObj;
1599   - $shapes[] = $shape;
  1524 + $centroides[] = $ShapeObj;
1600 1525 }
1601   - $fechou = $this->layer->close();
1602 1526 //gera o novo arquivo shape file
1603 1527 // cria o shapefile
1604 1528 $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POINT);
... ... @@ -2110,6 +2034,7 @@ $locaplic - Localização do I3geo
2110 2034 */
2111 2035 function nptPol($temaPt,$temaPo,$locaplic)
2112 2036 {
  2037 + //error_reporting(E_ALL);
2113 2038 set_time_limit(180);
2114 2039 //para manipular dbf
2115 2040 if($this->dbaseExiste == false){
... ... @@ -2137,38 +2062,19 @@ $locaplic - Localização do I3geo
2137 2062 {$db = xbase_create($nomeshp.".dbf", $def);xbase_close($db);}
2138 2063 else
2139 2064 {$db = dbase_create($nomeshp.".dbf", $def);dbase_close($db);}
2140   -
2141   - //if($layerPo->getProjection() == "" )
2142   - //{$layerPo->setProjection("init=epsg:4291");}
2143   - //if($layerPt->getProjection() == "" )
2144   - //{$layerPt->setProjection("init=epsg:4291");}
2145   -
2146 2065 //acrescenta os pontos no novo shapefile
2147 2066 $dbname = $nomeshp.".dbf";
2148 2067 if($this->dbaseExiste == false)
2149 2068 $db=xbase_open($dbname,2);
2150 2069 else
2151   - $db=dbase_open($dbname,2);
2152   - $sopen = $layerPo->open();
2153   - if($sopen == MS_FAILURE){return "erro";}
2154   -
2155   - $layerPo->querybyrect($this->mapa->extent);
2156   - $sopen = $layerPo->open();
2157   - $res_count = $layerPo->getNumresults();
2158   - for ($i = 0; $i < $res_count; ++$i)
  2070 + $db=dbase_open($dbname,2);
  2071 + $shapes = retornaShapesMapext($layerPo,$this->mapa);
  2072 + foreach($shapes as $shape)
2159 2073 {
2160   - if($this->v == 6)
2161   - {$shape = $layerPo->getShape($layerPo->getResult($i));}
2162   - else{
2163   - $result = $layerPo->getResult($i);
2164   - $shp_index = $result->shapeindex;
2165   - $shape = $layerPo->getfeature($shp_index,-1);
2166   - }
2167 2074 $novoreg = array();
2168 2075 foreach($itenspo as $ipo)
2169 2076 {$novoreg[] = $shape->values[$ipo];}
2170 2077 $layerPt->querybyshape($shape);
2171   - //echo $layerPt->getNumresults();
2172 2078 $novoreg[] = $layerPt->getNumresults();
2173 2079 $novoshpf->addShape($shape);
2174 2080 if($this->dbaseExiste == false)
... ... @@ -2176,14 +2082,13 @@ $locaplic - Localização do I3geo
2176 2082 else
2177 2083 dbase_add_record($db,$novoreg);
2178 2084 }
2179   - $fechou = $layerPo->close();
2180 2085 $novoshpf->free();
2181 2086 if($this->dbaseExiste == false)
2182 2087 xbase_close($db);
2183 2088 else
2184 2089 dbase_close($db);
2185 2090 //adiciona o novo tema no mapa
2186   - $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,"N pontos",$metaClasse="SIM");
  2091 + $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,"N pontos",$metaClasse="SIM",false);
2187 2092 $novolayer->set("data",$nomeshp.".shp");
2188 2093 $novolayer->setmetadata("DOWNLOAD","SIM");
2189 2094 $novolayer->setmetadata("TEMALOCAL","SIM");
... ... @@ -2211,47 +2116,23 @@ Salva o mapa acrescentando um novo layer com o resultado.
2211 2116 else
2212 2117 include_once "../pacotes/phpxbase/api_conversion.php";
2213 2118 }
2214   - //define o nome do novo shapefile que será criado
2215   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
2216   - $sopen = $this->layer->open();
2217   - if($sopen == MS_FAILURE){return "erro";}
2218   - $res_count = $this->layer->getNumresults();
2219   - //
2220   - //pega os indices dos poligonos por classe de atributo
2221   - //
  2119 + $shapes =retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
2222 2120 $indices = array();
2223   - for ($i = 0; $i < $res_count; ++$i)
2224   - {
2225   - if($this->v == 6){
2226   - $shape = $this->layer->getShape($this->layer->getResult($i));
2227   - $shp_index = $shape->index;
2228   - }
2229   - else{
2230   - $result = $this->layer->getResult($i);
2231   - $shp_index = $result->shapeindex;
2232   - $shape = $this->layer->getfeature($shp_index,-1);
2233   - }
  2121 + foreach($shapes as $shape){
2234 2122 if($item != "")
2235   - $valor = $shape->values[$item];
  2123 + {$valor = $shape->values[$item];}
2236 2124 else
2237   - $valor = "nenhum";
2238   - if(!isset($indices[$valor]))
2239   - {
2240   - $indices[$valor] = array($shp_index);
  2125 + {$valor = "nenhum";}
  2126 + if(!isset($indices[$valor])){
  2127 + $indices[$valor] = array($shape);
2241 2128 }
2242 2129 else
2243   - $indices[$valor] = array_merge($indices[$valor],array($shp_index));
  2130 + $indices[$valor] = array_merge($indices[$valor],array($shape));
2244 2131 }
2245   -
2246 2132 $dissolve=array();
2247   - foreach($indices as $i)
  2133 + foreach($indices as $shapes)
2248 2134 {
2249   - foreach ($i as $indice)
2250   - {
2251   - if($this->v == 6)
2252   - {$shape = $this->layer->getShape($this->layer->getResult($indice));}
2253   - else
2254   - {$shape = $this->layer->getfeature($indice,-1);}
  2135 + foreach($shapes as $shape){
2255 2136 if($item != "")
2256 2137 $valor = $shape->values[$item];
2257 2138 else
... ... @@ -2260,7 +2141,7 @@ Salva o mapa acrescentando um novo layer com o resultado.
2260 2141 {$dissolve[$valor] = $shape;}
2261 2142 else
2262 2143 {
2263   - $tipo = $shape1->type;
  2144 + $tipo = $shape->type;
2264 2145 if($tipo==2)
2265 2146 {
2266 2147 for($l=0;$l<($shape->numlines);$l++)
... ... @@ -2278,7 +2159,6 @@ Salva o mapa acrescentando um novo layer com o resultado.
2278 2159 }
2279 2160 }
2280 2161 }
2281   - $this->layer->close();
2282 2162 //
2283 2163 //cria o novo shapefile
2284 2164 //
... ... @@ -2317,13 +2197,10 @@ Salva o mapa acrescentando um novo layer com o resultado.
2317 2197 //adiciona o novo layer no mapa
2318 2198 //
2319 2199 $n = pegaNome($this->layer);
2320   - $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,("Agrupamento de ".$n),$metaClasse="SIM");
  2200 + $novolayer = criaLayer($this->mapa,MS_LAYER_POLYGON,MS_DEFAULT,("Agrupamento de ".$n),$metaClasse="SIM",false);
2321 2201 $novolayer->set("data",$nomeshp.".shp");
2322 2202 $novolayer->setmetadata("DOWNLOAD","SIM");
2323 2203 $novolayer->setmetadata("TEMALOCAL","SIM");
2324   - if (file_exists($this->qyfile))
2325   - {unlink ($this->qyfile);}
2326   -
2327 2204 return("ok");
2328 2205 }
2329 2206  
... ... @@ -2350,48 +2227,23 @@ $locaplic - Localização do I3geo
2350 2227 else
2351 2228 include_once "../pacotes/phpxbase/api_conversion.php";
2352 2229 }
2353   - //define o nome do novo shapefile que será criado
2354   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
2355   - $sopen = $this->layer->open();
2356   - if($sopen == MS_FAILURE){return "erro";}
2357   - $res_count = $this->layer->getNumresults();
2358   - //
2359   - //pega os indices dos poligonos por classe de atributo
2360   - //
  2230 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
2361 2231 $indices = array();
2362   - for ($i = 0; $i < $res_count; ++$i)
2363   - {
2364   - if($this->v == 6)
2365   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
2366   - else{
2367   - $result = $this->layer->getResult($i);
2368   - $shp_index = $result->shapeindex;
2369   - $shape = $this->layer->getfeature($shp_index,-1);
2370   - }
  2232 + foreach($shapes as $shape){
2371 2233 if($item != "")
2372   - $valor = $shape->values[$item];
  2234 + {$valor = $shape->values[$item];}
2373 2235 else
2374   - $valor = "nenhum";
2375   - if(!isset($indices[$valor]))
2376   - {
2377   - $indices[$valor] = array($i);
  2236 + {$valor = "nenhum";}
  2237 + if(!isset($indices[$valor])){
  2238 + $indices[$valor] = array($shape);
2378 2239 }
2379 2240 else
2380   - $indices[$valor] = array_merge($indices[$valor],array($i));
  2241 + $indices[$valor] = array_merge($indices[$valor],array($shape));
2381 2242 }
2382   - //var_dump($indices);
2383   - //
2384   - //faz o dissolve dos poligonos
2385   - //
2386 2243 $dissolve=array();
2387   - foreach($indices as $i)
  2244 + foreach($indices as $shapes)
2388 2245 {
2389   - foreach ($i as $indice)
2390   - {
2391   - if($this->v == 6)
2392   - {$shape = $this->layer->getShape($this->layer->getResult($indice));}
2393   - else
2394   - {$shape = $this->layer->getfeature($indice,-1);}
  2246 + foreach($shapes as $shape){
2395 2247 if($item != "")
2396 2248 $valor = $shape->values[$item];
2397 2249 else
... ... @@ -2400,11 +2252,23 @@ $locaplic - Localização do I3geo
2400 2252 {$dissolve[$valor] = $shape;}
2401 2253 else
2402 2254 {
2403   - $dissolve[$valor] = $shape->union($dissolve[$valor]);
  2255 + if($shape->type != MS_SHAPE_POLYGON)
  2256 + {
  2257 + for($l=0;$l<($shape->numlines);$l++)
  2258 + {
  2259 + $shape1 = $dissolve[$valor];
  2260 + $linha = $shape->line($l);
  2261 + $shape1->add($linha);
  2262 + }
  2263 + $dissolve[$valor] = $shape1;
  2264 + }
  2265 + else
  2266 + {
  2267 + $dissolve[$valor] = $shape->union($dissolve[$valor]);
  2268 + }
2404 2269 }
2405 2270 }
2406 2271 }
2407   - $this->layer->close();
2408 2272 //
2409 2273 //cria o novo shapefile
2410 2274 //
... ... @@ -2476,7 +2340,6 @@ $locaplic - Localização do I3geo
2476 2340 $this->incmapageometrias($dir_tmp,$imgdir,$geometrias,$tipoLista="arraywkt");
2477 2341 return "ok";
2478 2342 }
2479   -
2480 2343 $geos = array();
2481 2344 foreach ($geometrias as $geo){
2482 2345 $geos[] = ms_shapeObjFromWkt($geo);
... ... @@ -2775,35 +2638,18 @@ function gravaCoordenadasPt($tema,$limitepontos=&quot;TRUE&quot;,$extendelimite)
2775 2638 $nomefinal = nomeRandomico();
2776 2639 $nomearq = $this->diretorio."/".$nomefinal;
2777 2640 $itemspt = pegaItens($layerPt);
2778   - $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
2779   - if ($existesel == "nao")
2780   - {
2781   - //if($layerPt->getProjection() == "" )
2782   - //{$layerPt->setProjection("init=epsg:4291");}
2783   - $layerPt->queryByrect($this->mapa->extent);
  2641 + $shapes = retornaShapesSelecionados($layerPt,$this->arquivo,$this->mapa);
  2642 + if(count($shapes) == 0){
  2643 + $shapes = retornaShapesMapext($layerPt,$this->mapa);
2784 2644 }
2785   - $res_count = $layerPt->getNumresults();
2786 2645 $pontos = array();
2787   - //pega um shape especifico
2788   - $sopen = $layerPt->open();
2789   - if($sopen == MS_FAILURE){return "erro";}
2790   -
2791 2646 if (($prjTema != "") && ($prjMapa != $prjTema))
2792 2647 {
2793 2648 $projInObj = ms_newprojectionobj($prjTema);
2794 2649 $projOutObj = ms_newprojectionobj($prjMapa);
2795 2650 }
2796   - for ($i = 0; $i < $res_count; ++$i)
  2651 + foreach($shapes as $shape)
2797 2652 {
2798   - if($this->v == 6)
2799   - {$shape = $layerPt->getShape($layerPt->getResult($i));}
2800   - else{
2801   - $result = $layerPt->getResult($i);
2802   - $shp_index = $result->shapeindex;
2803   - $shape = $layerPt->getfeature($shp_index,-1);
2804   - }
2805   - //$lineo = $shape->line(0);
2806   - //$pt = $lineo->point(0);
2807 2653 $pt = $shape->getCentroid();
2808 2654 if (($prjTema != "") && ($prjMapa != $prjTema))
2809 2655 {
... ... @@ -2853,7 +2699,7 @@ function gravaCoordenadasPt($tema,$limitepontos=&quot;TRUE&quot;,$extendelimite)
2853 2699 $dimx = "c(".$xi.",".$xf.")";
2854 2700 $dimy = "c(".$yi.",".$yf.")";
2855 2701 return array("dimx"=>$dimx,"dimy"=>$dimy,"arqx"=>($nomearq."x"),"arqy"=>($nomearq."y"),"prefixoarquivo"=>$nomearq);
2856   -}
  2702 +}
2857 2703 /*
2858 2704 function unserializeGeo
2859 2705  
... ...
classesphp/classe_atributos.php
... ... @@ -269,23 +269,15 @@ $tipo - Tipo de busca brasil|null
269 269 $this->layer->setfilter("");
270 270 //le o arquivo de query se existir e checa se existe seleção para o tema
271 271 $items = pegaItens($this->layer);
272   - $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
273   - if ($existesel == "nao")
274   - {$this->layer->querybyrect($this->mapa->extent);}
275   - $sopen = $this->layer->open();
276   - if($sopen == MS_FAILURE){return "erro";}
  272 +
  273 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
  274 + if(count($shapes) == 0){
  275 + $shapes = retornaShapesMapext($this->layer,$this->mapa);
  276 + }
277 277 $registros[] = array();
278   - $res_count = $this->layer->getNumresults();
279   - for ($i = 0; $i < $res_count; ++$i)
  278 + foreach($shapes as $shape)
280 279 {
281 280 $valitem = array();
282   - if($this->v == 6)
283   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
284   - else{
285   - $result = $this->layer->getResult($i);
286   - $shp_index = $result->shapeindex;
287   - $shape = $this->layer->getfeature($shp_index,-1);
288   - }
289 281 foreach ($items as $item)
290 282 {
291 283 $v = trim($shape->values[$item]);
... ... @@ -338,11 +330,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona
338 330 else
339 331 {$items[] = $itemtema;}
340 332 $resultadoFinal[] = array("itens"=>$items);
341   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
342   - $indxlayer = $this->layer->index;
343   - $sopen = $this->layer->open();
344   - if($sopen == MS_FAILURE){return "erro";}
345   - $res_count = $this->layer->getNumresults();
  333 + $shapes = retornaShapesSelecionados($layerPt,$this->arquivo,$this->mapa);
  334 + $res_count = count($shapes);
346 335 $registros = array();
347 336 //lista apenas os selecionados
348 337 if ($tipolista == "selecionados")
... ... @@ -356,15 +345,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona
356 345 for ($i = $inicio; $i < $res_count; ++$i)
357 346 {
358 347 $valitem = array();
359   - if($this->v == 6){
360   - $shape = $this->layer->getShape($this->layer->getResult($i));
361   - $indx = $shape->index;
362   - }
363   - else{
364   - $result = $this->layer->getResult($i);
365   - $indx = $result->shapeindex;
366   - $shape = $this->layer->getfeature($indx,-1);
367   - }
  348 + $shape = $shapes[$i];
368 349 foreach ($items as $item)
369 350 {
370 351 $valori = trim($shape->values[$item]);
... ... @@ -381,10 +362,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona
381 362 $shp_atual = array();
382 363 for ($i = 0; $i < $res_count;++$i)
383 364 {
384   - $rc = $this->layer->getResult($i);
385   - $shp_atual[$rc->shapeindex] = $rc->shapeindex;
  365 + $shp_atual[$i] = $shapes[$i];;
386 366 }
387   - $this->layer->close();
388 367 $chk = "";
389 368 if (@$this->layer->queryByrect($this->mapa->extent) == MS_SUCCESS)
390 369 {
... ... @@ -551,22 +530,13 @@ Include:
551 530 $filtro = $this->layer->getfilterstring();
552 531 if ($filtro != ""){$this->layer->setfilter("");}
553 532 //le o arquivo de query se existir e checa se existe sele&ccedil;&atilde;o para o tema
554   - $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
555   - if ($existesel == "nao")
556   - {$this->layer->queryByrect($this->mapa->extent);}
557   - $sopen = $this->layer->open();
558   - if($sopen == MS_FAILURE){return "erro";}
559   - $res_count = $this->layer->getNumresults();
  533 + $shapes = retornaShapesSelecionados($layerPt,$this->arquivo,$this->mapa);
  534 + if(count($shapes) == 0){
  535 + $shapes = retornaShapesMapext($layerPt,$this->mapa);
  536 + }
560 537 //pega os valores
561   - for ($i = 0; $i < $res_count; ++$i)
  538 + foreach($shapes as $shape)
562 539 {
563   - if($this->v == 6)
564   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
565   - else{
566   - $result = $this->layer->getResult($i);
567   - $shp_index = $result->shapeindex;
568   - $shape = $this->layer->getfeature($shp_index,-1);
569   - }
570 540 $v = $shape->values[$item];
571 541 $valores[] = $v;
572 542 }
... ...
classesphp/classe_shp.php
... ... @@ -388,20 +388,10 @@ array - xy
388 388 if(!$this->layer){return "erro";}
389 389 $this->layer->set("template","none.htm");
390 390 $this->layer->setfilter("");
391   - $existesel = carregaquery2($this->arquivo,$this->layer,$this->mapa);
392   - $sopen = $this->layer->open();
393   - if($sopen == MS_FAILURE){return "erro";}
394   - $res_count = $this->layer->getNumresults();
  391 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
395 392 $xy = array();
396   - for ($i = 0; $i < $res_count; ++$i)
  393 + foreach($shapes as $shape)
397 394 {
398   - if($this->v == 6)
399   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
400   - else{
401   - $result = $this->layer->getResult($i);
402   - $shp_index = $result->shapeindex;
403   - $shape = $this->layer->getfeature($shp_index,-1);
404   - }
405 395 $nlinhas = $shape->numlines;
406 396 for($j = 0;$j < $nlinhas; ++$j){
407 397 $lin = $shape->line($j);
... ...
classesphp/classe_temas.php
... ... @@ -796,26 +796,14 @@ $nome - nome que será dado a geometria
796 796 $this->mapa->setsize(30,30);
797 797 $ext = $this->mapa->extent;
798 798 $sb = $this->mapa->scalebar;
799   - $sb->set("status",MS_OFF);
800   -
  799 + $sb->set("status",MS_OFF);
801 800 $items = pegaItens($this->layer);
802   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
803   - $sopen = $this->layer->open();
804   - if($sopen == MS_FAILURE){return "erro";}
805   -
806   - $res_count = $this->layer->getNumresults();
807 801 $final["layer"] = pegaNome($this->layer);
  802 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
808 803 $registros = array();
809   - for ($i = 0; $i < $res_count; ++$i)
  804 + foreach($shapes as $shape)
810 805 {
811 806 $valitem = array();
812   - if($this->v == 6)
813   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
814   - else{
815   - $result = $this->layer->getResult($i);
816   - $shp_index = $result->shapeindex;
817   - $shape = $this->layer->getfeature($shp_index,-1);
818   - }
819 807 foreach ($items as $item)
820 808 {
821 809 $v = trim($shape->values[$item]);
... ... @@ -1030,52 +1018,31 @@ Calcula a extensão geográfica dos elementos selecionados de um tema e ajusta o m
1030 1018 $extatual = $this->mapa->extent;
1031 1019 $prjMapa = $this->mapa->getProjection();
1032 1020 $prjTema = $this->layer->getProjection();
1033   - carregaquery2($this->arquivo,$this->layer,$this->mapa);
1034   - $sopen = $this->layer->open();
1035   - if($sopen == MS_FAILURE){return "erro";}
1036   - $res_count = $this->layer->getNumresults();
1037   - if($res_count > 0)
  1021 + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa);
  1022 + $xmin = array();
  1023 + $xmax = array();
  1024 + $ymin = array();
  1025 + $ymax = array();
  1026 + foreach($shapes as $shape)
1038 1027 {
1039   - $versao = versao();
1040   - if($versao["principal"] == 6){
1041   - $ret = $this->layer->getResultsBounds();
1042   - }
1043   - else{
1044   - $xmin = array();
1045   - $xmax = array();
1046   - $ymin = array();
1047   - $ymax = array();
1048   - for ($i = 0; $i < $res_count; ++$i)
1049   - {
1050   - $valitem = array();
1051   - if($this->v == 6)
1052   - {$shape = $this->layer->getShape($this->layer->getResult($i));}
1053   - else{
1054   - $result = $this->layer->getResult($i);
1055   - $shp_index = $result->shapeindex;
1056   - $shape = $this->layer->getfeature($shp_index,-1);
1057   - }
1058   - $bound = $shape->bounds;
1059   - $xmin[] = $bound->minx;
1060   - $xmax[] = $bound->maxx;
1061   - $ymin[] = $bound->miny;
1062   - $ymax[] = $bound->maxy;
1063   - }
1064   - $ret = ms_newRectObj();
1065   - $ret->set("minx",min($xmin));
1066   - $ret->set("miny",min($ymin));
1067   - $ret->set("maxx",max($xmax));
1068   - $ret->set("maxy",max($ymax));
1069   - }
1070   - $this->layer->close();
1071   - if (($prjTema != "") && ($prjMapa != $prjTema))
1072   - {
1073   - $projInObj = ms_newprojectionobj($prjTema);
1074   - $projOutObj = ms_newprojectionobj($prjMapa);
1075   - $ret->project($projInObj, $projOutObj);
1076   - }
1077   - $extatual->setextent($ret->minx,$ret->miny,$ret->maxx,$ret->maxy);
  1028 + $bound = $shape->bounds;
  1029 + $xmin[] = $bound->minx;
  1030 + $xmax[] = $bound->maxx;
  1031 + $ymin[] = $bound->miny;
  1032 + $ymax[] = $bound->maxy;
  1033 + }
  1034 + $ret = ms_newRectObj();
  1035 + $ret->set("minx",min($xmin));
  1036 + $ret->set("miny",min($ymin));
  1037 + $ret->set("maxx",max($xmax));
  1038 + $ret->set("maxy",max($ymax));
  1039 + if (($prjTema != "") && ($prjMapa != $prjTema))
  1040 + {
  1041 + $projInObj = ms_newprojectionobj($prjTema);
  1042 + $projOutObj = ms_newprojectionobj($prjMapa);
  1043 + $ret->project($projInObj, $projOutObj);
1078 1044 }
  1045 + $extatual->setextent($ret->minx,$ret->miny,$ret->maxx,$ret->maxy);
1079 1046 if($this->mapa->getmetadata("interface") == "googlemaps")
1080 1047 {$this->mapa->setProjection($projO);}
1081 1048 return("ok");
... ...
classesphp/funcoes_gerais.php
... ... @@ -1747,11 +1747,13 @@ $metaTema {string} - nome do tema que será incluído no metadata TEMA
1747 1747  
1748 1748 $metaClasse {string} - SIM|NAO indica se a classe é visível ou não na legenda
1749 1749  
  1750 +$reposiciona {boolean} - reordena ou não o novo layer
  1751 +
1750 1752 Retorno:
1751 1753  
1752 1754 {layer}
1753 1755 */
1754   -function criaLayer($oMapa,$ms_tipo,$ms_status,$metaTema,$metaClasse="SIM")
  1756 +function criaLayer($oMapa,$ms_tipo,$ms_status,$metaTema,$metaClasse="SIM",$reposiciona=true)
1755 1757 {
1756 1758 $l = ms_newLayerObj($oMapa);
1757 1759 $l->set("type",$ms_tipo);
... ... @@ -1773,23 +1775,25 @@ function criaLayer($oMapa,$ms_tipo,$ms_status,$metaTema,$metaClasse=&quot;SIM&quot;)
1773 1775 $estilo->set("symbolname","ponto");
1774 1776 }
1775 1777 //reposiciona o layer na pilha
1776   - $ltipo = $l->type;
1777   - if (($ltipo == 2) || ($ltipo == 3))
1778   - {
1779   - $indicel = $l->index;
1780   - $numlayers = $oMapa->numlayers;
1781   - $nummove = 0;
1782   - for ($i = $numlayers-1;$i > 0;$i--)
  1778 + if($reposiciona == true){
  1779 + $ltipo = $l->type;
  1780 + if (($ltipo == 2) || ($ltipo == 3))
1783 1781 {
1784   - $layerAbaixo = $oMapa->getlayer($i);
1785   - $tipo = $layerAbaixo->type;
1786   - if (($tipo != 2) && ($tipo != 3))
1787   - {$nummove++;}
1788   - }
1789   - if ($nummove > 2)
1790   - {
1791   - for ($i=0;$i<=($nummove - 3);++$i)
1792   - {$oMapa->movelayerup($indicel);}
  1782 + $indicel = $l->index;
  1783 + $numlayers = $oMapa->numlayers;
  1784 + $nummove = 0;
  1785 + for ($i = $numlayers-1;$i > 0;$i--)
  1786 + {
  1787 + $layerAbaixo = $oMapa->getlayer($i);
  1788 + $tipo = $layerAbaixo->type;
  1789 + if (($tipo != 2) && ($tipo != 3))
  1790 + {$nummove++;}
  1791 + }
  1792 + if ($nummove > 2)
  1793 + {
  1794 + for ($i=0;$i<=($nummove - 3);++$i)
  1795 + {$oMapa->movelayerup($indicel);}
  1796 + }
1793 1797 }
1794 1798 }
1795 1799 return $l;
... ... @@ -2776,6 +2780,21 @@ function carregaquery($mapfile,$objlayer,$objmapa)
2776 2780 }
2777 2781 return "nao";
2778 2782 }
  2783 +/*
  2784 +Function: carregaquery2
  2785 +
  2786 +Le um arquivo PHP, serializado com a lista de índices de objetos SHAPE selecionados em um LAYER, e aplica ao LAYER a seleção desses SHAPES usando querybyindex
  2787 +
  2788 +Atenção: na versão 6 do Mapserver, não funciona com layers do tipo Postgis
  2789 +
  2790 +Parametros:
  2791 +
  2792 +$mapfile
  2793 +
  2794 +$objlayer
  2795 +
  2796 +$objmapa
  2797 +*/
2779 2798 function carregaquery2($mapfile,&$objlayer,&$objmapa)
2780 2799 {
2781 2800 $qyfile = dirname($mapfile)."/".$objlayer->name.".php";
... ... @@ -2823,4 +2842,64 @@ function verificaEditores($editores)
2823 2842 }
2824 2843 return $editor;
2825 2844 }
  2845 +function retornaShapesMapext($objLayer,$objMapa){
  2846 + $shapes = array();
  2847 + $status = $objLayer->open();
  2848 + $status = $objLayer->whichShapes($objMapa->extent);
  2849 + while ($shape = $objLayer->nextShape())
  2850 + {$shapes[] = $shape;}
  2851 + $objLayer->close();
  2852 + return $shapes;
  2853 +}
  2854 +function retornaShapesSelecionados($objLayer,$map_file,$objMapa){
  2855 + $shapes = array();
  2856 + $qyfile = dirname($map_file)."/".$objLayer->name.".php";
  2857 + $handle = fopen ($qyfile, "r");
  2858 + $conteudo = fread ($handle, filesize ($qyfile));
  2859 + fclose ($handle);
  2860 + $listaDeIndices = unserialize($conteudo);
  2861 + if(count($listaDeIndices) == 0)
  2862 + {return $shapes;}
  2863 + if ($objLayer->connectiontype != MS_POSTGIS){
  2864 + //pega os shapes selecionados
  2865 + carregaquery2($map_file,$objLayer,$objMapa);
  2866 + $sopen = $objLayer->open();
  2867 + if($sopen == MS_FAILURE){return "erro";}
  2868 + $objLayer->open();
  2869 + $res_count = $objLayer->getNumresults();
  2870 + $centroides = array();
  2871 + $shapes = array();
  2872 + //pega um shape especifico
  2873 + for ($i = 0; $i < $res_count; ++$i)
  2874 + {
  2875 + if($this->v == 6)
  2876 + {$shape = $objLayer->getShape($objLayer->getResult($i));}
  2877 + else{
  2878 + $result = $objLayer->getResult($i);
  2879 + $shp_index = $result->shapeindex;
  2880 + $shape = $objLayer->getfeature($shp_index,-1);
  2881 + }
  2882 + $shapes[] = $shape;
  2883 + }
  2884 + $fechou = $objLayer->close();
  2885 + }
  2886 + else{
  2887 + $rect = ms_newRectObj();
  2888 + $rect->set("minx",-180);
  2889 + $rect->set("miny",-90);
  2890 + $rect->set("maxx",180);
  2891 + $rect->set("maxy",90);
  2892 + $status = $objLayer->open();
  2893 + $status = $objLayer->whichShapes($rect);
  2894 + while ($shape = $objLayer->nextShape())
  2895 + {
  2896 + if(in_array($shape->index,$listaDeIndices)){
  2897 + $shapes[] = $shape;
  2898 + }
  2899 + }
  2900 + $objLayer->close();
  2901 + }
  2902 + return $shapes;
  2903 +}
  2904 +
2826 2905 ?>
2827 2906 \ No newline at end of file
... ...