I am having the following issue writing points to a SQLite file using ogr with SPATIALITE enabed:

ERROR 1: Cannot insert feature with geometry of type POINTZ in column GEOMETRY. Type POINT expected

Below is my code, this code was previously used to create a GeoPackage with exactly the same fields. (But not with Spatialite enabled because it doesn't have it)

I have commented the code to indicate where the point is created and where the error message comes up

import ogr
import numpy as np
import os 
DataSource= ogr.GetDriverByName("SQLite").CreateDataSource(os.path.join(OutputFolder,"DataFile.sqlite"), options = ["SPATIALITE=YES"])
DataLayer = DataSource.CreateLayer("Data_Points",proj,geom_type=ogr.wkbPoint)


Data_layer_defn = DataLayer.GetLayerDefn()

data = np.load(os.path.join(OutputFolder,"Output0.npy"))
arr_id = 0
for row in range(len(data)):

    point = ogr.Geometry(ogr.wkbPoint)
    point.AddPoint(float(data[row,1]),float(data[row,2])) #x,y Setting the point

    Data_Feature = ogr.Feature(Data_layer_defn)
    Data_Feature.SetField("ID", int(data[row,0]))
    Data_Feature.SetField("buffer_dist", int(data[row,3]))
    Data_Feature.SetField("arr_id", arr_id)
    DataLayer.CreateFeature(Data_Feature) #Error message happens on this line

    point = None
    arr_id +=1

  • Would you mind to improve you code with required imports etc? – user30184 Jun 16 '19 at 20:47
  • I have added the imports necessary, there are only two – Francis Jun 17 '19 at 8:26
  • I am getting error "NameError: name 'os' is not defined". – user30184 Jun 17 '19 at 9:47
  • 1
    3D geometry seems to be the default. Test with three lines point=ogr.Geometry(ogr.wkbPoint) point.AddPoint(float(1.0),float(2.0)) print point.ExportToWkt() POINT (1 2 0). The same appears here pastebin.com/ewkKPuVM. – user30184 Jun 17 '19 at 11:00
  • 1
    And so as in gis.stackexchange.com/questions/199820/… you must flatten 3D into 2D first with point.FlattedTo2D(). – user30184 Jun 17 '19 at 11:15

Creating a point with 2 coordinates actually creates a 3D point as can be tested with

print point.ExportToWkt()
POINT (1 2 0)

You can turn 3D points into 2D points with FlattenTo2D

print point.ExportToWkt()
POINT (1 2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.