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
ogr2ogr
from within PHP, meaning that you prepare the shell script as string? If so, you could use sth. likeogr2ogr <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.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 ?<layer_name>
is refering to the input file! Try with the name of the KML file you import from, i.e.... FROM "1597889056";
.no such table: 1597889056
, withogrinfo -al -so 1597889056.kml
returnLayer name: LOBR640610MZSNTB09 Geometry:Unknown (any) Feature Count: 1
, is there a way to get layer_name from ogr2ogr or change the value ?