<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 2, 2021 at 7:59 AM Michael Saupe <<a href="mailto:msaupe@web.de">msaupe@web.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Evan,<br>
<br>
thank you for the explanation. That makes sense. However, in my opinion ogr2ogr behavior is not really consistent in this case: The column ogc_fid , which is in fact the track id, is incremented on each gpx file import ( regardless if you use -update -append or not ).<br>
<br></blockquote><div><br></div><div>The ogc_fid is a primary key column created by ogr2ogr. Its values come from a postgres sequence named TABLE_NAME_ogc_fid_seq. You can see this by looking at your table definition, for example in pgAdmin in the "SQL" tab. The ogc_fid is not the track id but might appear to be since it starts at 0.</div><div><br></div><div>Rich</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Am 02.01.2021 um 14:03 schrieb Even Rouault:<br>
> Michael,<br>
><br>
> You have a single track in each file, so it is expected that track_fid doesn't <br>
> change and is set at 0 (as there's no attribute to uniquely identify a track)<br>
> For what you want to do (that is have distinct track_fid for each file), <br>
> you'll likely have to use an intermediate postgresql schema, where you would <br>
> correct the value of track_fid, before merging them together<br>
><br>
> Even<br>
><br>
>> clarification: second table of my points is 'track_points'.<br>
>><br>
>> Also adding my 2 gpx files for reference:<br>
>><br>
>> *file1.gpx:*<br>
>><br>
>> <?xml version="1.0" encoding="UTF-8"?><br>
>> <gpx version="1.1" xmlns="<a href="http://www.topografix.com/GPX/1/1" rel="noreferrer" target="_blank">http://www.topografix.com/GPX/1/1</a>"><br>
>> <metadata><br>
>> </metadata><br>
>> <trk><br>
>> <trkseg><br>
>> <trkpt lat="49.250324000" lon="8.687196000"><br>
>> <ele>1</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.250019001" lon="8.687469003"><br>
>> <ele>1</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.249714001" lon="8.687742003"><br>
>> <ele>1</ele><br>
>> </trkpt><br>
>> </trkseg><br>
>> <trkseg><br>
>> <trkpt lat="49.125652000" lon="8.714194000"><br>
>> <ele>2</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.125519000" lon="8.714731000"><br>
>> <ele>2</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.125414000" lon="8.715057001"><br>
>> <ele>2</ele><br>
>> </trkpt><br>
>> </trkseg><br>
>> </trk><br>
>> </gpx><br>
>><br>
>> *file2.gpx:*<br>
>><br>
>> <?xml version="1.0" encoding="UTF-8"?><br>
>> <gpx version="1.1" xmlns="<a href="http://www.topografix.com/GPX/1/1" rel="noreferrer" target="_blank">http://www.topografix.com/GPX/1/1</a>"><br>
>> <metadata><br>
>> </metadata><br>
>> <trk><br>
>> <trkseg><br>
>> <trkpt lat="49.11" lon="8.7"><br>
>> <ele>3</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.12" lon="8.7"><br>
>> <ele>3</ele><br>
>> </trkpt><br>
>> <trkpt lat="49.13" lon="8.7"><br>
>> <ele>3</ele><br>
>> </trkpt><br>
>> </trkseg><br>
>> </trk><br>
>> </gpx<br>
>><br>
>> Am 01.01.2021 um 18:04 schrieb Michael Saupe:<br>
>>> Hello folks,<br>
>>><br>
>>> I am importing multiple gpx files into a postgis database. The tables<br>
>>> 'tracks' and 'track_points' are created / updated.<br>
>>><br>
>>> The column track_fid in in the track_points table should be a reference to<br>
>>> the track feature id as documented in<br>
>>> <a href="https://gdal.org/drivers/vector/gpx.html" rel="noreferrer" target="_blank">https://gdal.org/drivers/vector/gpx.html</a>, however it is always zero. <br>
>>><br>
>>> Is this a bug or am I missing something?<br>
>>><br>
>>> Details<br>
>>><br>
>>> I am creating an empty database, then create postgis extension with<br>
>>> 'CREATE EXTENSION POSTGIS'<br>
>>><br>
>>> I have two simple gpx files ( see attachments )<br>
>>><br>
>>> * file1.gpx - containing 2 track segments - each with 3 track points<br>
>>> * file2.gpx - containing 1 track segment with 3 track points<br>
>>><br>
>>> I am using commands<br>
>>><br>
>>> ogr2ogr -f PostgreSQL -update -append "PG:dbname=testdb host=localhost<br>
>>> user=postgres password=xx port=5432" file1.gpx<br>
>>><br>
>>> ogr2ogr -f PostgreSQL -update -append "PG:dbname=testdb host=localhost<br>
>>> user=postgres password=xx port=5432" file2.gpx<br>
>>><br>
>>> Resulting data in 'tracks'<br>
>>><br>
>>> ogc_fid name cmt desc src link1_href link1_text link1_type<br>
>>> link2_href link2_text link2_type number type wkb_geometry 1 <br>
> NULL<br>
>>> NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL <br>
> NULL ... 2<br>
>>> NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL <br>
> NULL NULL<br>
>>> ...<br>
>> Resulting data in 'track_points'<br>
>><br>
>> ogc_fid track_fid track_seg_id track_seg_point_id ele time .... <br>
> other<br>
>> columns omitted ... 1 0 0 0 1 NULL<br>
>> 2 0 0 1 1 NULL<br>
>> 3 0 0 2 1 NULL<br>
>> 4 0 1 0 2 NULL<br>
>> 5 0 1 1 2 NULL<br>
>> 6 0 1 2 2 NULL<br>
>> 7 0 0 0 3 NULL<br>
>> 8 0 0 1 3 NULL<br>
>> 9 0 0 2 3 NULL<br>
>><br>
>>> Expected:<br>
>>><br>
>>> ogc_fid track_fid track_seg_id track_seg_point_id ele time ....<br>
>>> other columns omitted ... 1 1<br>
>>><br>
>>> 0 0 1 NULL<br>
>>><br>
>>> 2 1<br>
>>><br>
>>> 0 1 1 NULL<br>
>>><br>
>>> 3 1<br>
>>><br>
>>> 0 2 1 NULL<br>
>>><br>
>>> 4 1<br>
>>><br>
>>> 1 0 2 NULL<br>
>>><br>
>>> 5 1<br>
>>><br>
>>> 1 1 2 NULL<br>
>>><br>
>>> 6 1<br>
>>><br>
>>> 1 2 2 NULL<br>
>>><br>
>>> 7 2<br>
>>><br>
>>> 0 0 3 NULL<br>
>>><br>
>>> 8 2<br>
>>><br>
>>> 0 1 3 NULL<br>
>>><br>
>>> 9 2<br>
>>><br>
>>> 0 2 3 NULL<br>
>>><br>
>>> I also tried to omit -update -append, but same result.<br>
>>><br>
>>> Versions:<br>
>>> * Postgres: "PostgreSQL 12.5 on x86_64-pc-linux-musl, compiled by gcc<br>
>>> (Alpine 9.3.0) 9.3.0, 64-bit" * Postgis: "POSTGIS="3.0.3 0" [EXTENSION]<br>
>>> PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" PROJ="7.0.1" LIBXML="2.9.10"<br>
>>> LIBJSON="0.14" LIBPROTOBUF="1.3.3" WAGYU="0.4.3 (Internal)"" * Gdal:<br>
>>> 3.2.0<br>
><br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Richard W. Greenwood, PLS<br><a href="http://www.greenwoodmap.com" target="_blank">www.greenwoodmap.com</a></div></div></div>