i trying insert linestrings local postgres/postgis-database. use python 2.7, psycopg2 , ppygis.
every time when make loop-input, few records inserted table. tried find out problem mogrify, see no failure.
polyline = [] row in positions: lat = row[0] lon = row[1] point = ppygis.point(lon, lat, srid=4326) polyline.append(point) linestring = ppygis.linestring(polyline, srid=4326) self.cursor.execute("begin") self.cursor.execute("insert gtrack_4326 (car, polyline) values (%s,%s);", ("test_car", linestring)) self.cursor.execute("commit")
the use of execute.mogrify results in strings this:
insert gtrack_4326 (car,polyline) values ('test_car', '0102000020e610000018000000aefab72638502940140c42d4d899484055a4c2d84250294056a824a1e3994840585b0c795f50294085cda55df1994840edca78a57650294069595249f8994840ec78dd6cbd502940828debdff5994840745314f93f5129407396fecaef994840e1f6bafbd25129404eab329de7994840da588979565229407a562d44e2994840ebc9fca36f522940c2af4797ed9948403bd164b5af5229407a90f9dbf99948407adbf1cb05532940818af4ec039a484062928087585329402834ff9e0e9a4840e8bb5b59a2532940b1ec38341b9a4840dcb28d89de532940afe94141299a484084d3275e0a54294019b1aab9379a484080ca42853454294053509b82469a48408df8043f6054294063844b22569a48406d3e09c7875429406dfbc33b659a4840aa5a77989b542940c20e08196d9a48401b56a7b9cb542940a0a0b9f3699a4840cf2d742502552940192543e9669a484045ac0f351b552940fdb0efd46d9a48406891ed7c3f552940450a0a28799a4840d0189c77525529405f7b6649809a4840');
but if database, see lot of records without geometry-data in second column. did not understand why mogrify shows data in each column , in db there in 50 % of table no data in geometry-column.
first, psycopg2
own transaction management, should write:
self.cursor.execute( "insert gtrack_4326 (car, polyline) values (%s,%s);", ("test_car", linestring) ) self.conn.commit()
see the psycopg2 docs.
second, consider loading data in batches copy
. see copy
in psycopg2 docs.
also consider setting log_statement = 'all'
in postgresql.conf
, suitable log_line_prefix
restarting postgresql server. examine logs , see if can tell what's doing bogus inserts.
if practical, add check
and/or not null
constraint geometry column incorrect insert
s fail , report error program doing insert. might diagnose problem.
Comments
Post a Comment