IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Script point Polygone et format donnees Lat Long


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2012
    Messages : 320
    Par défaut Script point Polygone et format donnees Lat Long
    Bonjour,*
    Je me trouve devant un problème de compréhension. J'ai un script écrit par***Michaël Niessen* et libre de publication et modification. ce script détermine si une cordonnée gps* *-44.0814,* -81.8608 se trouve ou pas a l 'intérieur d'un polygone. Je* récupère* la coordonnée en question dans un fichier txt* dans la variable $id, mais la problème* !!* cela ne foctionne pas et m 'indique que ces coordonnées son a l 'extérieures . alors que si je rentre les cordonnées en "dur" cela fonctionne .* Pouvez vous m 'aider? Merci d'avance

    * * $fp = fopen("coor.txt", "r");

    * * $id=fread($fp,2000);fclose($fp);

    * * $points=array("$id");// la pas bon

    * * //$points=array("-44.0814,* -81.8608");// la c'est ok( noter l 'espace entre la virgule et la longitude sans cet espace cela ne fonctionne pas non plus

  2. #2
    Expert confirmé Avatar de CosmoKnacki
    Homme Profil pro
    Justicier interdimensionnel
    Inscrit en
    Mars 2009
    Messages
    2 986
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Justicier interdimensionnel

    Informations forums :
    Inscription : Mars 2009
    Messages : 2 986
    Par défaut
    Merci de mettre en forme ton message et de montrer un dump de $id (var_dump($id))

  3. #3
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2012
    Messages : 320
    Par défaut
    Bonjour, Ah mince désolé pour la mise ne forme

  4. #4
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2012
    Messages : 320
    Par défaut
    Re moi je post le script entier ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    <?php
        /*
        Descripción: El algoritmo del punto en un polígono permite comprobar mediante
        programación si un punto está dentro de un polígono o fuera de ello.
        Autor: Michaël Niessen (2009)
        Sito web: AssemblySys.com
    
        Si este código le es útil, puede mostrar su
        agradecimiento a Michaël ofreciéndole un café ;)
        PayPal: michael.niessen@assemblysys.com
    
        Mientras estos comentarios (incluyendo nombre y detalles del autor) estén
        incluidos y SIN ALTERAR, este código está distribuido bajo la GNU Licencia
        Pública General versión 3: http://www.gnu.org/licenses/gpl.html
        */
     
        class pointLocation {
            var $pointOnVertex = true; // Checar si el punto se encuentra exactamente en uno de los vértices?
     
            function pointLocation() {
            }
     
                function pointInPolygon($point, $polygon, $pointOnVertex = true) {
                $this->pointOnVertex = $pointOnVertex;
     
                // Transformar la cadena de coordenadas en matrices con valores "x" e "y"
                $point = $this->pointStringToCoordinates($point);
                $vertices = array(); 
                foreach ($polygon as $vertex) {
                    $vertices[] = $this->pointStringToCoordinates($vertex); 
                }
     
                // Checar si el punto se encuentra exactamente en un vértice
                if ($this->pointOnVertex == true and $this->pointOnVertex($point, $vertices) == true) {
                    return "vertex";
                }
     
                // Checar si el punto está adentro del poligono o en el borde
                $intersections = 0; 
                $vertices_count = count($vertices);
     
                for ($i=1; $i < $vertices_count; $i++) {
                    $vertex1 = $vertices[$i-1]; 
                    $vertex2 = $vertices[$i];
                    if ($vertex1['y'] == $vertex2['y'] and $vertex1['y'] == $point['y'] and $point['x'] > min($vertex1['x'], $vertex2['x']) and $point['x'] < max($vertex1['x'], $vertex2['x'])) { // Checar si el punto está en un segmento horizontal
                        return "boundary";
                    }
                    if ($point['y'] > min($vertex1['y'], $vertex2['y']) and $point['y'] <= max($vertex1['y'], $vertex2['y']) and $point['x'] <= max($vertex1['x'], $vertex2['x']) and $vertex1['y'] != $vertex2['y']) { 
                        $xinters = ($point['y'] - $vertex1['y']) * ($vertex2['x'] - $vertex1['x']) / ($vertex2['y'] - $vertex1['y']) + $vertex1['x']; 
                        if ($xinters == $point['x']) { // Checar si el punto está en un segmento (otro que horizontal)
                            return "boundary";
                        }
                        if ($vertex1['x'] == $vertex2['x'] || $point['x'] <= $xinters) {
                            $intersections++; 
                        }
                    } 
                } 
                // Si el número de intersecciones es impar, el punto está dentro del poligono. 
                if ($intersections % 2 != 0) {
                    return "IN POLYGONE";
                } else {
                    return "OUT POLYGONE";
                }
            }
     
            function pointOnVertex($point, $vertices) {
                foreach($vertices as $vertex) {
                    if ($point == $vertex) {
                        return true;
                    }
                }
     
            }
     
            function pointStringToCoordinates($pointString) {
                $coordinates = explode(" ", $pointString);
                return array("x" => $coordinates[0], "y" => $coordinates[1]);
            }
     
        }
     
        $json="[[30.247481942444168, -130.16202318217532],[25.725145007300867, -37.830595537571206],[-41.72718148608446, -12.52381385214828],[-35.92520316896399, -110.64444201453682]]";
    //aca estaba el error (here the error)
        $resultado = str_replace(" ", "", $json);
        $resultado = str_replace(",", " ", $resultado);
        $resultado = str_replace("[[", "", $resultado);
        $resultado = str_replace("]]", "", $resultado);
     
        $polygon=explode("] [", $resultado);
     
     
     
     
        $fp = fopen("coor.txt", "r");
        $id=fread($fp,2000);fclose($fp);
     
     
     
     
     
         $points=array("$id");
     
        //$points=array("-44.0814,  -81.8608");
     
     
         //$id (var_dump($id));
     
     
     
        // print_r ($polygon);
        $pointLocation = new pointLocation();
        //$points = array("50 70","70 40","-20 30","100 10","-10 -10","40 -20","110 -20");
        //$polygon = array("-50 30","50 70","100 50","80 10","110 -10","110 -30","-20 -50","-30 -40","10 -10","-10 10","-30 -20","-50 30");
     
        // print_r($polygon);
        // Las últimas coordenadas tienen que ser las mismas que las primeras, para "cerrar el círculo"
        foreach($points as $key => $point) {
            echo "point " . ($key+1) . " ($point): " . $pointLocation->pointInPolygon($point, $polygon) . "<br>";
     
     
        }
        ?>

  5. #5
    Expert confirmé
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 347
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 347
    Billets dans le blog
    17
    Par défaut
    Ton script est mal formaté (merci) et n'est pas exécutable/testable.
    Tu ne réponds pas à la demande de CosmoKnacki.

    $points=array("$id"); est douteux.

    Pour traiter du JSON, il y a json_decode().

    Pour récupérer le contenu d'un fichier il y a file_get_contents().

  6. #6
    Membre éclairé
    Homme Profil pro
    Inscrit en
    Juin 2012
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2012
    Messages : 320
    Par défaut
    Bonjour Seb,


    file_get_contents() oui merci plus simple

    voisci la reponse du dump
    Fatal error: Uncaught Error: Call to undefined function -44.0814, -81.8608 () in /home/xxxx/public_html/www/xxx.php:100 Stack trace: #0 {main} thrown
    JE précise que si je fais

    $points=array("-44.0814, -81.8608"); en dur cela fonctionne bien pourtant après vérification par un echo j 'ai bien -44.0814,-81.8608 c'est juste l 'espace qui manque aprés la virgule.

    Bonne journée

Discussions similaires

  1. Réponses: 4
    Dernier message: 09/07/2019, 09h25
  2. Réponses: 12
    Dernier message: 23/06/2008, 16h44
  3. Format WAV/PCM,long 4 octets et masques PHP
    Par juki dans le forum Langage
    Réponses: 3
    Dernier message: 29/01/2006, 18h57
  4. Conversion Lat/Long vers UTM
    Par efficks dans le forum Algorithmes et structures de données
    Réponses: 6
    Dernier message: 12/12/2005, 17h13
  5. Réponses: 13
    Dernier message: 01/10/2004, 14h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo