Commit 8cee961ecdab8c42e718865a2766a32bf7dccee3
1 parent
d0550acb
Exists in
master
and in
7 other branches
--no commit message
Showing
2 changed files
with
51 additions
and
15 deletions
Show diff stats
classesphp/classe_analise.php
... | ... | @@ -108,6 +108,46 @@ $ext - Extensão geográfica do mapa |
108 | 108 | } |
109 | 109 | } |
110 | 110 | /* |
111 | +Method: criaDefDb | |
112 | + | |
113 | +Cria um array contendo as definições das colunas que serão criadas em uma tabela DBF conforme as exigências de arquivos dbf | |
114 | + | |
115 | +parameters: | |
116 | + | |
117 | +$itens - array com os nomes originais das colunas | |
118 | + | |
119 | +return: | |
120 | +{array} | |
121 | +*/ | |
122 | + function criaDefDb($itens){ | |
123 | + $c = 0; | |
124 | + $def = array(); | |
125 | + foreach ($items as $ni){ | |
126 | + $ni = strtoupper($ni); | |
127 | + $def[] = array(substr($ni, 0, 8).$c,"C","254"); | |
128 | + $c = $c + 1; | |
129 | + } | |
130 | + return $def; | |
131 | + } | |
132 | +/* | |
133 | +Method: truncaS | |
134 | + | |
135 | +Trunca o comprimento de uma string em 255 caracteres | |
136 | + | |
137 | +parameters: | |
138 | + | |
139 | +$s - string | |
140 | + | |
141 | +return | |
142 | +{string} | |
143 | +*/ | |
144 | + function truncaS($s){ | |
145 | + if(strlen($s) > 255){ | |
146 | + $s = substr($s,0,255); | |
147 | + } | |
148 | + return $s; | |
149 | + } | |
150 | +/* | |
111 | 151 | Method: salva |
112 | 152 | |
113 | 153 | Salva o mapfile atual |
... | ... | @@ -979,9 +1019,7 @@ $locaplic - Localização do I3geo. |
979 | 1019 | $layerPt->close(); |
980 | 1020 | //gera o novo arquivo shape file |
981 | 1021 | // cria o dbf |
982 | - $def = array(); | |
983 | - foreach ($itemspt as $ni) | |
984 | - {$def[] = array(substr($ni, 0, 10),"C","254");} | |
1022 | + $def = $this->criaDefDb($itemspt); | |
985 | 1023 | //pega os itens dos temas poligonais |
986 | 1024 | $layersPol = array(); |
987 | 1025 | $temas = explode(",",$temasPo); |
... | ... | @@ -1024,7 +1062,7 @@ $locaplic - Localização do I3geo. |
1024 | 1062 | foreach($spts as $spt) |
1025 | 1063 | { |
1026 | 1064 | foreach ($itemspt as $ni) |
1027 | - {$reg[] = $spt->values[$ni];} | |
1065 | + {$reg[] = $this->truncaS($spt->values[$ni]);} | |
1028 | 1066 | $novoshpf->addShape($spt); |
1029 | 1067 | $lineo = $spt->line(0); |
1030 | 1068 | $pt = $lineo->point(0); |
... | ... | @@ -1047,7 +1085,7 @@ $locaplic - Localização do I3geo. |
1047 | 1085 | |
1048 | 1086 | $shape = $layer->getfeature($shp_index,-1); |
1049 | 1087 | foreach ($itens as $item) |
1050 | - {$reg[] = $shape->values[$item];} | |
1088 | + {$reg[] = $this->truncaS($shape->values[$item]);} | |
1051 | 1089 | } |
1052 | 1090 | else |
1053 | 1091 | { |
... | ... | @@ -1302,10 +1340,8 @@ nome do layer criado com o buffer. |
1302 | 1340 | // cria o shapefile |
1303 | 1341 | $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POLYGON); |
1304 | 1342 | // cria o dbf |
1305 | - $def = array(); | |
1343 | + $def = $this->criaDefDb($items); | |
1306 | 1344 | $def[] = array("i3geo","C","254"); |
1307 | - foreach ($items as $ni) | |
1308 | - {$def[] = array(substr($ni, 0, 10),"C","254");} | |
1309 | 1345 | if(!function_exists(dbase_create)) |
1310 | 1346 | {$db = xbase_create($nomeshp.".dbf", $def);xbase_close($db);} |
1311 | 1347 | else |
... | ... | @@ -1315,9 +1351,9 @@ nome do layer criado com o buffer. |
1315 | 1351 | $db=xbase_open($dbname,2); |
1316 | 1352 | for($i = 0;$i < count($buffers);++$i) |
1317 | 1353 | { |
1318 | - $reg[] = $i; | |
1319 | 1354 | foreach ($items as $ni) |
1320 | - {$reg[] = $shapes[$i]->values[$ni];} | |
1355 | + {$reg[] = $this->truncaS($shapes[$i]->values[$ni]);} | |
1356 | + $reg[] = $i; | |
1321 | 1357 | $novoshpf->addShape($buffers[$i]); |
1322 | 1358 | xbase_add_record($db,$reg); |
1323 | 1359 | $reg = array(); |
... | ... | @@ -1473,9 +1509,7 @@ $locaplic - Localização do I3geo. |
1473 | 1509 | $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POINT); |
1474 | 1510 | $items = pegaItens($this->layer); |
1475 | 1511 | // cria o dbf |
1476 | - $def = array(); | |
1477 | - foreach ($items as $ni) | |
1478 | - {$def[] = array(substr($ni, 0, 10),"C","254");} | |
1512 | + $def = $this->criaDefDb($items); | |
1479 | 1513 | if(!function_exists(dbase_create)) |
1480 | 1514 | {$db = xbase_create($nomeshp.".dbf", $def);xbase_close($db);} |
1481 | 1515 | else |
... | ... | @@ -1486,7 +1520,7 @@ $locaplic - Localização do I3geo. |
1486 | 1520 | for($i = 0;$i < count($centroides);++$i) |
1487 | 1521 | { |
1488 | 1522 | foreach ($items as $ni) |
1489 | - {$reg[] = $shapes[$i]->values[$ni];} | |
1523 | + {$reg[] = $this->truncaS($shapes[$i]->values[$ni]);} | |
1490 | 1524 | $novoshpf->addShape($centroides[$i]); |
1491 | 1525 | xbase_add_record($db,$reg); |
1492 | 1526 | $reg = array(); | ... | ... |
classesphp/funcoes_gerais.php
... | ... | @@ -1854,14 +1854,16 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) |
1854 | 1854 | $items = pegaItens($layer); |
1855 | 1855 | // cria o dbf |
1856 | 1856 | $def = array(); |
1857 | + $cni = 0; | |
1857 | 1858 | foreach ($items as $ni) |
1858 | 1859 | { |
1859 | 1860 | $temp = strtoupper($ni); |
1860 | - $temp = substr($temp,0,9); | |
1861 | + $temp = substr($temp,0,8).$cni; | |
1861 | 1862 | // |
1862 | 1863 | //nao tem como descobrir o tamanho e tipo do campo |
1863 | 1864 | // |
1864 | 1865 | $def[] = array($temp,"C","254"); |
1866 | + $cni = $cni + 1; | |
1865 | 1867 | } |
1866 | 1868 | if(!function_exists("dbase_create")) |
1867 | 1869 | {$db = xbase_create($nomeshp.".dbf", $def);} | ... | ... |