2016-05-23 11 views
1
 x = float(stand[1].split(' ')[0]) 
     y = float(stand[1].split(' ')[1]) 
     coordinate = ppygis.Point(x, y) 
     coordinate.srid = SRID_WGS84 
     # Stand delimiters 
     delimiter = [] 
     line = [] 

     for i in range(2, len(stand)): 
      # The cycle will run through everythin in the stand list 
      # But it will only actually do something when it finds a coordinate 
      # counter 
      if (len(stand[i].split(' ')) == 1): 
       # Number of coordinates to process. Adjusted for indexation 
       ncoords = int(stand[i]) + 1 

       for c in range(i + 1, i + ncoords, 1): 
        x = float(stand[c].split(' ')[0]) 
        y = float(stand[c].split(' ')[1]) 

        point = ppygis.Point(x, y) 
        point.srid = SRID_WGS84 
        line.append(point) 
       line = ppygis.LineString((line)) 
       delimiter.append(line) 
       line = [] 
     delimiter = ppygis.MultiLineString((delimiter)) 
     cur.execute(""" 
       INSERT INTO taxi_stands(id, name, coordinates, delimiter_geom) 
       VALUES(%s, %s, ST_PointFromText(%s), %s); 
       """, (taxi_stands_list.index(stand), stand_name, coordinate, 
        delimiter)) 

私たちは、Pythonを使用してPostgreSQLデータベースにMultiLineStringを挿入しようとしています。 ppygisを使用して座標を実際の図形に変換しています。スタンドは挿入される座標です。次のようにリストの形式は次のとおりです。psycopg2.InternalError:解析エラー - 無効なジオメトリ

[nº of points in line, x1line1, y1line1, ..., nº of points in line, ...] 

我々はこのエラーを取得し、データベースに挿入する:

psycopg2.InternalError: parse error - invalid geometry 
HINT: "0101000020e6100000645d" <-- parse error at position 22 within geometry 
CONTEXT: SQL function "st_pointfromtext" statement 1 

我々はエラーをST_GeomFromTextするST_PointFromTextを変更した場合は、次のとおりです。

psycopg2.InternalError: parse error - invalid geometry 
HINT: "0101000020e6100000645d" <-- parse error at position 22 within geometry 

ppygis pythonモジュールもドキュメントに重大な欠点があり、私たちはどちらがエラーであるかわかりません。

助けが必要ですか?ありがとう。

答えて

2

ジオメトリがすでにWKB形式(ST_PointFromTextの形状はWKT形式)であるため、St_PointFromText()は使用しないでください。

単にので、あなたの文を変更します。

cur.execute(""" 
       INSERT INTO taxi_stands(id, name, coordinates, delimiter_geom) 
       VALUES(%s, %s, %s, %s); 
       """, (taxi_stands_list.index(stand), stand_name, coordinate, 
        delimiter)) 
関連する問題