Ejemplo n.º 1
0
function inserePoligonosUrl()
{
    global $tamanhosimbolo, $simbolo, $corsimbolo, $poligonos, $nometemapoligonos, $dir_tmp, $imgdir, $tmpfname, $locaplic;
    include_once "pacotes/phpxbase/api_conversion.php";
    if (!isset($nometemapoligonos)) {
        $nometemapoligonos = "Poligonos";
    }
    if ($nometemapoligonos == "") {
        $nometemapoligonos = "Poligonos";
    }
    //
    //cria o shape file
    //
    $tipol = MS_SHP_POLYGON;
    $nomeshp = $dir_tmp . "/" . $imgdir . "/poligonosins";
    // cria o dbf
    $def = array();
    $items = array("COORD");
    foreach ($items as $ni) {
        $def[] = array($ni, "C", "254");
    }
    if (!function_exists(dbase_create)) {
        xbase_create($nomeshp . ".dbf", $def);
    } else {
        dbase_create($nomeshp . ".dbf", $def);
    }
    $dbname = $nomeshp . ".dbf";
    $db = xbase_open($dbname, 2);
    $novoshpf = ms_newShapefileObj($nomeshp, $tipol);
    $linhas = explode(",", trim($poligonos));
    $pontosLinhas = array();
    //guarda os pontos de cada linha em arrays
    foreach ($linhas as $l) {
        $tempPTs = explode(" ", trim($l));
        $temp = array();
        foreach ($tempPTs as $p) {
            if (is_numeric($p)) {
                $temp[] = $p;
            }
        }
        $pontosLinhas[] = $temp;
    }
    foreach ($pontosLinhas as $ptsl) {
        $linhas = $ptsl;
        $shape = ms_newShapeObj($tipol);
        $linha = ms_newLineObj();
        $reg = array();
        $reg[] = "";
        for ($ci = 0; $ci < count($linhas); $ci = $ci + 2) {
            $linha->addXY($linhas[$ci], $linhas[$ci + 1]);
        }
        $shape->add($linha);
        $novoshpf->addShape($shape);
        xbase_add_record($db, $reg);
    }
    $novoshpf->free();
    xbase_close($db);
    //adiciona o layer
    $mapa = ms_newMapObj($tmpfname);
    $layer = ms_newLayerObj($mapa);
    $layer->set("name", "linhains");
    $layer->set("data", $nomeshp . ".shp");
    $layer->setmetadata("DOWNLOAD", "sim");
    $layer->setmetadata("temalocal", "sim");
    $layer->setmetadata("tema", $nometemapoligonos);
    $layer->setmetadata("classe", "sim");
    $layer->setmetadata("ATLAS", "nao");
    $layer->set("type", MS_LAYER_POLYGON);
    $layer->set("opacity", "50");
    $layer->set("status", MS_DEFAULT);
    $classe = ms_newClassObj($layer);
    $classe->set("name", " ");
    $estilo = ms_newStyleObj($classe);
    $cor = $estilo->color;
    if (!isset($corsimbolo)) {
        $corsimbolo = "255,0,0";
    }
    $corsimbolo = str_replace(" ", ",", $corsimbolo);
    $corsimbolo = explode(",", $corsimbolo);
    $cor->setRGB($corsimbolo[0], $corsimbolo[1], $corsimbolo[2]);
    $salvo = $mapa->save($tmpfname);
    erroCriacao();
}
Ejemplo n.º 2
0
 function adicionaTemaGeoRSS($servico, $dir_tmp, $locaplic, $canal)
 {
     $xml = simplexml_load_file($servico);
     $conta = 0;
     foreach ($xml->channel as $c) {
         if ($conta == $canal) {
             $canal = $c;
         }
     }
     $nos = $canal->item;
     //verifica se o canal faz referencia a elementos externos
     //se sim, usa todos os elementos do xml no lugar do canal
     foreach ($canal->items as $t) {
         foreach ($t->xpath('rdf:Seq') as $x) {
             foreach ($x->xpath('rdf:li') as $z) {
                 $nos = $xml->item;
             }
         }
     }
     $resultado = array();
     $tipog = "";
     foreach ($nos as $item) {
         $env = array();
         //define o tipo
         if ($item->xpath('geo:lat')) {
             $tipog = "geo";
         }
         if ($item->xpath('georss:point')) {
             $tipog = "georsspoint";
         }
         if ($item->xpath('georss:where')) {
             $tipog = "envelope";
         }
         if ($tipog == "envelope") {
             foreach ($item->xpath('georss:where') as $w) {
                 foreach ($w->xpath('gml:Envelope') as $e) {
                     //$lc = $e->xpath('gml:lowerCorner');
                     $lc = (string) $e->children('gml', TRUE)->lowerCorner;
                     //$uc = $e->xpath('gml:upperCorner');
                     $uc = (string) $e->children('gml', TRUE)->upperCorner;
                     $lc = explode(" ", $lc);
                     $uc = explode(" ", $uc);
                     if (is_numeric($lc[0])) {
                         $ymin = $lc[0];
                         $ymax = $uc[0];
                         $xmin = $lc[1];
                         $xmax = $uc[1];
                         if ($ymin != "") {
                             $env = array($xmin, $ymin, $xmax, $ymax);
                         }
                     }
                 }
             }
         }
         if ($tipog == "geo") {
             if ($item->xpath('geo:lon')) {
                 $x = (string) $item->children('geo', TRUE)->lon;
             } else {
                 $x = (string) $item->children('geo', TRUE)->long;
             }
             //$y = $item->xpath('geo:lat');
             $y = (string) $item->children('geo', TRUE)->lat;
             $env = array($y, $x);
         }
         if ($tipog == "georsspoint") {
             //$temp = $item->xpath('georss:point');
             $temp = (string) $item->children('georss', TRUE)->point;
             $env = explode(" ", $temp);
         }
         if (count($env) > 0) {
             $resultado[] = array(ixml($item, "title"), ixml($item, "link"), ixml($item, "description"), ixml($item, "category"), $env);
         }
     }
     //cria o shapefile com os dados
     if (count($resultado) > 0) {
         //para manipular dbf
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
         $diretorio = dirname($this->arquivo);
         $tipol = MS_SHP_POLYGON;
         if ($tipog == "georsspoint") {
             $tipol = MS_SHP_POINT;
         }
         if ($tipog == "geo") {
             $tipol = MS_SHP_POINT;
         }
         $novonomelayer = nomeRandomico(10) . "georss";
         $nomeshp = $diretorio . "/" . $novonomelayer;
         $novoshpf = ms_newShapefileObj($nomeshp, $tipol);
         $def[] = array("TITULO", "C", "254");
         $def[] = array("LINK", "C", "254");
         $def[] = array("DESC", "C", "254");
         $def[] = array("CATEGORIA", "C", "254");
         if (!function_exists(dbase_create)) {
             $db = xbase_create($nomeshp . ".dbf", $def);
             xbase_close($db);
         } else {
             $db = dbase_create($nomeshp . ".dbf", $def);
             dbase_close($db);
         }
         //acrescenta os pontos no novo shapefile
         $dbname = $nomeshp . ".dbf";
         $db = xbase_open($dbname, 2);
         $reg = array();
         $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2);
         //acrescenta os shapes
         foreach ($resultado as $r) {
             $pts = $r[4];
             if ($tipol == MS_SHP_POLYGON) {
                 $shp = ms_newShapeObj(MS_SHP_POLYGON);
                 $linha = ms_newLineObj();
                 $linha->addXY($pts[0], $pts[3]);
                 $linha->addXY($pts[2], $pts[3]);
                 $linha->addXY($pts[2], $pts[1]);
                 $linha->addXY($pts[0], $pts[1]);
                 $linha->addXY($pts[0], $pts[3]);
             } else {
                 $shp = ms_newShapeObj(MS_SHP_POINT);
                 $linha = ms_newLineObj();
                 $linha->addXY($pts[1], $pts[0]);
             }
             $shp->add($linha);
             $novoshpf->addShape($shp);
             $reg = array($r[0], $r[1], $r[2], $r[3]);
             xbase_add_record($db, $reg);
             $reg = array();
         }
         xbase_close($db);
         if ($tipog == "georsspoint" || $tipog == "geo") {
             $tipol = MS_LAYER_POINT;
         } else {
             $tipol = MS_LAYER_POLYGON;
         }
         $layer = criaLayer($this->mapa, $tipol, MS_DEFAULT, "GeoRSS", "SIM");
         $layer->set("data", $nomeshp . ".shp");
         $layer->set("name", basename($nomeshp));
         $layer->setmetadata("DOWNLOAD", "sim");
         $layer->setmetadata("TEMALOCAL", "SIM");
         //evita problemas no modo tile
         if ($this->v > 5) {
             $layer->setprocessing("LABEL_NO_CLIP=True");
             $layer->setprocessing("POLYLINE_NO_CLIP=True");
         }
         if ($tipol == MS_LAYER_POLYGON) {
             $classe = $layer->getclass(0);
             $estilo = $classe->getstyle(0);
             $estilo->set("symbolname", "p4");
             $estilo->set("size", 5);
             $cor = $estilo->color;
             $cor->setrgb(255, 0, 0);
             $coro = $estilo->outlinecolor;
             $coro->setrgb(255, 0, 0);
         }
         //$layer->set("transparency",50);
         $layer->setmetadata("nomeoriginal", basename($nomeshp));
         //echo $tipol;
         return "ok";
     }
     return "erro";
 }
Ejemplo n.º 3
0
function dbase_create($filename, $fields)
{
    return xbase_create($filename, $fields);
}
Ejemplo n.º 4
0
*  Developer        : Erwin Kooi
*  released at      : Jan 2005
*  last modified by : Erwin Kooi
*  date modified    : Jan 2005
*                                                               
*  Info? Mail to info@cyane.nl
* 
* --------------------------------------------------------------
*
* R/W with api demonstration / compare with PHP integrated dbase functions
*
**/
require_once "api_conversion.php";
$fields = array(array("bool", DBFFIELD_TYPE_LOGICAL), array("memo", DBFFIELD_TYPE_MEMO), array("date", DBFFIELD_TYPE_DATE), array("number", DBFFIELD_TYPE_NUMERIC, 3, 0), array("string", DBFFIELD_TYPE_CHAR, 50));
$di = dbase_create("test/dbase.dbf", $fields);
$xi = xbase_create("test/xbase.dbf", $fields);
dbase_add_record($di, array("T", "abc", "20060120", 123, "string one"));
dbase_add_record($di, array("F", "def", "20060121", 321, "string two"));
dbase_add_record($di, array("F", "ghi", "20060121", 111, "string trio"));
xbase_add_record($xi, array("T", "abc", "20060120", 123, "string one"));
xbase_add_record($xi, array("F", "def", "20060121", 321, "string two"));
xbase_add_record($xi, array("F", "ghi", "20060121", 111, "string trio"));
dbase_close($di);
xbase_close($xi);
$di = dbase_open("test/dbase.dbf", 2);
$xi = xbase_open("test/xbase.dbf", 2);
dbase_delete_record($di, 2);
xbase_delete_record($xi, 2);
dbase_pack($di);
xbase_pack($xi);
dbase_close($di);
Ejemplo n.º 5
0
function criaSHP($tema, $map_file, $locaplic, $dir_tmp, $nomeRand = TRUE, $prj = "", $projetaToMap = true, $shapesSel = false)
{
    include dirname(__FILE__) . "/../ms_configura.php";
    $versao = versao();
    $versao = $versao["principal"];
    //para manipular dbf
    if (file_exists($locaplic . "/pacotes/phpxbase/api_conversion.php")) {
        include_once $locaplic . "/pacotes/phpxbase/api_conversion.php";
    } else {
        include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
    }
    $map = @ms_newMapObj($map_file);
    $nameMapfile = $map->name;
    substituiConObj($map, $postgis_mapa);
    $layer = $map->getlayerbyname($tema);
    //e necessario abrir ou nao vai projetar
    $layer->open();
    $prjMapa = $map->getProjection();
    $prjTema = $layer->getProjection();
    if ($prjTema != "") {
        $projInObj = new projectionObj($prjTema);
        $projOutObj = new projectionObj($prjMapa);
    } else {
        $projInObj = "";
        $projOutObj = "";
        $projetaToMap = false;
    }
    $layer->set("template", "none.htm");
    $diretorio = dirname($dir_tmp);
    $tipol = MS_SHP_POINT;
    if ($layer->type == MS_LAYER_LINE) {
        $tipol = MS_SHP_ARC;
    }
    if ($layer->type == MS_LAYER_POLYGON) {
        $tipol = MS_SHP_POLYGON;
    }
    if ($nomeRand == true) {
        $novonomelayer = $tema . "_" . nomeRandomico(5);
    } else {
        $novonomelayer = $tema;
    }
    $novonomelayer = str_replace(".", "-", $novonomelayer);
    $nomeshp = $dir_tmp . "/" . $nameMapfile . "_" . $novonomelayer;
    if (file_exists($nomeshp . ".shp")) {
        return $nomeshp;
    }
    $novoshpf = ms_newShapefileObj($nomeshp, $tipol);
    //se for do tipo features
    $data = $layer->data;
    $resultadoFinal = true;
    if ($data == "") {
        $def[] = array("ID", "C", "50");
        $reg[] = 0;
        if (!function_exists("dbase_create")) {
            $db = xbase_create($nomeshp . ".dbf", $def);
            xbase_add_record($db, $reg);
            xbase_close($db);
        } else {
            $db = dbase_create($nomeshp . ".dbf", $def);
            dbase_add_record($db, $reg);
            dbase_close($db);
        }
        if ($versao >= 6) {
            $shape = $layer->getshape(new resultObj(0));
        } else {
            $s = $layer->getfeature(0, -1);
            $result = $layer->getResult(0);
            $shpi = $result->shapeindex;
            $shape = $layer->getfeature($shpi, -1);
        }
        $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2);
        $novoshpf->addShape($shape);
        $resultadoFinal = true;
    } else {
        if ($shapesSel == false) {
            $shapesSel = retornaShapesSelecionados($layer, $map_file, $map, false);
        }
        $items = pegaItens($layer);
        // cria o dbf
        $def = array();
        $cni = 0;
        foreach ($items as $ni) {
            $temp = strtoupper($ni);
            $temp = substr($temp, 0, 8) . $cni;
            //
            //nao tem como descobrir o tamanho e tipo do campo
            //
            $def[] = array($temp, "C", "254");
            $cni = $cni + 1;
        }
        if (!function_exists("dbase_create")) {
            $db = xbase_create($nomeshp . ".dbf", $def);
        } else {
            $db = dbase_create($nomeshp . ".dbf", $def);
        }
        $dbname = $nomeshp . ".dbf";
        $reg = array();
        $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2);
        $res_count = count($shapesSel);
        if ($res_count > 0) {
            for ($i = 0; $i < $res_count; ++$i) {
                $shape = $shapesSel[$i];
                if ($projetaToMap == true) {
                    $shape->project($projInObj, $projOutObj);
                }
                foreach ($items as $ni) {
                    $vreg = $shape->values[$ni];
                    if (strlen($vreg) > 255) {
                        $vreg = substr($vreg, 0, 255);
                    }
                    $reg[] = $vreg;
                }
                $novoshpf->addShape($shape);
                if (!function_exists("dbase_create")) {
                    xbase_add_record($db, $reg);
                } else {
                    dbase_add_record($db, $reg);
                }
                $reg = array();
            }
            if (!function_exists("dbase_create")) {
                xbase_close($db);
            } else {
                dbase_close($db);
            }
            //
            //verifica a quantidade de registros no final
            //
            if (function_exists("dbase_open")) {
                $db = dbase_open($nomeshp . ".dbf", 0);
            } else {
                $db = xbase_open($nomeshp . ".dbf", 0);
            }
            if (function_exists("dbase_numrecords")) {
                $record_numbers = dbase_numrecords($db);
            } else {
                $record_numbers = xbase_numrecords($db);
            }
            if (function_exists("dbase_close")) {
                dbase_close($db);
            } else {
                xbase_close($db);
            }
            if ($record_numbers != $res_count) {
                if (file_exists($nomeshp . ".dbf")) {
                    unlink($nomeshp . ".dbf");
                }
                if (file_exists($nomeshp . ".shp")) {
                    unlink($nomeshp . ".shp");
                }
                if (file_exists($nomeshp . ".shx")) {
                    unlink($nomeshp . ".shx");
                }
                if (file_exists($nomeshp . ".prj")) {
                    unlink($nomeshp . ".prj");
                }
                $resultadoFinal = false;
            }
        } else {
            $resultadoFinal = false;
        }
    }
    if ($resultadoFinal == false) {
        return false;
    } else {
        //gera o arquivo prj
        if ($prj != "") {
            gravaDados(array($prj), $nomeshp . ".prj");
        } elseif ($projetaToMap == false) {
            $nomePrjOriginal = str_replace(".shp", ".prj", $layer->data);
            $nomeDestino = $nomeshp . ".prj";
            if (file_exists($nomePrjOriginal) && !file_exists($nomeDestino)) {
                copy($nomePrjOriginal, $nomeDestino);
            }
        }
        return $nomeshp;
    }
}
Ejemplo n.º 6
0
 function incmapageometrias($dir_tmp, $imgdir, $lista, $tipoLista = "stringArquivos")
 {
     $dir = $dir_tmp . "/" . $imgdir . "/";
     $tituloTema = " geometria";
     if ($tipoLista == "stringArquivos") {
         $lista = explode(",", $lista);
         $shapes = array();
         $valoresoriginais = array();
         foreach ($lista as $l) {
             $geos = $this->unserializeGeo($dir . $l);
             // pega todas as geometrias
             foreach ($geos["dados"] as $geo) {
                 // echo $geo["wkt"]."<br>";
                 $shapes[] = ms_shapeObjFromWkt(str_replace("'", "", $geo["wkt"]));
                 foreach ($geo["valores"] as $v) {
                     $valorestemp[] = $v["item"] . "=" . $v["valor"];
                 }
                 $valoresoriginais[] = implode(" ", $valorestemp);
             }
         }
     }
     if ($tipoLista == "arraywkt") {
         $shapes = array();
         $valoresoriginais = array();
         foreach ($lista as $l) {
             $shapes[] = ms_shapeObjFromWkt($l);
         }
     }
     if ($tipoLista == "marcadores") {
         $shapes = array();
         $valoresoriginais = array();
         foreach ($lista as $l) {
             $valoresoriginais[] = $l["nome"];
             $p = explode(" ", $l["ext"]);
             $l = "POLYGON ((" . $p[0] . " " . $p[1] . "," . $p[0] . " " . $p[3] . "," . $p[2] . " " . $p[3] . "," . $p[2] . " " . $p[1] . "," . $p[0] . " " . $p[1] . "))";
             $shapes[] = ms_shapeObjFromWkt($l);
         }
         $tituloTema = " marcadores";
     }
     // verifica o tipo
     if (count($shapes) == 0) {
         return "erro.";
     }
     $tiposhape = $shapes[0]->type;
     $tiposhapefile = MS_SHP_POLYGON;
     if ($tiposhape == 0) {
         $tiposhapefile = MS_SHP_MULTIPOINT;
     }
     if ($tiposhape == 1) {
         $tiposhapefile = MS_SHP_ARC;
     }
     // cria o shapefile
     if ($this->dbaseExiste == false) {
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
     }
     $diretorio = dirname($this->arquivo);
     $novonomelayer = nomeRandomico();
     $nomeshp = $diretorio . "/" . $novonomelayer;
     $l = criaLayer($this->mapa, $tiposhape, MS_DEFAULT, "Ins", "SIM");
     $novoshpf = ms_newShapefileObj($nomeshp, $tiposhapefile);
     $def[] = array("ID", "C", "250");
     if ($this->dbaseExiste == false) {
         $db = xbase_create($nomeshp . ".dbf", $def);
         xbase_close($db);
     } else {
         $db = dbase_create($nomeshp . ".dbf", $def);
         dbase_close($db);
     }
     // acrescenta os pontos no novo shapefile
     $dbname = $nomeshp . ".dbf";
     if ($this->dbaseExiste == false) {
         $db = xbase_open($dbname, 2);
     } else {
         $db = dbase_open($dbname, 2);
     }
     $conta = 0;
     foreach ($shapes as $s) {
         $reg = array();
         $reg[] = $valoresoriginais[$conta];
         if ($this->dbaseExiste == false) {
             xbase_add_record($db, $reg);
         } else {
             dbase_add_record($db, $reg);
         }
         $novoshpf->addshape($s);
         $conta = $conta + 1;
     }
     if ($this->dbaseExiste == false) {
         xbase_close($db);
     } else {
         dbase_close($db);
     }
     $l->set("opacity", 80);
     $l->setmetadata("tema", $novonomelayer . $tituloTema);
     $l->setmetadata("TEMALOCAL", "SIM");
     $l->setmetadata("DOWNLOAD", "sim");
     $l->set("data", $nomeshp);
     $l->set("name", $novonomelayer);
     $classe = $l->getclass(0);
     $estilo = $classe->getstyle(0);
     if ($tiposhape == 0) {
         $estilo->set("symbolname", "ponto");
         $estilo->set("size", 6);
     }
     $cor = $estilo->color;
     $cor->setrgb(255, 210, 0);
     $cor = $estilo->outlinecolor;
     $cor->setrgb(255, 0, 0);
     $this->salva();
     return $novonomelayer;
 }
Ejemplo n.º 7
0
 /**
  * Converte um tipo de regiao em shapefile
  * @param codigo do tipo de regiao
  * @return nome do arquivo criado
  */
 function regiao2shp($codigo_tipo_regiao)
 {
     $regiao = $this->listaTipoRegiao($codigo_tipo_regiao);
     $dados = $this->obtemDadosTabelaDB($regiao["codigo_estat_conexao"], $regiao["esquemadb"], $regiao["tabela"], "sim");
     $tipol = $this->listaPropGeoRegiao($codigo_tipo_regiao);
     include_once dirname(__FILE__) . "/../../classesphp/classe_shp.php";
     $s = new SHP();
     //st_dimension returns 0 for POINT, 1 for LINESTRING, 2 for POLYGON
     //echo MS_SHP_POINT.", ".MS_SHP_ARC.", ".MS_SHP_POLYGON.", ".MS_SHP_MULTIPOINT;
     //1, 3, 5, 8
     $conv[0] = 1;
     $conv[1] = 3;
     $conv[2] = 5;
     //cria as colunas
     $cni = 0;
     foreach ($dados["colunas"] as $t) {
         $temp = strtoupper($t["field"]);
         if (strlen($temp) > 10) {
             $temp = substr($temp, 0, 8) . $cni++;
         }
         if ($t["type"] == "varchar" || $t["type"] == "char" || $t["type"] == "character varying" || $t["type"] == "character" || $t["type"] == "text") {
             $def[] = array($temp, "C", "254");
         } else {
             if ($t["lengthvar"] < 0) {
                 $t["lengthvar"] = 0;
             }
             $def[] = array($temp, "N", $t["length"], $t["lengthvar"]);
         }
     }
     $nomeshp = $this->dir_tmp . "/regiao{$codigo_tipo_regiao}" . "_" . $this->nomeRandomico();
     $dbaseExiste = false;
     if (function_exists("dbase_create")) {
         $dbaseExiste = true;
     }
     //para manipular dbf
     if ($dbaseExiste == false) {
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
         $db = xbase_create($nomeshp . ".dbf", $def);
     } else {
         $db = dbase_create($nomeshp . ".dbf", $def);
     }
     $dbname = $nomeshp . ".dbf";
     $reg = array();
     $novoshpf = ms_newShapefileObj($nomeshp . ".shp", $conv[$tipol["st_dimension"]]);
     $cols = $dados["colunas"];
     $nc = count($dados["colunas"]);
     foreach ($dados["linhas"] as $l) {
         $reg = array();
         for ($i = 0; $i < $nc; $i++) {
             if ($cols[$i]["type"] != "geometry" && $cols[$i]["type"] != "geography") {
                 $reg[] = $l[$i];
             } else {
                 $reg[] = 0;
                 if ($cols[$i]["field"] == $regiao["colunageo"]) {
                     $shape = ms_shapeObjFromWkt($l[$i]);
                 }
             }
         }
         $novoshpf->addShape($shape);
         if ($dbaseExiste == false) {
             xbase_add_record($db, $reg);
         } else {
             dbase_add_record($db, $reg);
         }
     }
     if ($this->dbaseExiste == false) {
         xbase_close($db);
     } else {
         dbase_close($db);
     }
     return $nomeshp;
 }
Ejemplo n.º 8
0
 function shpPT2shp($locaplic, $para)
 {
     if (!$this->layer) {
         return "erro";
     }
     $this->layer->set("template", "none.htm");
     $diretorio = dirname($this->arquivo);
     $tipol = MS_SHP_ARC;
     $tipos = MS_SHAPE_LINE;
     if ($para == "poligono") {
         $tipol = MS_SHP_POLYGON;
         $tipos = MS_SHAPE_POLYGON;
     }
     $novonomelayer = nomeRandomico();
     $nomeshp = $diretorio . "/" . $novonomelayer;
     $items = pegaItens($this->layer);
     // cria o dbf
     $def = array();
     foreach ($items as $ni) {
         $temp = strtoupper($ni);
         $def[] = array($temp, "C", "254");
     }
     //para manipular dbf
     if ($this->dbaseExiste == false) {
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
         $db = xbase_create($nomeshp . ".dbf", $def);
     } else {
         $db = dbase_create($nomeshp . ".dbf", $def);
     }
     $dbname = $nomeshp . ".dbf";
     $reg = array();
     $novoshpf = ms_newShapefileObj($nomeshp . ".shp", $tipol);
     $this->layer->open();
     $prjMapa = $this->mapa->getProjection();
     $prjTema = $this->layer->getProjection();
     $ret = $this->mapa->extent;
     if ($prjTema != "" && $prjMapa != $prjTema) {
         $projOutObj = ms_newprojectionobj($prjTema);
         $projInObj = ms_newprojectionobj($prjMapa);
         $ret->project($projInObj, $projOutObj);
     }
     $this->layer->whichShapes($ret);
     $linha = ms_newLineObj();
     $pponto = "";
     $pontos = array();
     while ($shape = $this->layer->nextShape()) {
         $lin = $shape->line(0);
         $pt = $lin->point(0);
         if ($pponto == "") {
             $pponto = $pt;
         }
         if ($prjTema != "" && $prjMapa != $prjTema) {
             $pt->project($projInObj, $projOutObj);
         }
         $pontos[] = $pt->x;
         $pontos[] = $pt->y;
     }
     $pontos = implode(" ", $pontos);
     $pontos = xy2wkt($pontos);
     if ($para == "poligono") {
         $shape = ms_shapeObjFromWkt($pontos["poligono"]);
     } else {
         $shape = ms_shapeObjFromWkt($pontos["linha"]);
     }
     foreach ($items as $ni) {
         $reg[] = "-";
     }
     $novoshpf->addShape($shape);
     if ($this->dbaseExiste == false) {
         xbase_add_record($db, $reg);
         xbase_close($db);
     } else {
         dbase_add_record($db, $reg);
         dbase_close($db);
     }
     $this->layer->close();
     //cria o novo layer
     $layer = criaLayer($this->mapa, MS_LAYER_LINE, MS_DEFAULT, "", $metaClasse = "SIM");
     $layer->set("data", $nomeshp);
     $layer->setmetadata("tema", $novonomelayer . " (linear)");
     $layer->setmetadata("download", "sim");
     $layer->setmetadata("temalocal", "sim");
     $classe = $layer->getclass(0);
     $estilo = $classe->getstyle(0);
     $estilo->set("symbolname", "linha");
     if ($para == "poligono") {
         $layer->set("type", MS_LAYER_POLYGON);
         $layer->set("opacity", "50");
         $layer->setmetadata("tema", $novonomelayer . " (poligonal)");
     }
     return "ok";
 }
Ejemplo n.º 9
0
     foreach ($colunas as $i) {
         $i = strtoupper($i);
         $i = trim($i);
         if ($i != $nomex && $i != $nomey) {
             $i = str_replace("_", "", $i);
             $i = str_replace("-", "", $i);
             if (strlen($i) > 10) {
                 $i = substr($i, 0, 7) . $conta++;
             }
             $def[] = array($i, "C", "255");
         } else {
             $def[] = array($i, "C", "255");
         }
     }
     if (!function_exists("dbase_create")) {
         xbase_create($dirmap . "/" . $nome . ".dbf", $def);
     } else {
         dbase_create($dirmap . "/" . $nome . ".dbf", $def);
     }
     $db = xbase_open($dirmap . "/" . $nome . ".dbf", 2);
     foreach ($csv->data as $d) {
         $reg = array();
         foreach ($d as $i) {
             $reg[] = $i;
         }
         xbase_add_record($db, $reg);
     }
     xbase_close($db);
 } else {
     copy($dirmap . "/" . $ArquivoDest, $dirmap . "/" . $nome . ".dbf");
 }