2

So I have a KML file that I want to save to my PostGIS database, Currently I have the following code using PHP:

$file = $request->file("item");
$name = time();
$name = $name . '.' . $file->getClientOriginalExtension();
$temp = 'uploads/' . $user_app->id . '/kml/';
$path = public_path('uploads/' . $user_app->id . '/kml/');
if (!file_exists($path)) {
 mkdir($path, 0777, true);
}
$path = public_path() . '/uploads/' . $user_app->id . '/kml/';
$command = "ogr2ogr -f PostgreSQL PG:\"host=".$HOST." dbname=".$DBNAME." port=".$PORT." user=".$USER." password=".$PASSWORD."\" ".$path.$name." -nln siap 2>&1";
Log::debug($command);
$res = shell_exec($command) ;
Log::debug($res);

This is the command line,

ogr2ogr -f PostgreSQL PG:"host=127.0.0.1 dbname=postgis_24_sample port=5432 user=postgres password=123456" C:\xampp\htdocs\siap-padron\public/uploads/2044492/kml/1597284059.kml -nln siap 2>&1

If I run it in PowerShell or in the system symbol it inserts it correctly in the PostGIS base, but when it is run in PHP it gives me the following error:

local.DEBUG: FAILURE: Unable to open datasource `C:/xampp/htdocs/siap-padron/public/uploads/2044492/kml/1597284059.kml' with the following drivers.
-> `JP2ECW'......

Any comment would be very helpful.

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Aug 13, 2020 at 2:33
1
  • It looks like GDAL tries to open the kml file with raster drivers. I do not know why. EDIT: wrong thinking, JPEG 2000 can contain also vector data and therefore the JP2ECW driver was tested as well. Commented Aug 13, 2020 at 7:25

1 Answer 1

1

The error came out because my kml file path was wrong, the correct way is as follows

ogr2ogr -f PostgreSQL PG:"host=127.0.0.1 dbname=postgis_24_sample port=5432 user=postgres password=123456" C:/xampp/htdocs/siap-padron/public/uploads/2044492/kml/1597328869.kml -nln siap 2>&1
answered Aug 13, 2020 at 15:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.