oustyle
oustyle

Reputation: 103

how to add raster data postgis from a web interface

in the design framework and the development of a GIS platform WEB (Web Mapping) for the dissemination of spatial data, I need to create a web interface that help the administrator to add these spatial data to postgis via a web interface I try this code I get no error but the data is not added

<form method="post" action="" enctype="multipart/form-data">
     <label for="fichier">Ajouter raster :</label><br />
     <input type="file" name="fichier"  />
     <input type="submit" name="submit" value="Envoyer" />
</form>
<?php 
        $db = pg_connect('host=5432 dbname=gisdb user=postges password=ou$$am@16'); 

        $raster = pg_escape_string($_POST['fichier']); 
        $name = $_FILES['$raster']['name']; 

        $query = "INSERT INTO eau_param_hydro(rast,filname) VALUES('". addslashes($raster) ."','" . $name . "')"; 
        $result = pg_query($query); 
        if (!$result) { 
            $errormessage = pg_last_error(); 
            echo "Error with query: " . $errormessage; 
            exit(); 
        } 
        pg_close(); }
        ?> 

  </body>

Upvotes: 0

Views: 344

Answers (1)

fradal83
fradal83

Reputation: 2022

You cannot insert a file in a raster column like that.

You shuold import that file using raster2pgsql (for example raster2pgsql -s -t 50x50 -f -I -Y myRaster.tif rasterSchema.RasterName > raster.sql ).

This command will produce a raster.sql file containing the SQL to insert raster data.

You can execute that command using php exec() function, passing $_FILES['fichier']['tmp_name']

Upvotes: 2

Related Questions