1

So I have my table named ppb_curp with the following columns

ogc_fid | name | description | wkb_geometry |curp | zip_code

Then I insert the KML file in my PostGis base with ogr2ogr

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/polygon/1597861175.kml  -nln  ppb_curp  2>&1

but just insert data into column ogc_fid and wkb_geometry.

i am using php as language, the values ​​of name, description, curp,zip_code I have them in a variable:

$name = "My kml file";
$description = "My kml file description";
$curp = "2JJIDEIEIEI";
$zip_code = "89790";

My question is how do I insert these fields with Ogr2ogr?

The command line with ogr2ogr is:

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/1597889056.kml  -nln  ppb_curp  -dialect sqlite  -sql "SELECT ogc_fid, 'My kml file' as name FROM 'ppb_curp'" 2>&1

but it gives me the following error:

ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT ogc_fid, 'Hello Ogr2ogr' as name FROM 'ppb_curp'): no such table: ppb_curp
4
  • 1
    So you execute ogr2ogr from within PHP, meaning that you prepare the shell script as string? If so, you could use sth. like ogr2ogr <other_options> -dialect sqlite -sql 'SELECT ogc_fid, <name> AS name, <desc> AS description, <curp> AS curp, <zip> AS zip_code, GEOMETRY AS wkb_geometry FROM <layer_name>;' where you pass in string literals from your vars.
    – geozelot
    Commented Aug 20, 2020 at 8:50
  • Exact, the string I generate from php @geozelot update my question with the string I generate with your answer. output; 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/polygon/1597861175.kml -nln ppb_curp -dialect sqlite -sql "SELECT ogc_fid, 'My kml file ' as name FROM 'ppb_curp'" 2>&1 , but how do I get the value of layer_name ?
    – Eze
    Commented Aug 20, 2020 at 15:45
  • <layer_name> is refering to the input file! Try with the name of the KML file you import from, i.e. ... FROM "1597889056";.
    – geozelot
    Commented Aug 20, 2020 at 19:17
  • @geozelot I have changed my command line but I still get no such table: 1597889056, with ogrinfo -al -so 1597889056.kml return Layer name: LOBR640610MZSNTB09 Geometry:Unknown (any) Feature Count: 1, is there a way to get layer_name from ogr2ogr or change the value ?
    – Eze
    Commented Aug 20, 2020 at 19:31

0

Your Answer

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

Browse other questions tagged or ask your own question.